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