4c5c68d44b030accbe8640ddd55f7af50702351f
[reactos.git] / reactos / 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 (chaez.san@gmail.com)
7 */
8 #include "unattended.h"
9 #include "defines.h"
10 #include "available.h"
11 #include "dialogs.h"
12
13 #include "setupapi.h"
14
15 #define MIN_ARGS 2
16
17 BOOL UseCmdParameters(LPWSTR lpCmdLine)
18 {
19 INT argc;
20 LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
21
22 if (!argv || argc < MIN_ARGS)
23 {
24 return FALSE;
25 }
26
27 // TODO: use DB filenames as names because they're shorter
28 ATL::CSimpleArray<ATL::CStringW> arrNames;
29 if (!StrCmpW(argv[0], CMD_KEY_INSTALL))
30 {
31 for (INT i = 1; i < argc; ++i)
32 {
33 arrNames.Add(argv[i]);
34 }
35 }
36 else
37 if (!StrCmpW(argv[0], CMD_KEY_SETUP))
38 {
39 HINF InfHandle = SetupOpenInfFileW(argv[1], NULL, INF_STYLE_WIN4, NULL);
40 if (InfHandle == INVALID_HANDLE_VALUE)
41 {
42 return FALSE;
43 }
44
45 INFCONTEXT Context;
46 if (SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
47 {
48 WCHAR szName[MAX_PATH];
49 do
50 {
51 if (SetupGetStringFieldW(&Context, 1, szName, MAX_PATH, NULL))
52 {
53 arrNames.Add(szName);
54 }
55 } while (SetupFindNextLine(&Context, &Context));
56 }
57 SetupCloseInfFile(InfHandle);
58 }
59 else
60 {
61 return FALSE;
62 }
63
64 CAvailableApps apps;
65 apps.UpdateAppsDB();
66 apps.Enum(ENUM_ALL_AVAILABLE, NULL);
67
68 ATL::CSimpleArray<CAvailableApplicationInfo*> arrAppInfo = apps.FindInfoList(arrNames);
69 if (arrAppInfo.GetSize() > 0)
70 {
71 CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE);
72 return TRUE;
73 }
74
75 return FALSE;
76 }