//with full updates we should have admin rights void FullUpdate() { DeleteFileW(L"desura_old.exe"); DeleteFileW(L"desura_service_old.exe"); std::wstring updateFile = UTIL::OS::getAppDataPath(UPDATEFILE_W); DeleteFileW(updateFile.c_str()); int nRes = DisplayUpdateWindow(UPDATE_FILES); //Critical failure if (nRes == -1) exit(0); if (nRes == 2) exit(0); #ifndef DEBUG try { SetRegValues(); InstallService(); ServiceUpdate(false); } catch (gcException &e) { char msg[255]; Safe::snprintf(msg, 255, "Failed to Update Desura: %s [%d.%d]", e.getErrMsg(), e.getErrId(), e.getSecErrId()); ::MessageBox(NULL, msg, "Desura Critical Error", MB_OK); exit(-4); } #endif }
bool BootLoader::preLaunchCheck(UTIL::MISC::CMDArgs &args) { #ifdef DESURA_OFFICIAL_BUILD CheckForBadUninstaller(); #endif if (args.hasArg("urllink")) { std::string a(m_lpCmdLine); size_t pos = a.find("-urllink"); a.replace(pos, 8, ""); BootLoaderUtil::Restart(a.c_str(), false); return false; } #ifdef DESURA_OFFICIAL_BUILD if (args.hasArg("testinstall")) { m_bRetCode = true; m_iRetCode = InstallFilesForTest(); return false; } if (args.hasArg("testdownload")) { m_bRetCode = true; m_iRetCode = DownloadFilesForTest(); return false; } #endif if (args.hasArg("dumplevel")) { SetDumpLevel(args.getInt("dumplevel")); g_bLockDump = true; } if (args.hasArg("autostart")) { //need to wait for service to start Sleep(15 * 1000); BootLoaderUtil::RestartAsNormal("-wait"); return false; } #ifdef DESURA_OFFICIAL_BUILD #ifdef DEBUG if (args.hasArg("debugupdater")) { INT_PTR nResponse = DisplayUpdateWindow(-1); return false; } if (args.hasArg("debuginstall")) { McfUpdate(); return false; } if (args.hasArg("debugdownload")) { FullUpdate(); return false; } if (args.hasArg("debugcheck")) { CheckInstall(); return false; } #endif #endif if (args.hasArg("testcrash")) { BootLoader *ai = nullptr; //ai->gcAssertValid(); } unsigned int osid = BootLoaderUtil::GetOSId(); if (osid == WINDOWS_PRE2000) { ::MessageBox(nullptr, PRODUCT_NAME " needs Windows XP or better to run.", PRODUCT_NAME " Error: Old Windows", MB_OK); return false; } else if (osid == WINDOWS_XP || osid == WINDOWS_XP64) { m_bHasAdminRights = true; } if (args.hasArg("admin")) { m_bHasAdminRights = true; } //if the wait command is parsed in then we need to wait for all other instances of desura to exit. if (args.hasArg("wait")) { BootLoaderUtil::WaitForOtherInstance(m_hInstance); } else { if (BootLoaderUtil::CheckForOtherInstances(m_hInstance)) { sendArgs(); return false; } else { //if windows uninstall software launches desura it will disable its window till it quits. //Work around for existing clients std::string a(m_lpCmdLine); size_t pos = a.find("desura://uninstall/"); if (pos != std::string::npos) { a.replace(pos + 9, 9, "remove"); BootLoaderUtil::RestartAsNormal(a.c_str()); return false; } } } #ifdef DESURA_OFFICIAL_BUILD if (args.hasArg("forceupdate")) { if (!m_bHasAdminRights) { restartAsAdmin(UPDATE_FORCED); return false; } else { FullUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return false; } } #endif #ifdef _DEBUG SetRegValues(); InstallService(); #else int nu = NeedUpdate(); if (nu != UPDATE_NONE) { if (nu == UPDATE_MCF) { Log("Updating from MCF.\n"); McfUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return false; } else if (nu == UPDATE_SERVICE_PATH) { Log("Service update path [%s].\n", g_UpdateReasons[nu]); if (ServiceUpdate(true)) nu = UPDATE_NONE; } } if (nu != UPDATE_NONE) { if (!m_bHasAdminRights) { restartAsAdmin(nu); return false; } else if (nu == UPDATE_SERVICE_LOCATION || nu == UPDATE_SERVICE_HASH) { Log("Service update location [%s].\n", g_UpdateReasons[nu]); ServiceUpdate(false); } else if (nu == UPDATE_SERVICE_DISABLED) { if (FixServiceDisabled()) BootLoaderUtil::RestartAsNormal("-wait"); return false; } else { Log("Full update [%s].\n", g_UpdateReasons[nu]); FullUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return false; } } if (m_bHasAdminRights && !(osid == WINDOWS_XP || osid == WINDOWS_XP64)) { BootLoaderUtil::RestartAsNormal("-wait"); return false; } #endif return true; }
BOOL BootLoader::InitInstance() { BootLoaderUtil::CMDArgs args(m_lpCmdLine); if (args.hasArg("waitfordebugger")) BootLoaderUtil::WaitForDebugger(); BootLoaderUtil::SetCurrentDir(); CWinApp::InitInstance(); #ifdef DESURA_NONGPL_BUILD CheckForBadUninstaller(); #endif if (args.hasArg("urllink")) { std::string a(m_lpCmdLine); size_t pos = a.find("-urllink"); a.replace(pos, 8, ""); BootLoaderUtil::Restart(a.c_str(), false); return FALSE; } #ifdef DESURA_NONGPL_BUILD if (args.hasArg("testinstall")) { m_bRetCode = true; m_iRetCode = InstallFilesForTest(); return FALSE; } if (args.hasArg("testdownload")) { m_bRetCode = true; m_iRetCode = DownloadFilesForTest(); return FALSE; } #endif if (args.hasArg("dumplevel")) { SetDumpLevel(args.getInt("dumplevel")); g_bLockDump = true; } if (args.hasArg("autostart")) { //need to wait for service to start Sleep(15*1000); BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } #ifdef DESURA_NONGPL_BUILD #ifdef DEBUG if (args.hasArg("debugupdater")) { INT_PTR nResponse = DisplayUpdateWindow(-1); return FALSE; } if (args.hasArg("debuginstall")) { McfUpdate(); return FALSE; } if (args.hasArg("debugdownload")) { FullUpdate(); return FALSE; } if (args.hasArg("debugcheck")) { CheckInstall(); return FALSE; } #endif #endif if (args.hasArg("testcrash")) { BootLoader *ai = NULL; ai->AssertValid(); } unsigned int osid = BootLoaderUtil::GetOSId(); if (osid == WINDOWS_PRE2000) { ::MessageBox(NULL, "Desura needs Windows xp or better to run.", "Desura Error: Old Windows", MB_OK); return FALSE; } else if (osid == WINDOWS_XP || osid == WINDOWS_XP64) { hasAdminRights = true; } if (args.hasArg("admin")) { hasAdminRights = true; } //if the wait command is parsed in then we need to wait for all other instances of desura to exit. if (args.hasArg("wait")) { BootLoaderUtil::WaitForOtherInstance(m_hInstance); } else { if (BootLoaderUtil::CheckForOtherInstances(m_hInstance)) { sendArgs(); return FALSE; } else { //if windows uninstall software launches desura it will disable its window till it quits. //Work around for existing clients std::string a(m_lpCmdLine); size_t pos = a.find("desura://uninstall/"); if (pos != std::string::npos) { a.replace(pos+9, 9, "remove"); BootLoaderUtil::RestartAsNormal(a.c_str()); return FALSE; } } } #ifdef DESURA_NONGPL_BUILD if (args.hasArg("forceupdate")) { if (!hasAdminRights) { restartAsAdmin(UPDATE_FORCED); return FALSE; } else { FullUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } } #endif #ifdef _DEBUG SetRegValues(); InstallService(); #else int nu = NeedUpdate(); if (nu != UPDATE_NONE) { if (nu == UPDATE_MCF) { Log("Updating from MCF.\n"); McfUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } else if (nu == UPDATE_SERVICE_PATH) { Log("Service update path [%s].\n", g_UpdateReasons[nu]); if (ServiceUpdate(true)) nu = UPDATE_NONE; } } if (nu != UPDATE_NONE) { if (!hasAdminRights) { restartAsAdmin(nu); return FALSE; } else if (nu == UPDATE_SERVICE_LOCATION || nu == UPDATE_SERVICE_HASH) { Log("Service update location [%s].\n", g_UpdateReasons[nu]); ServiceUpdate(false); } else if (nu == UPDATE_SERVICE_DISABLED) { if (FixServiceDisabled()) BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } else { Log("Full update [%s].\n", g_UpdateReasons[nu]); FullUpdate(); BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } } if (hasAdminRights && !(osid == WINDOWS_XP || osid == WINDOWS_XP64)) { BootLoaderUtil::RestartAsNormal("-wait"); return FALSE; } #endif loadUICore(); if (!m_pUICore) return FALSE; bool res = m_pUICore->initWxWidgets(m_hInstance, m_nCmdShow, args.getArgc(), const_cast<char**>(args.getArgv())); if (res) m_pMainWnd = new BootLoaderUtil::CDummyWindow(m_pUICore->getHWND()); return res?TRUE:FALSE; }