ReactOS 0.4.15-dev-7842-g558ab78
unattended.cpp File Reference
#include "gui.h"
#include "unattended.h"
#include <setupapi.h>
#include <conutils.h>
Include dependency graph for unattended.cpp:

Go to the source code of this file.

Functions

static BOOL MatchCmdOption (LPWSTR argvOption, LPCWSTR szOptToMacth)
 
static void InitRappsConsole ()
 
static BOOL HandleInstallCommand (CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
 
static BOOL HandleSetupCommand (CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
 
static BOOL HandleFindCommand (CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
 
static BOOL HandleInfoCommand (CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
 
static VOID PrintHelpCommand ()
 
BOOL ParseCmdAndExecute (LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
 

Function Documentation

◆ HandleFindCommand()

static BOOL HandleFindCommand ( CAppDB db,
LPWSTR  szCommand,
int  argcLeft,
LPWSTR argvLeft 
)
static

Definition at line 108 of file unattended.cpp.

109{
110 if (argcLeft < 1)
111 {
113 return FALSE;
114 }
115
116 CAtlList<CAppInfo *> List;
118
119 for (int i = 0; i < argcLeft; i++)
120 {
121 LPCWSTR lpszSearch = argvLeft[i];
123
124 POSITION CurrentListPosition = List.GetHeadPosition();
125 while (CurrentListPosition)
126 {
127 CAppInfo *Info = List.GetNext(CurrentListPosition);
128
129 if (SearchPatternMatch(Info->szDisplayName, lpszSearch) || SearchPatternMatch(Info->szComments, lpszSearch))
130 {
131 ConPrintf(StdOut, L"%s (%s)\n", Info->szDisplayName.GetString(), Info->szIdentifier.GetString());
132 }
133 }
134
135 ConPrintf(StdOut, L"\n");
136 }
137
138 return TRUE;
139}
@ ENUM_ALL_AVAILABLE
Definition: appinfo.h:26
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
Definition: misc.cpp:372
#define IDS_CMD_FIND_RESULT_FOR
Definition: resource.h:227
#define IDS_CMD_NEED_PARAMS
Definition: resource.h:225
VOID GetApps(CAtlList< CAppInfo * > &List, AppsCategories Type) const
Definition: appdb.cpp:53
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define L(x)
Definition: ntvdm.h:50
INT __cdecl ConResMsgPrintf(IN PCON_STREAM Stream, IN DWORD dwFlags, IN UINT uID,...)
Definition: outstream.c:1461
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ParseCmdAndExecute().

◆ HandleInfoCommand()

static BOOL HandleInfoCommand ( CAppDB db,
LPWSTR  szCommand,
int  argcLeft,
LPWSTR argvLeft 
)
static

Definition at line 142 of file unattended.cpp.

143{
144 if (argcLeft < 1)
145 {
147 return FALSE;
148 }
149
150 for (int i = 0; i < argcLeft; i++)
151 {
152 LPCWSTR PackageName = argvLeft[i];
153 CAppInfo *AppInfo = db->FindByPackageName(PackageName);
154 if (!AppInfo)
155 {
157 }
158 else
159 {
161
162 ConPuts(StdOut, AppInfo->szDisplayName);
163
164 if (!AppInfo->szDisplayVersion.IsEmpty())
165 {
168 }
169
170 CStringW License, Size, UrlSite, UrlDownload;
171 AppInfo->GetDisplayInfo(License, Size, UrlSite, UrlDownload);
172
173 if (!License.IsEmpty())
174 {
176 ConPuts(StdOut, License);
177 }
178
179 if (!Size.IsEmpty())
180 {
183 }
184
185 if (!UrlSite.IsEmpty())
186 {
188 ConPuts(StdOut, UrlSite);
189 }
190
191 if (AppInfo->szComments)
192 {
194 ConPuts(StdOut, AppInfo->szComments);
195 }
196
197 if (!UrlDownload.IsEmpty())
198 {
200 ConPuts(StdOut, UrlDownload);
201 }
202 ConPuts(StdOut, L"\n");
203 }
204 ConPuts(StdOut, L"\n");
205 }
206 return TRUE;
207}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define IDS_AINFO_SIZE
Definition: resource.h:163
#define IDS_AINFO_VERSION
Definition: resource.h:161
#define IDS_CMD_PACKAGE_INFO
Definition: resource.h:229
#define IDS_AINFO_LICENSE
Definition: resource.h:165
#define IDS_AINFO_DESCRIPTION
Definition: resource.h:162
#define IDS_AINFO_URLSITE
Definition: resource.h:164
#define IDS_AINFO_URLDOWNLOAD
Definition: resource.h:166
#define IDS_CMD_PACKAGE_NOT_FOUND
Definition: resource.h:228
CAppInfo * FindByPackageName(const CStringW &name)
Definition: appdb.cpp:38
CStringW szComments
Definition: appinfo.h:80
CStringW szDisplayName
Definition: appinfo.h:78
virtual VOID GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload)=0
CStringW szDisplayVersion
Definition: appinfo.h:79
CAtlStringW CStringW
Definition: atlstr.h:130
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by ParseCmdAndExecute().

◆ HandleInstallCommand()

static BOOL HandleInstallCommand ( CAppDB db,
LPWSTR  szCommand,
int  argcLeft,
LPWSTR argvLeft 
)
static

Definition at line 46 of file unattended.cpp.

47{
48 if (argcLeft < 1)
49 {
52 return FALSE;
53 }
54
55 CAtlList<CAppInfo *> Applications;
56 for (int i = 0; i < argcLeft; i++)
57 {
58 LPCWSTR PackageName = argvLeft[i];
59 CAppInfo *AppInfo = db->FindByPackageName(PackageName);
60 if (AppInfo)
61 {
62 Applications.AddTail(AppInfo);
63 }
64 }
65
66 return DownloadListOfApplications(Applications, TRUE);
67}
#define IDS_CMD_NEED_PACKAGE_NAME
Definition: resource.h:223
BOOL DownloadListOfApplications(const CAtlList< CAppInfo * > &AppsList, BOOL bIsModal)
Definition: loaddlg.cpp:1089
static void InitRappsConsole()
Definition: unattended.cpp:30

Referenced by ParseCmdAndExecute().

◆ HandleSetupCommand()

static BOOL HandleSetupCommand ( CAppDB db,
LPWSTR  szCommand,
int  argcLeft,
LPWSTR argvLeft 
)
static

Definition at line 70 of file unattended.cpp.

71{
72 if (argcLeft != 1)
73 {
76 return FALSE;
77 }
78
79 CAtlList<CAppInfo *> Applications;
80 HINF InfHandle = SetupOpenInfFileW(argvLeft[0], NULL, INF_STYLE_WIN4, NULL);
81 if (InfHandle == INVALID_HANDLE_VALUE)
82 {
83 return FALSE;
84 }
85
87 if (SetupFindFirstLineW(InfHandle, L"RAPPS", L"Install", &Context))
88 {
89 WCHAR szPkgName[MAX_PATH];
90 do
91 {
92 if (SetupGetStringFieldW(&Context, 1, szPkgName, _countof(szPkgName), NULL))
93 {
94 CAppInfo *AppInfo = db->FindByPackageName(szPkgName);
95 if (AppInfo)
96 {
97 Applications.AddTail(AppInfo);
98 }
99 }
100 } while (SetupFindNextLine(&Context, &Context));
101 }
102 SetupCloseInfFile(InfHandle);
103
104 return DownloadListOfApplications(Applications, TRUE);
105}
#define IDS_CMD_NEED_FILE_NAME
Definition: resource.h:224
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define _countof(array)
Definition: sndvol32.h:68
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:186
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:56
BOOL WINAPI SetupFindNextLine(IN PINFCONTEXT ContextIn, OUT PINFCONTEXT ContextOut)
Definition: infsupp.c:82
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ParseCmdAndExecute().

◆ InitRappsConsole()

static void InitRappsConsole ( )
static

Definition at line 30 of file unattended.cpp.

31{
32 // First, try to attach to our parent's console
34 {
35 // Did we already have a console?
37 {
38 // No, try to open a new one
40 }
41 }
42 ConInitStdStreams(); // Initialize the Console Standard Streams
43}
#define ConInitStdStreams()
Definition: fc.c:13
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
BOOL WINAPI AttachConsole(IN DWORD dwProcessId)
Definition: console.c:147
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ATTACH_PARENT_PROCESS
Definition: wincon.h:21

Referenced by HandleInstallCommand(), HandleSetupCommand(), and ParseCmdAndExecute().

◆ MatchCmdOption()

static BOOL MatchCmdOption ( LPWSTR  argvOption,
LPCWSTR  szOptToMacth 
)
static

Definition at line 15 of file unattended.cpp.

16{
17 WCHAR FirstCharList[] = {L'-', L'/'};
18
19 for (UINT i = 0; i < _countof(FirstCharList); i++)
20 {
21 if (argvOption[0] == FirstCharList[i])
22 {
23 return StrCmpIW(argvOption + 1, szOptToMacth) == 0;
24 }
25 }
26 return FALSE;
27}
int WINAPI StrCmpIW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:353
unsigned int UINT
Definition: ndis.h:50

Referenced by ParseCmdAndExecute().

◆ ParseCmdAndExecute()

BOOL ParseCmdAndExecute ( LPWSTR  lpCmdLine,
BOOL  bIsFirstLaunch,
int  nCmdShow 
)

Definition at line 221 of file unattended.cpp.

222{
223 INT argc;
224 LPWSTR *argv = CommandLineToArgvW(lpCmdLine, &argc);
225 if (!argv)
226 return FALSE;
227
230 CAppDB db(Directory);
231
232 BOOL bAppwizMode = (argc > 1 && MatchCmdOption(argv[1], CMD_KEY_APPWIZ));
233 if (!bAppwizMode)
234 {
235 if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
236 db.RemoveCached();
237
238 db.UpdateAvailable();
239 }
240
241 db.UpdateInstalled();
242
243 if (argc == 1 || bAppwizMode) // RAPPS is launched without options or APPWIZ mode is requested
244 {
245 // Check whether the RAPPS MainWindow is already launched in another process
247
250 {
251 /* If already started, find its window */
253
254 /* Activate window */
255 ShowWindow(hWindow, SW_SHOWNORMAL);
256 SetForegroundWindow(hWindow);
257 if (bAppwizMode)
259 return FALSE;
260 }
261
262 CMainWindow wnd(&db, bAppwizMode);
263 MainWindowLoop(&wnd, nCmdShow);
264
265 if (hMutex)
267
268 return TRUE;
269 }
270
272 {
273 return HandleInstallCommand(&db, argv[1], argc - 2, argv + 2);
274 }
275 else if (MatchCmdOption(argv[1], CMD_KEY_SETUP))
276 {
277 return HandleSetupCommand(&db, argv[1], argc - 2, argv + 2);
278 }
279
281
283 {
284 return HandleFindCommand(&db, argv[1], argc - 2, argv + 2);
285 }
286 else if (MatchCmdOption(argv[1], CMD_KEY_INFO))
287 {
288 return HandleInfoCommand(&db, argv[1], argc - 2, argv + 2);
289 }
291 {
293 return TRUE;
294 }
295 else
296 {
297 // unrecognized/invalid options
300 return FALSE;
301 }
302}
static int argc
Definition: ServiceArgs.c:12
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL GetStorageDirectory(CStringW &lpDirectory)
Definition: misc.cpp:145
#define ID_ACTIVATE_APPWIZ
Definition: resource.h:89
#define IDS_CMD_INVALID_OPTION
Definition: resource.h:226
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:20
Definition: appdb.h:9
#define CloseHandle
Definition: compat.h:739
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID MainWindowLoop(CMainWindow *wnd, INT nShowCmd)
Definition: gui.cpp:798
const TCHAR szWindowClass[]
Definition: magnifier.c:28
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
HANDLE hMutex
Definition: mutex.c:11
#define argv
Definition: mplay32.c:18
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:80
base for all directory entries
Definition: entries.h:138
BOOL bUpdateAtStart
Definition: settings.h:8
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
int32_t INT
Definition: typedefs.h:58
static BOOL HandleInfoCommand(CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
Definition: unattended.cpp:142
static BOOL MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth)
Definition: unattended.cpp:15
static BOOL HandleFindCommand(CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
Definition: unattended.cpp:108
static VOID PrintHelpCommand()
Definition: unattended.cpp:210
static BOOL HandleInstallCommand(CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
Definition: unattended.cpp:46
static BOOL HandleSetupCommand(CAppDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
Definition: unattended.cpp:70
#define CMD_KEY_INFO
Definition: unattended.h:7
#define CMD_KEY_INSTALL
Definition: unattended.h:4
#define CMD_KEY_SETUP
Definition: unattended.h:5
#define CMD_KEY_HELP
Definition: unattended.h:8
#define CMD_KEY_HELP_ALT
Definition: unattended.h:9
#define CMD_KEY_APPWIZ
Definition: unattended.h:3
#define CMD_KEY_FIND
Definition: unattended.h:6
#define SW_SHOWNORMAL
Definition: winuser.h:770
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1740
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define PostMessage
Definition: winuser.h:5832
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by wWinMain().

◆ PrintHelpCommand()

static VOID PrintHelpCommand ( )
static

Definition at line 210 of file unattended.cpp.

211{
212 ConPrintf(StdOut, L"\n");
214 ConPrintf(StdOut, L"\n\n");
215
217 ConPrintf(StdOut, L"%ls\n", UsageString);
218}
#define IDS_APPTITLE
Definition: resource.h:3
#define IDS_CMD_USAGE
Definition: resource.h:222
const WCHAR UsageString[]
Definition: unattended.h:12

Referenced by ParseCmdAndExecute().