c23b8bfd718c12a54457a31856cfe792de73ab21
[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: add multiple apps
21 // TODO: use DB filenames as names because they're shorter
22
23 // app setup
24 ATL::CSimpleArray<ATL::CStringW> arrNames;
25 if (!StrCmpW(argv[0], CMD_KEY_INSTALL))
26 {
27 for (int i = 1; i < argc; ++i)
28 {
29 arrNames.Add(argv[i]);
30 }
31 }
32 else
33 if (!StrCmpW(argv[0], CMD_KEY_SETUP))
34 {
35 //TODO: inf file loading
36 HINF InfHandle = SetupOpenInfFileW(argv[1], NULL, INF_STYLE_WIN4, NULL);
37 if (InfHandle == INVALID_HANDLE_VALUE)
38 {
39 return FALSE;
40 }
41
42 INFCONTEXT Context;
43 if (!SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
44 {
45 return FALSE;
46 }
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 }
56 while (SetupFindNextLine(&Context, &Context));
57 SetupCloseInfFile(InfHandle);
58 }
59
60 CAvailableApps apps;
61 apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL);
62 ATL::CSimpleArray<PAPPLICATION_INFO> arrAppInfo = apps.FindInfoList(arrNames);
63 if (arrAppInfo.GetSize() > 0)
64 {
65 CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE);
66 return TRUE;
67 }
68
69 return FALSE;
70 }
71