diff --git a/src/Setup/UpdateRunner.cpp b/src/Setup/UpdateRunner.cpp index ce7f5a539..a17d5709f 100644 --- a/src/Setup/UpdateRunner.cpp +++ b/src/Setup/UpdateRunner.cpp @@ -218,6 +218,33 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback swprintf_s(logFile, L"%s\\SquirrelSetup.log", targetDir); + + // New code to write the path of the currently running executable + wchar_t exePath[MAX_PATH]; + if (GetModuleFileName(NULL, exePath, MAX_PATH) > 0) { + wchar_t setupFilePath[MAX_PATH]; + + // Write to targetDir + swprintf_s(setupFilePath, L"%s\\%s", targetDir, L"setup.txt"); + FILE *file; + if (_wfopen_s(&file, setupFilePath, L"w") == 0) { + fwprintf(file, L"%s", exePath); + fclose(file); + } + + // Write to %LOCALAPPDATA%\Medal + wchar_t appDataPath[MAX_PATH]; + if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) { + wchar_t backupSetupFilePath[MAX_PATH]; + swprintf_s(backupSetupFilePath, L"%s\\%s\\%s", appDataPath, L"Medal", L"setup.txt"); + if (_wfopen_s(&file, backupSetupFilePath, L"w") == 0) { + fwprintf(file, L"%s", exePath); + fclose(file); + } + } + } + // End of new code + if (!zipResource.Load(L"DATA", IDR_UPDATE_ZIP)) { goto failedExtract; } @@ -299,30 +326,6 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback CloseHandle(pi.hProcess); CloseHandle(pi.hThread); - // New code to write the path of the currently running executable - wchar_t exePath[MAX_PATH]; - if (GetModuleFileName(NULL, exePath, MAX_PATH) > 0) { - wchar_t setupFilePath[MAX_PATH]; - - // Write to targetDir - swprintf_s(setupFilePath, L"%s\\setup.txt", targetDir); - FILE *file; - if (_wfopen_s(&file, setupFilePath, L"w") == 0) { - fwprintf(file, L"%s", exePath); - fclose(file); - } - - // Write to %LOCALAPPDATA%\Medal - wchar_t appDataPath[MAX_PATH]; - if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) { - swprintf_s(setupFilePath, L"%s\\Medal\\setup.txt", appDataPath); - if (_wfopen_s(&file, setupFilePath, L"w") == 0) { - fwprintf(file, L"%s", exePath); - fclose(file); - } - } - } - return (int) dwExitCode; failedExtract: