ReactOS 0.4.15-dev-8236-g99f0937
main.c
Go to the documentation of this file.
1#define WIN32_NO_STATUS
2#define WIN32_LEAN_AND_MEAN
3#include <windows.h>
4#include <shellapi.h>
5#include <shlobj.h>
6#include <setupapi.h>
7
8#define NT_PARAMS L"NT3.51 Intel Params"
9#define MSSETUP_PATH L"~MSSETUP.T\\"
10
12{
14 FILEPATHS_W *pFilePaths;
15
17
18 switch(Notification)
19 {
21 pInfo = (FILE_IN_CABINET_INFO_W*)Param1;
23 wcscat(pInfo->FullTargetName, pInfo->NameInCabinet);
24 return FILEOP_DOIT;
26 pFilePaths = (FILEPATHS_W*)Param1;
27 return NO_ERROR;
28 }
29 return NO_ERROR;
30}
31
33{
34 SHFILEOPSTRUCT fileop;
35 DWORD len = wcslen(lpszDir);
36 WCHAR *pszFrom = HeapAlloc(GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
37 int ret;
38
39 wcscpy(pszFrom, lpszDir);
40 pszFrom[len] = 0;
41 pszFrom[len+1] = 0;
42
43 fileop.hwnd = NULL;
44 fileop.wFunc = FO_DELETE;
45 fileop.pFrom = pszFrom;
46 fileop.pTo = NULL;
49 fileop.lpszProgressTitle = NULL;
50 fileop.hNameMappings = NULL;
51
52 ret = SHFileOperation(&fileop);
53 HeapFree(GetProcessHeap(), 0, pszFrom);
54 return (ret == 0);
55}
56
58{
59 WCHAR szWindir[MAX_PATH];
61 _wsplitpath(szWindir, lpszDrive, NULL, NULL, NULL);
62 wcscat(lpszDrive, L"\\");
63}
64
66 HINSTANCE hPrevInstance,
67 LPWSTR lpCmdLine,
68 int nCmdShow)
69{
70 WCHAR szSetupPath[MAX_PATH];
71 WCHAR szFileName[MAX_PATH];
72 WCHAR szCabFileName[MAX_PATH];
73 WCHAR szCabFilePath[MAX_PATH];
74 WCHAR szTempDirName[50];
75 WCHAR szCmdLine[MAX_PATH];
76 WCHAR szTempCmdLine[MAX_PATH];
78 WCHAR szFullTempPath[MAX_PATH];
79 WCHAR szDrive[4];
80 DWORD dwAttrib;
81 PROCESS_INFORMATION processInfo;
82 STARTUPINFO startupInfo;
83 UNREFERENCED_PARAMETER(hPrevInstance);
84 UNREFERENCED_PARAMETER(nCmdShow);
85
86 GetCurrentDirectory(MAX_PATH, szSetupPath);
87 wcscat(szSetupPath, L"\\");
88 wcscpy(szFileName, szSetupPath);
89 wcscat(szFileName, L"setup.lst");
90
92 {
93 MessageBoxW(0, L"Cannot find Setup.lst file", L"Error", MB_OK | MB_ICONERROR);
94 return 1;
95 }
96
97 /* read information from setup.lst */
98 GetPrivateProfileStringW(NT_PARAMS, L"CabinetFile", NULL, szCabFileName, MAX_PATH, szFileName);
99 GetPrivateProfileStringW(NT_PARAMS, L"TmpDirName", NULL, szTempDirName, 50, szFileName);
100 GetPrivateProfileStringW(NT_PARAMS, L"CmdLine", NULL, szCmdLine, MAX_PATH, szFileName);
101
102 wcscpy(szCabFilePath, szSetupPath);
103 wcscat(szCabFilePath, szCabFileName);
104
105 /* ceate temp directory */
106 GetSystemDrive(szDrive);
107 wcscpy(szTempPath, szDrive);
109 wcscpy(szFullTempPath, szTempPath);
110 wcscat(szFullTempPath, szTempDirName);
111 wcscat(szFullTempPath, L"\\");
112
113 if (SHCreateDirectoryEx(0, szFullTempPath, NULL) != ERROR_SUCCESS)
114 {
115 MessageBoxW(0, L"Could not create Temp Directory.", L"Error", MB_OK | MB_ICONERROR);
116 return 1;
117 }
118
119 dwAttrib = GetFileAttributes(szTempPath);
121
122 /* extract files */
123 if (!SetupIterateCabinetW(szCabFilePath, 0, ExtCabCallback, szFullTempPath))
124 {
125 MessageBoxW(0, L"Could not extract cab file", L"Error", MB_OK | MB_ICONERROR);
127 return 1;
128 }
129
130 /* prepare command line */
131 wsprintf(szTempCmdLine, szCmdLine, szFullTempPath, lpCmdLine);
132 wcscpy(szCmdLine, szFullTempPath);
133 wcscat(szCmdLine, szTempCmdLine);
134
135 /* execute the 32-Bit installer */
136 ZeroMemory(&processInfo, sizeof(processInfo));
137 ZeroMemory(&startupInfo, sizeof(startupInfo));
138 startupInfo.cb = sizeof(startupInfo);
139 if (CreateProcessW(NULL, szCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, szFullTempPath, &startupInfo, &processInfo))
140 {
142 CloseHandle(processInfo.hProcess);
143 CloseHandle(processInfo.hThread);
144 }
145 else
146 {
147 WCHAR szMsg[MAX_PATH];
148 wsprintf(szMsg, L"Failed to load the installer. Error %lu", GetLastError());
149 MessageBoxW(0, szMsg, L"Error", MB_OK | MB_ICONERROR);
151 return 1;
152 }
153
154 /* cleanup */
156
157 return 0;
158}
159
160/* EOF */
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
Definition: main.c:788
#define MSSETUP_PATH
Definition: main.c:9
static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2)
Definition: main.c:11
VOID GetSystemDrive(LPWSTR lpszDrive)
Definition: main.c:57
#define NT_PARAMS
Definition: main.c:8
BOOL DeleteDirectory(LPWSTR lpszDir)
Definition: main.c:32
HINSTANCE hInstance
Definition: charmap.c:19
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
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:4592
INT WINAPI GetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len, LPCWSTR filename)
Definition: profile.c:1142
BOOL WINAPI SetupIterateCabinetW(PCWSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_W MsgHandler, PVOID Context)
Definition: setupcab.c:575
#define INFINITE
Definition: serial.h:102
#define FILEOP_DOIT
Definition: fileqsup.h:48
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP void __cdecl _wsplitpath(_In_z_ const wchar_t *_FullPath, _Pre_maybenull_ _Post_z_ wchar_t *_Drive, _Pre_maybenull_ _Post_z_ wchar_t *_Dir, _Pre_maybenull_ _Post_z_ wchar_t *_Filename, _Pre_maybenull_ _Post_z_ wchar_t *_Ext)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static char szTempPath[MAX_PATH]
Definition: data.c:16
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:319
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define SPFILENOTIFY_FILEEXTRACTED
Definition: setupapi.h:564
#define SPFILENOTIFY_FILEINCABINET
Definition: setupapi.h:562
#define FO_DELETE
Definition: shellapi.h:138
#define FOF_NOCONFIRMATION
Definition: shellapi.h:145
#define SHFileOperation
Definition: shellapi.h:696
#define FOF_SILENT
Definition: shellapi.h:143
#define SHCreateDirectoryEx
Definition: shlobj.h:2116
WCHAR FullTargetName[MAX_PATH]
Definition: setupapi.h:804
PVOID hNameMappings
Definition: shellapi.h:351
LPCSTR lpszProgressTitle
Definition: shellapi.h:352
FILEOP_FLAGS fFlags
Definition: shellapi.h:349
BOOL fAnyOperationsAborted
Definition: shellapi.h:350
DWORD cb
Definition: winbase.h:831
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetFileAttributes
Definition: winbase.h:3815
#define SetFileAttributes
Definition: winbase.h:3909
#define GetCurrentDirectory
Definition: winbase.h:3805
#define WINAPI
Definition: msvc.h:6
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:787
#define MB_OK
Definition: winuser.h:790
#define wsprintf
Definition: winuser.h:5874
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185