ReactOS  0.4.12-dev-43-g63b00d8
unattended.cpp
Go to the documentation of this file.
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 
10 #include "unattended.h"
11 
12 #include <setupapi.h>
13 
14 #define MIN_ARGS 3
15 
17 {
18  INT argc;
19  LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
20 
21  if (!argv || argc < MIN_ARGS)
22  {
23  return FALSE;
24  }
25 
26  // TODO: use DB filenames as names because they're shorter
28  if (!StrCmpIW(argv[1], CMD_KEY_INSTALL))
29  {
30  for (INT i = 2; i < argc; ++i)
31  {
32  arrNames.Add(argv[i]);
33  }
34  }
35  else
36  if (!StrCmpIW(argv[1], CMD_KEY_SETUP))
37  {
38  HINF InfHandle = SetupOpenInfFileW(argv[2], NULL, INF_STYLE_WIN4, NULL);
39  if (InfHandle == INVALID_HANDLE_VALUE)
40  {
41  return FALSE;
42  }
43 
45  if (SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
46  {
48  do
49  {
50  if (SetupGetStringFieldW(&Context, 1, szName, _countof(szName), NULL))
51  {
52  arrNames.Add(szName);
53  }
54  } while (SetupFindNextLine(&Context, &Context));
55  }
56  SetupCloseInfFile(InfHandle);
57  }
58  else
59  {
60  return FALSE;
61  }
62 
63  CAvailableApps apps;
64  apps.UpdateAppsDB();
66 
68  if (arrAppInfo.GetSize() > 0)
69  {
71  return TRUE;
72  }
73 
74  return FALSE;
75 }
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:52
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define CMD_KEY_SETUP
Definition: unattended.h:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CMD_KEY_INSTALL
Definition: unattended.h:3
#define _countof(array)
Definition: fontsub.cpp:30
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
static BOOL UpdateAppsDB()
Definition: available.cpp:285
int GetSize() const
Definition: atlsimpcoll.h:104
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
#define MIN_ARGS
Definition: unattended.cpp:14
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ATL::CSimpleArray< CAvailableApplicationInfo > FindInfoList(const ATL::CSimpleArray< ATL::CStringW > &arrAppsNames) const
Definition: available.cpp:413
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:76
smooth NULL
Definition: ftsmooth.c:416
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1087
BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc)
Definition: available.cpp:323
static BOOL DownloadListOfApplications(const ATL::CSimpleArray< CAvailableApplicationInfo > &AppsList, BOOL bIsModal=FALSE)
Definition: loaddlg.cpp:930
BOOL UseCmdParameters(LPWSTR lpCmdLine)
Definition: unattended.cpp:16
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:75
static const WCHAR szName[]
Definition: msipriv.h:1194
struct tagContext Context
Definition: acpixf.h:1027
WCHAR * LPWSTR
Definition: xmlstorage.h:184
int WINAPI StrCmpIW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:353
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:179