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