[RAPPS]
[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 }
58
59 CAvailableApps apps;
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 }
70