Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve file writing #2

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions src/Setup/UpdateRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
Loading