ReactOS  0.4.12-dev-57-g7050ac4
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 
11 static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2)
12 {
14  FILEPATHS_W *pFilePaths;
15 
17 
18  switch(Notification)
19  {
21  pInfo = (FILE_IN_CABINET_INFO_W*)Param1;
22  wcscpy(pInfo->FullTargetName, (LPCWSTR)Context);
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];
60  GetWindowsDirectoryW(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 
91  if (GetFileAttributes(szFileName) == INVALID_FILE_ATTRIBUTES)
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);
108  wcscat(szTempPath, MSSETUP_PATH);
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);
120  SetFileAttributes(szTempPath, dwAttrib | FILE_ATTRIBUTE_HIDDEN);
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);
126  DeleteDirectory(szTempPath);
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  {
141  WaitForSingleObject(processInfo.hProcess, INFINITE);
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);
150  DeleteDirectory(szTempPath);
151  return 1;
152  }
153 
154  /* cleanup */
155  DeleteDirectory(szTempPath);
156 
157  return 0;
158 }
159 
160 /* EOF */
void _wsplitpath(const WCHAR *path, WCHAR *drv, WCHAR *dir, WCHAR *name, WCHAR *ext)
Definition: splitpath.c:22
#define NT_PARAMS
Definition: main.c:8
INT WINAPI GetPrivateProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len, LPCWSTR filename)
Definition: profile.c:1142
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SPFILENOTIFY_FILEEXTRACTED
Definition: setupapi.h:559
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
__wchar_t WCHAR
Definition: xmlstorage.h:180
FILEOP_FLAGS fFlags
Definition: shellapi.h:345
#define FOF_SILENT
Definition: shellapi.h:140
static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2)
Definition: main.c:11
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI SetupIterateCabinetW(PCWSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_W MsgHandler, PVOID Context)
Definition: setupcab.c:575
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define NO_ERROR
Definition: dderror.h:5
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
BOOL DeleteDirectory(LPWSTR lpszDir)
Definition: main.c:32
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define GetCurrentDirectory
Definition: winbase.h:3619
LPCSTR lpszProgressTitle
Definition: shellapi.h:348
#define APIENTRY
Definition: nt_native.h:48
WCHAR FullTargetName[MAX_PATH]
Definition: setupapi.h:799
#define FOF_NOCONFIRMATION
Definition: shellapi.h:142
smooth NULL
Definition: ftsmooth.c:416
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:4623
static TCHAR szTempPath[MAX_PATH]
Definition: CImage.cpp:45
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
#define FILEOP_DOIT
Definition: fileqsup.h:48
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD cb
Definition: winbase.h:796
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define SetFileAttributes
Definition: winbase.h:3723
#define MAX_PATH
Definition: compat.h:26
unsigned int UINT
Definition: ndis.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
HINSTANCE hInstance
Definition: main.c:36
#define SHFileOperation
Definition: shellapi.h:682
#define MSSETUP_PATH
Definition: main.c:9
BOOL fAnyOperationsAborted
Definition: shellapi.h:346
PVOID hNameMappings
Definition: shellapi.h:347
VOID GetSystemDrive(LPWSTR lpszDrive)
Definition: main.c:57
int ret
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
#define MB_ICONERROR
Definition: winuser.h:781
GLenum GLsizei len
Definition: glext.h:6722
#define SPFILENOTIFY_FILEINCABINET
Definition: setupapi.h:557
#define WINAPI
Definition: msvc.h:20
#define GetFileAttributes
Definition: winbase.h:3629
#define SHCreateDirectoryEx
Definition: shlobj.h:1938
_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 FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define MB_OK
Definition: winuser.h:784
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
Definition: main.c:420
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define wsprintf
Definition: winuser.h:5731
#define INFINITE
Definition: serial.h:102
#define FO_DELETE
Definition: shellapi.h:135
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394