2013-01-24 23:00:42 +00:00
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2012-03-11 10:51:40 +00:00
|
|
|
#include <windows.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <shellapi.h>
|
2012-03-11 10:51:40 +00:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include <setupapi.h>
|
|
|
|
|
|
|
|
#define NT_PARAMS L"NT3.51 Intel Params"
|
|
|
|
#define MSSETUP_PATH L"~MSSETUP.T\\"
|
|
|
|
|
|
|
|
static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2)
|
|
|
|
{
|
|
|
|
FILE_IN_CABINET_INFO_W *pInfo;
|
|
|
|
FILEPATHS_W *pFilePaths;
|
|
|
|
|
2014-05-31 16:58:03 +00:00
|
|
|
DBG_UNREFERENCED_LOCAL_VARIABLE(pFilePaths);
|
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
switch(Notification)
|
|
|
|
{
|
|
|
|
case SPFILENOTIFY_FILEINCABINET:
|
|
|
|
pInfo = (FILE_IN_CABINET_INFO_W*)Param1;
|
|
|
|
wcscpy(pInfo->FullTargetName, (LPCWSTR)Context);
|
|
|
|
wcscat(pInfo->FullTargetName, pInfo->NameInCabinet);
|
|
|
|
return FILEOP_DOIT;
|
|
|
|
case SPFILENOTIFY_FILEEXTRACTED:
|
|
|
|
pFilePaths = (FILEPATHS_W*)Param1;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL DeleteDirectory(LPWSTR lpszDir)
|
|
|
|
{
|
2012-03-11 13:29:59 +00:00
|
|
|
SHFILEOPSTRUCT fileop;
|
2012-03-11 10:51:40 +00:00
|
|
|
DWORD len = wcslen(lpszDir);
|
2014-05-31 16:58:03 +00:00
|
|
|
WCHAR *pszFrom = HeapAlloc(GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
|
2012-03-11 13:29:59 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
wcscpy(pszFrom, lpszDir);
|
|
|
|
pszFrom[len] = 0;
|
|
|
|
pszFrom[len+1] = 0;
|
|
|
|
|
|
|
|
fileop.hwnd = NULL;
|
|
|
|
fileop.wFunc = FO_DELETE;
|
|
|
|
fileop.pFrom = pszFrom;
|
|
|
|
fileop.pTo = NULL;
|
|
|
|
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;
|
|
|
|
fileop.fAnyOperationsAborted = FALSE;
|
|
|
|
fileop.lpszProgressTitle = NULL;
|
|
|
|
fileop.hNameMappings = NULL;
|
|
|
|
|
2012-03-11 13:29:59 +00:00
|
|
|
ret = SHFileOperation(&fileop);
|
2014-04-05 15:47:49 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, pszFrom);
|
2012-03-11 10:51:40 +00:00
|
|
|
return (ret == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID GetSystemDrive(LPWSTR lpszDrive)
|
|
|
|
{
|
|
|
|
WCHAR szWindir[MAX_PATH];
|
|
|
|
GetWindowsDirectoryW(szWindir, MAX_PATH);
|
|
|
|
_wsplitpath(szWindir, lpszDrive, NULL, NULL, NULL);
|
|
|
|
wcscat(lpszDrive, L"\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
LPWSTR lpCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
WCHAR szSetupPath[MAX_PATH];
|
|
|
|
WCHAR szFileName[MAX_PATH];
|
|
|
|
WCHAR szCabFileName[MAX_PATH];
|
|
|
|
WCHAR szCabFilePath[MAX_PATH];
|
|
|
|
WCHAR szTempDirName[50];
|
|
|
|
WCHAR szCmdLine[MAX_PATH];
|
|
|
|
WCHAR szTempCmdLine[MAX_PATH];
|
|
|
|
WCHAR szTempPath[MAX_PATH];
|
|
|
|
WCHAR szFullTempPath[MAX_PATH];
|
|
|
|
WCHAR szDrive[4];
|
|
|
|
DWORD dwAttrib;
|
|
|
|
PROCESS_INFORMATION processInfo;
|
|
|
|
STARTUPINFO startupInfo;
|
2012-03-11 13:29:59 +00:00
|
|
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|
|
|
UNREFERENCED_PARAMETER(nCmdShow);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
GetCurrentDirectory(MAX_PATH, szSetupPath);
|
|
|
|
wcscat(szSetupPath, L"\\");
|
|
|
|
wcscpy(szFileName, szSetupPath);
|
|
|
|
wcscat(szFileName, L"setup.lst");
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 19:04:07 +00:00
|
|
|
if (GetFileAttributes(szFileName) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
MessageBoxW(0, L"Cannot find Setup.lst file", L"Error", MB_OK | MB_ICONERROR);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* read information from setup.lst */
|
|
|
|
GetPrivateProfileStringW(NT_PARAMS, L"CabinetFile", NULL, szCabFileName, MAX_PATH, szFileName);
|
|
|
|
GetPrivateProfileStringW(NT_PARAMS, L"TmpDirName", NULL, szTempDirName, 50, szFileName);
|
|
|
|
GetPrivateProfileStringW(NT_PARAMS, L"CmdLine", NULL, szCmdLine, MAX_PATH, szFileName);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
wcscpy(szCabFilePath, szSetupPath);
|
|
|
|
wcscat(szCabFilePath, szCabFileName);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* ceate temp directory */
|
|
|
|
GetSystemDrive(szDrive);
|
|
|
|
wcscpy(szTempPath, szDrive);
|
|
|
|
wcscat(szTempPath, MSSETUP_PATH);
|
|
|
|
wcscpy(szFullTempPath, szTempPath);
|
|
|
|
wcscat(szFullTempPath, szTempDirName);
|
|
|
|
wcscat(szFullTempPath, L"\\");
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
if (SHCreateDirectoryEx(0, szFullTempPath, NULL) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
MessageBoxW(0, L"Could not create Temp Directory.", L"Error", MB_OK | MB_ICONERROR);
|
|
|
|
return 1;
|
2014-05-31 16:58:03 +00:00
|
|
|
}
|
2012-03-11 10:51:40 +00:00
|
|
|
|
|
|
|
dwAttrib = GetFileAttributes(szTempPath);
|
|
|
|
SetFileAttributes(szTempPath, dwAttrib | FILE_ATTRIBUTE_HIDDEN);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* extract files */
|
|
|
|
if (!SetupIterateCabinetW(szCabFilePath, 0, ExtCabCallback, szFullTempPath))
|
|
|
|
{
|
|
|
|
MessageBoxW(0, L"Could not extract cab file", L"Error", MB_OK | MB_ICONERROR);
|
|
|
|
DeleteDirectory(szTempPath);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* prepare command line */
|
|
|
|
wsprintf(szTempCmdLine, szCmdLine, szFullTempPath, lpCmdLine);
|
|
|
|
wcscpy(szCmdLine, szFullTempPath);
|
|
|
|
wcscat(szCmdLine, szTempCmdLine);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* execute the 32-Bit installer */
|
|
|
|
ZeroMemory(&processInfo, sizeof(processInfo));
|
|
|
|
ZeroMemory(&startupInfo, sizeof(startupInfo));
|
|
|
|
startupInfo.cb = sizeof(startupInfo);
|
|
|
|
if (CreateProcessW(NULL, szCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, szFullTempPath, &startupInfo, &processInfo))
|
|
|
|
{
|
|
|
|
WaitForSingleObject(processInfo.hProcess, INFINITE);
|
|
|
|
CloseHandle(processInfo.hProcess);
|
|
|
|
CloseHandle(processInfo.hThread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR szMsg[MAX_PATH];
|
2013-03-15 21:59:57 +00:00
|
|
|
wsprintf(szMsg, L"Failed to load the installer. Error %lu", GetLastError());
|
2012-03-11 10:51:40 +00:00
|
|
|
MessageBoxW(0, szMsg, L"Error", MB_OK | MB_ICONERROR);
|
|
|
|
DeleteDirectory(szTempPath);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
/* cleanup */
|
|
|
|
DeleteDirectory(szTempPath);
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2012-03-11 10:51:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-11 13:29:59 +00:00
|
|
|
/* EOF */
|