[RAPPS][TRANSLATION] Estonian localization (#959)
[reactos.git] / base / applications / rapps / unattended.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/unattended.cpp
5 * PURPOSE: Functions to parse command-line flags and process them
6 * COPYRIGHT: Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
7 */
8 #include "rapps.h"
9
10 #include "unattended.h"
11
12 #include <setupapi.h>
13
14 #define MIN_ARGS 3
15
16 BOOL UseCmdParameters(LPWSTR lpCmdLine)
17 {
18 INT argc;
19 LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
20
21 if (!argv || argc < MIN_ARGS)
22 {
23 return FALSE;
24 }
25
26 // TODO: use DB filenames as names because they're shorter
27 ATL::CSimpleArray<ATL::CStringW> arrNames;
28 if (!StrCmpIW(argv[1], CMD_KEY_INSTALL))
29 {
30 for (INT i = 2; i < argc; ++i)
31 {
32 arrNames.Add(argv[i]);
33 }
34 }
35 else
36 if (!StrCmpIW(argv[1], CMD_KEY_SETUP))
37 {
38 HINF InfHandle = SetupOpenInfFileW(argv[2], NULL, INF_STYLE_WIN4, NULL);
39 if (InfHandle == INVALID_HANDLE_VALUE)
40 {
41 return FALSE;
42 }
43
44 INFCONTEXT Context;
45 if (SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
46 {
47 WCHAR szName[MAX_PATH];
48 do
49 {
50 if (SetupGetStringFieldW(&Context, 1, szName, _countof(szName), NULL))
51 {
52 arrNames.Add(szName);
53 }
54 } while (SetupFindNextLine(&Context, &Context));
55 }
56 SetupCloseInfFile(InfHandle);
57 }
58 else
59 {
60 return FALSE;
61 }
62
63 CAvailableApps apps;
64 apps.UpdateAppsDB();
65 apps.Enum(ENUM_ALL_AVAILABLE, NULL);
66
67 ATL::CSimpleArray<CAvailableApplicationInfo> arrAppInfo = apps.FindInfoList(arrNames);
68 if (arrAppInfo.GetSize() > 0)
69 {
70 CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE);
71 return TRUE;
72 }
73
74 return FALSE;
75 }