ReactOS 0.4.17-dev-444-g71ee754
addons.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS System Setup
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * or GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
5 * PURPOSE: Addon installation management
6 * COPYRIGHT: Copyright 2026 Carl Bialorucki <carl.bialorucki@reactos.org>
7 */
8
9#include "precomp.h"
10#include <strsafe.h>
11
12typedef enum _RappsConsent {
15 DENIED
17
18typedef struct _ADDON_INSTALL_DATA
19{
26
27/* TODO: Move this out of code and into an .inf or something. */
28static const ADDON_INSTALL_DATA Addons[] = {
29#ifdef _M_IX86
30 {L"Wine Gecko", L"%SystemRoot%\\wine_gecko-2.40-x86.msi", L"msiexec.exe /i \"%s\" /qn /norestart", L"gecko"},
31 {L"WineVDM", L"%SystemRoot%\\winevdm_setup.exe", L"\"%s\" /VERYSILENT", L"winevdm"},
32#endif
33 {NULL, NULL, NULL}
34};
35
39{
40 STARTUPINFOW si = { sizeof(si) };
42 DWORD ExitCode = 0;
43
45 0, NULL, NULL, &si, &pi))
46 {
48 GetExitCodeProcess(pi.hProcess, &ExitCode);
51 if (ExitCode == 0)
52 return S_OK;
53 }
54
56}
57
60{
62 return (attr != INVALID_FILE_ATTRIBUTES &&
64}
65
68 _In_ PCADDON_INSTALL_DATA pInstallData,
69 _Inout_ RappsConsent* Consent,
70 _In_ PITEMSDATA pItemsData,
72{
73 HRESULT hr;
74 WCHAR Command[MAX_PATH], ExpandedAddonPath[MAX_PATH];
75
76 pNotify->Progress++;
77 pNotify->CurrentItem = pInstallData->Title;
78 SendMessage(pItemsData->hwndDlg, PM_STEP_START, 3, (LPARAM)pNotify);
79
80 ExpandEnvironmentStringsW(pInstallData->AddonPath,
81 ExpandedAddonPath,
82 ARRAYSIZE(ExpandedAddonPath));
83
84 /* Attempt to install addon from local installer. */
85 if (!DoesFileExist(ExpandedAddonPath))
86 goto rapps_install;
87
89 pInstallData->CreateProcessFormatString, ExpandedAddonPath);
90 if (!SUCCEEDED(hr))
91 goto done;
92
94 if (SUCCEEDED(hr))
95 {
96 /* We successfully installed the addon locally! Try removing it from disk and finish. */
97 DeleteFileW(ExpandedAddonPath);
98 goto done;
99 }
100
101rapps_install:
102 /* Local installer doesn't exist or failed. Try installing through Rapps. */
103 if (*Consent == NOT_ASKED)
104 {
105 WCHAR szMessage[256], szCaption[64];
108 int MsgBox = MessageBoxW(NULL, szMessage, szCaption,
110 *Consent = (MsgBox == IDYES) ? APPROVED : DENIED;
111 }
112
113 if (*Consent == DENIED)
114 {
116 goto done;
117 }
118
119 hr = StringCchPrintfW(Command, ARRAYSIZE(Command), L"rapps.exe /install /S %s", pInstallData->RappsId);
120 if (!SUCCEEDED(hr))
121 goto done;
122
124
125done:
126 /* We don't set an error in pNotify because the user chose to cancel rapps install.
127 * Showing an error may make the user think the installation of the operating system failed. */
129 pNotify->LastError = HRESULT_CODE(hr);
130 SendMessage(pItemsData->hwndDlg, PM_STEP_END, 3, (LPARAM)pNotify);
131 return hr;
132}
133
136 _In_ PITEMSDATA pItemsData)
137{
138 HRESULT hr;
139 PSETUPDATA pSetupData;
141 RappsConsent Consent = NOT_ASKED;
142
143 /* The last element in Addons is null, don't count it as a step. */
144 SendMessage(pItemsData->hwndDlg, PM_ITEM_START, 3, (LPARAM)(ARRAYSIZE(Addons) - 1));
145 pSetupData = (PSETUPDATA)GetWindowLongPtr(pItemsData->hwndDlg, GWLP_USERDATA);
146
147 if (pSetupData->UnattendSetup)
148 Consent = pSetupData->RappsDownload ? APPROVED : DENIED;
149
150 for (DWORD i = 0; i < ARRAYSIZE(Addons); i++)
151 {
152 if (Addons[i].AddonPath == NULL
153 || Addons[i].CreateProcessFormatString == NULL
154 || Addons[i].RappsId == NULL)
155 continue;
156
157 hr = InstallAddon(&Addons[i], &Consent, pItemsData, &Notify);
158
159 /* Cancelling rapps install is not an error. Reset hr to S_OK. */
161 hr = S_OK;
162
163 if (!SUCCEEDED(hr))
164 {
165 WCHAR szMessage[256], szCaption[64];
168 MessageBoxW(NULL, szMessage, szCaption,
170 break;
171 }
172 }
173
174 SendMessage(pItemsData->hwndDlg, PM_ITEM_END, 3, HRESULT_CODE(hr));
175 return hr;
176}
struct _SETUPDATA * PSETUPDATA
static HINSTANCE hDllInstance
Definition: clb.c:9
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI SHIM_OBJ_NAME() Notify(DWORD fdwReason, PVOID ptr)
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:492
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:636
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4441
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1165
#define PM_STEP_START
Definition: globals.h:62
#define PM_ITEM_START
Definition: globals.h:52
#define PM_ITEM_END
Definition: globals.h:57
#define PM_STEP_END
Definition: globals.h:63
#define IDS_INSTALLADDONSFAILEDMESSAGE
Definition: resource.h:193
#define IDS_INSTALLADDONSCAPTION
Definition: resource.h:191
#define IDS_INSTALLADDONSMESSAGE
Definition: resource.h:192
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
#define DoesFileExist(RootDirectory, FileName)
Definition: filesup.h:83
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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 S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
LONG_PTR LPARAM
Definition: minwindef.h:175
static PROCESS_INFORMATION pi
Definition: debugger.c:2303
static SYSTEM_INFO si
Definition: virtual.c:39
#define _Inout_
Definition: no_sal2.h:162
#define _In_
Definition: no_sal2.h:158
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
short WCHAR
Definition: pedump.c:58
#define LoadStringW
Definition: utils.h:64
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
Definition: shell.h:41
PCWSTR CreateProcessFormatString
Definition: addons.c:22
PCWSTR RappsId
Definition: addons.c:23
PCWSTR AddonPath
Definition: addons.c:21
BOOL UnattendSetup
Definition: syssetup.h:50
BOOL RappsDownload
Definition: syssetup.h:51
Definition: cookie.c:202
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define GetWindowLongPtr
Definition: treelist.c:73
#define GWLP_USERDATA
Definition: treelist.c:63
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint16_t * PWCHAR
Definition: typedefs.h:56
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_RappsConsent
Definition: addons.c:12
@ APPROVED
Definition: addons.c:14
@ DENIED
Definition: addons.c:15
@ NOT_ASKED
Definition: addons.c:13
struct _ADDON_INSTALL_DATA * PADDON_INSTALL_DATA
HRESULT InstallAddon(_In_ PCADDON_INSTALL_DATA pInstallData, _Inout_ RappsConsent *Consent, _In_ PITEMSDATA pItemsData, _Inout_ PREGISTRATIONNOTIFY pNotify)
Definition: addons.c:67
HRESULT RunCommandAndWait(_In_ PWCHAR Command)
Definition: addons.c:37
enum _RappsConsent RappsConsent
static const ADDON_INSTALL_DATA Addons[]
Definition: addons.c:28
const ADDON_INSTALL_DATA * PCADDON_INSTALL_DATA
Definition: addons.c:25
HRESULT InstallOptionalComponents(_In_ PITEMSDATA pItemsData)
Definition: addons.c:135
struct _ADDON_INSTALL_DATA ADDON_INSTALL_DATA
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_CANCELLED
Definition: winerror.h:1055
#define HRESULT_CODE(hr)
Definition: winerror.h:188
#define MB_TOPMOST
Definition: winuser.h:836
#define MB_YESNO
Definition: winuser.h:828
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define SendMessage
Definition: winuser.h:6009
#define MB_OK
Definition: winuser.h:801
#define MB_ICONWARNING
Definition: winuser.h:797
#define MB_ICONINFORMATION
Definition: winuser.h:813
#define IDYES
Definition: winuser.h:846