fix update via *.ocu on Windows 7 (#870)

see bugtracker entry for details
stable-5.4
Tobias Zwick 2014-02-02 23:45:24 +07:00
parent ba2d71c942
commit 325d2b80e1
1 changed files with 10 additions and 31 deletions

View File

@ -145,18 +145,6 @@ void C4UpdateDlg::UpdateText()
// --------------------------------------------------
// static update application function
static bool IsWindowsWithUAC()
{
#ifdef _WIN32
// Determine windows version
OSVERSIONINFO ver;
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx((LPOSVERSIONINFO) &ver))
return (ver.dwMajorVersion >= 6);
#endif
return false;
}
void C4UpdateDlg::RedirectToDownloadPage()
{
OpenURL("http://www.openclonk.org/download");
@ -198,11 +186,11 @@ bool C4UpdateDlg::ApplyUpdate(const char *strUpdateFile, bool fDeleteUpdate, C4G
strUpdateProg += ".exe";
#endif
// Determine name of local extract of update program
StdStrBuf strUpdateProgEx; strUpdateProgEx.Copy(Config.AtExePath(strUpdateProg.getData()));
// Windows Vista/7: rename update program to setup.exe for UAC elevation and in temp path
if (IsWindowsWithUAC()) strUpdateProgEx.Copy(Config.AtTempPath("setup.exe"));
StdStrBuf strUpdateProgEx;
strUpdateProgEx.Copy(Config.AtExePath(strUpdateProg.getData()));
// Extract update program (the update should be applied using the new version)
C4Group UpdateGroup, SubGroup;
C4Group UpdateGroup;
if (!UpdateGroup.Open(strUpdateFile))
{
LogF("Error opening \"%s\": %s", strUpdateFile, UpdateGroup.GetError());
@ -228,30 +216,21 @@ bool C4UpdateDlg::ApplyUpdate(const char *strUpdateFile, bool fDeleteUpdate, C4G
}
#endif
UpdateGroup.Close();
// Execute update program
Log(LoadResStr("IDS_PRC_LAUNCHINGUPDATE"));
succeeded = true;
#ifdef _WIN32
// Notice: even if the update program and update group are in the temp path, they must be executed in our working directory
DWORD ProcessID = GetCurrentProcessId();
StdStrBuf strUpdateArgs, strTitle;
StdStrBuf strUpdateArgs;
strUpdateArgs.Format("\"%s\" \"%s\" %s %lu", strUpdateProgEx.getData(), strUpdateFile, fDeleteUpdate ? "-yd" : "-y", (unsigned long)ProcessID);
STARTUPINFOW startupInfo;
startupInfo.cb = sizeof(startupInfo);
startupInfo.lpReserved = NULL;
startupInfo.lpDesktop = NULL;
startupInfo.lpTitle = L"Updating OpenClonk...";
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_SHOW;
startupInfo.cbReserved2 = 0;
startupInfo.lpReserved2 = NULL;
PROCESS_INFORMATION procInfo;
BOOL success = CreateProcessW(strUpdateProgEx.GetWideChar(), strUpdateArgs.GetWideChar(), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, Config.General.ExePath.GetWideChar(), &startupInfo, &procInfo);
if(!success) return false;
// the magic verb "runas" opens the update program in a shell requesting elevation
int iError = (intptr_t)ShellExecute(NULL, L"runas", strUpdateProgEx.GetWideChar(), strUpdateArgs.GetWideChar(), Config.General.ExePath.GetWideChar(), SW_SHOW);
if (iError <= 32) return false;
//int iError = (intptr_t)ShellExecute(NULL, "open", strUpdateProgEx.getData(), strUpdateArgs.getData(), Config.General.ExePath, SW_SHOW);
//if (iError <= 32) return false;
// must quit ourselves for update program to work
if (succeeded) Application.Quit();
#else