1
0
Fork 0

LAUNCHER: Simplify installation process

Thx to Jonas for helping me with the zone data
This commit is contained in:
Duncan Ogilvie 2020-07-09 18:47:52 +02:00
parent 4312b99fd4
commit 6cf28d32e6
2 changed files with 57 additions and 6 deletions

Binary file not shown.

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <windows.h>
#include <string>
#include <queue>
#include <shlwapi.h>
#include <objbase.h>
#pragma warning(push)
@ -298,6 +299,16 @@ static TCHAR sz32Dir[MAX_PATH] = TEXT("");
static TCHAR sz64Path[MAX_PATH] = TEXT("");
static TCHAR sz64Dir[MAX_PATH] = TEXT("");
static void restartInstall()
{
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
auto operation = osvi.dwMajorVersion >= 6 ? TEXT("runas") : TEXT("open");
ShellExecute(nullptr, operation, szModulePath, TEXT("::install"), szCurrentDir, SW_SHOWNORMAL);
}
static BOOL CALLBACK DlgLauncher(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
@ -340,12 +351,7 @@ static BOOL CALLBACK DlgLauncher(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
case IDC_BUTTONINSTALL:
{
EndDialog(hwndDlg, 0);
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
auto operation = osvi.dwMajorVersion >= 6 ? TEXT("runas") : TEXT("open");
ShellExecute(nullptr, operation, szModulePath, TEXT("::install"), szCurrentDir, SW_SHOWNORMAL);
restartInstall();
}
return TRUE;
}
@ -382,6 +388,42 @@ const wchar_t* SHELLEXT_ICON_EXE_KEY = L"exefile\\shell\\Debug with x64dbg";
const wchar_t* SHELLEXT_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg\\Command";
const wchar_t* SHELLEXT_ICON_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg";
static void deleteZoneData(const std::wstring & rootDir)
{
wchar_t szTempPath[MAX_PATH] = L"";
std::queue<std::wstring> queue;
queue.push(rootDir);
while(!queue.empty())
{
auto dir = queue.front();
queue.pop();
WIN32_FIND_DATAW foundData;
HANDLE hSearch = FindFirstFileW((dir + L"\\*").c_str(), &foundData);
if(hSearch == INVALID_HANDLE_VALUE)
{
continue;
}
do
{
if((foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
{
if(wcscmp(foundData.cFileName, L".") != 0 && wcscmp(foundData.cFileName, L"..") != 0)
queue.push(dir + L"\\" + foundData.cFileName);
}
else
{
wcscpy_s(szTempPath, dir.c_str());
wcscat_s(szTempPath, L"\\");
wcscat_s(szTempPath, foundData.cFileName);
wcscat_s(szTempPath, L":Zone.Identifier");
DeleteFileW(szTempPath);
}
}
while(FindNextFileW(hSearch, &foundData));
FindClose(hSearch);
}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
InitCommonControls();
@ -487,6 +529,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
auto argc = 0;
auto argv = CommandLineToArgvW(GetCommandLineW(), &argc);
// If x64dbg is not found, perform installation
if(bDoneSomething)
{
restartInstall();
return 0;
}
if(argc <= 1) //no arguments -> launcher dialog
{
if(!FileExists(sz32Path) && BrowseFileOpen(nullptr, TEXT("x32dbg.exe\0x32dbg.exe\0\0"), nullptr, sz32Path, MAX_PATH, szCurrentDir))
@ -513,6 +562,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
WritePrivateProfileString(TEXT("Launcher"), TEXT("x64dbg"), sz64Path, szIniPath);
bDoneSomething = true;
}
deleteZoneData(szCurrentDir);
deleteZoneData(szCurrentDir + std::wstring(L"\\..\\pluginsdk"));
if(MessageBox(nullptr, LoadResString(IDS_ASKSHELLEXT), LoadResString(IDS_QUESTION), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
TCHAR szLauncherCommand[MAX_PATH] = TEXT("");