[RAPPS] Formatting fixes
[reactos.git] / reactos / base / applications / rapps / unattended.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/unattended.cpp
5 * PURPOSE: Functions to parse command-line flags and process them
6 * PROGRAMMERS: Alexander Shaposhnikov (chaez.san@gmail.com)
7 */
8
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 CmdParser(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 // Setup key - single app expected
29 // TODO: use DB filenames as names because they're shorter
30
31 ATL::CSimpleArray<ATL::CStringW> arrNames;
32 if (!StrCmpW(argv[0], CMD_KEY_INSTALL))
33 {
34 for (INT i = 1; i < argc; ++i)
35 {
36 arrNames.Add(argv[i]);
37 }
38 }
39 else
40 if (!StrCmpW(argv[0], CMD_KEY_SETUP))
41 {
42 HINF InfHandle = SetupOpenInfFileW(argv[1], NULL, INF_STYLE_WIN4, NULL);
43 if (InfHandle == INVALID_HANDLE_VALUE)
44 {
45 return FALSE;
46 }
47
48 INFCONTEXT Context;
49 if (SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
50 {
51 WCHAR szName[MAX_PATH];
52 do
53 {
54 if (SetupGetStringFieldW(&Context, 1, szName, MAX_PATH, NULL))
55 {
56 arrNames.Add(szName);
57 }
58 } while (SetupFindNextLine(&Context, &Context));
59 }
60 SetupCloseInfFile(InfHandle);
61 }
62 else
63 {
64 return FALSE;
65 }
66
67 CAvailableApps apps;
68 apps.UpdateAppsDB();
69 apps.Enum(ENUM_ALL_AVAILABLE, NULL);
70
71 ATL::CSimpleArray<CAvailableApplicationInfo*> arrAppInfo = apps.FindInfoList(arrNames);
72 if (arrAppInfo.GetSize() > 0)
73 {
74 CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE);
75 return TRUE;
76 }
77
78 return FALSE;
79 }