void MainApp::onClose(wxCloseEvent& event) { gcTrace(""); if (m_pOfflineDialog) m_pOfflineDialog->EndModal(0); if (m_wxLoginForm) { m_wxLoginForm->Show(false); m_wxLoginForm->Close(true); } if (m_wxMainForm) { m_wxMainForm->Show(false); m_wxMainForm->Close(true); } HideLogForm(); if (m_pInternalLink) m_pInternalLink->closeAll(); Destroy(); }
void MainApp::onLoginAccepted(bool saveLoginInfo, bool autologin) { gcTrace(""); std::pair<bool,bool> res(saveLoginInfo, autologin); onLoginAcceptedEvent(res); }
void AppUpdateInstall::onComplete() { gcTrace(""); SetEvent(m_pEvent); m_pPrivates->m_iResult = 0; }
void AppUpdateInstall::onIPCDisconnect() { gcTrace(""); m_pPrivates->m_iResult = 4; SetEvent(m_pEvent); }
void MainApp::onAppUpdate(UserCore::Misc::UpdateInfo& info) { gcTrace(""); setProgressState(P_NONE); m_pInternalLink->showAppUpdate(info.branch); }
void MainAppNoUI::onGiftUpdate(std::vector<gcRefPtr<UserCore::Misc::NewsItem>>& itemList) { std::vector<gcRefPtr<UserCore::Misc::NewsItem>> oldList; std::vector<gcRefPtr<UserCore::Misc::NewsItem>> output; { std::lock_guard<std::mutex> guard(m_NewsLock); oldList = m_vGiftItems; m_vGiftItems.clear(); for (auto i : itemList) { if (!i) continue; m_vGiftItems.push_back(i); } auto it = std::set_intersection(begin(m_vGiftItems), end(m_vGiftItems), begin(oldList), end(oldList), std::back_inserter(output), [](gcRefPtr<UserCore::Misc::NewsItem> a, gcRefPtr<UserCore::Misc::NewsItem> b){ return a->id < b->id; }); for (auto i : output) i->hasBeenShown = true; } if (m_vGiftItems.size() != output.size()) { gcTrace(""); onNotifyGiftUpdateEvent(); } }
void InternalLink::createMCF(DesuraId id) { gcTrace("Id: {0}", id); gcRefPtr<UserCore::Item::ItemInfoI> item = GetUserCore()->getItemManager()->findItemInfo( id ); if (!GetUserCore()->isAdmin() && !item) { //cant upload show prompt gcMessageBox(g_pMainApp->getMainWindow(), Managers::GetString(L"#MF_NONDEV_ERROR"), Managers::GetString(L"#MF_PERMISSION_ERRTITLE")); return; } //create new create from CreateMCFForm* form = new CreateMCFForm(m_pParent); form->setInfo(id); form->onUploadTriggerEvent += delegate(this, &InternalLink::onUploadTrigger); form->Show(true); form->Raise(); form->run(); #ifdef NIX form->Raise(); #endif m_vSubForms.push_back(form); }
void MainApp::newAccountLogin(const char* username, const char* cookie) { gcTrace("User: {0}", username); if (!m_bLoggedIn && m_iMode != APP_MODE::MODE_OFFLINE && m_wxLoginForm) m_wxLoginForm->newAccountLogin(username, cookie); }
void MainApp::Init(int argc, wxCmdLineArgsArray &argv) { gcTrace(""); if (argc > 0) { for (int x=0; x<argc; x++) { wxString str = argv[x].MakeLower(); if (str == "-dgl") m_bQuiteMode = true; if (str.StartsWith("desura://")) m_szDesuraCache = gcString(argv[x].ToStdString()); } } //char *comAppPath = nullptr; //UTIL::OS::getAppDataPath(&comAppPath); //UTIL::FS::recMakeFolder(comAppPath); //safe_delete(comAppPath); InitLogging(); cc_PrintVersion(); cc_CheckCert(); Msg("Logging Has started\n"); Msg("\n\n"); InitManagers(); InitLocalManagers(); std::string val = UTIL::OS::getConfigValue(REGRUN); gc_autostart.setValue( val.size() > 0 ); //because logging gets init first we need to man reg it RegLogWithWindow(); //because logging gets init before managers we need to reapply the color scheme. LoggingapplyTheme(); loadFrame(wxDEFAULT_FRAME_STYLE); #ifndef NIX if (!m_bQuiteMode) m_wxTBIcon = new TaskBarIcon(this); #endif m_wxTBIcon = nullptr; std::string szAppid = UTIL::OS::getConfigValue(APPID); uint32 appid = -1; if (szAppid.size() > 0) appid = Safe::atoi(szAppid.c_str()); if (appid == BUILDID_BETA || appid == BUILDID_INTERNAL) gc_uploaddumps.setValue(true); }
void MainApp::onPipeDisconnect() { if (!m_bLoggedIn) return; gcTrace(""); DesuraServiceError dse(getMainWindow()); dse.ShowModal(); }
void MainApp::onNewsUpdate(std::vector<gcRefPtr<UserCore::Misc::NewsItem>>& itemList) { gcTrace(""); std::lock_guard<std::mutex> guard(m_NewsLock); for (auto i : itemList) m_vNewsItems.push_back(i); }
void MCF::dlHeaderFromHttp(const char* url) { gcTrace("Url: {0}", url); if (m_bStopped) return; if (!url) throw gcException(ERR_BADURL); //FIXME: Needs error checking on getweb HttpHandle wc(url); wc->setDownloadRange(0, MCFCore::MCFHeader::getSizeS()); wc->setUserAgent(USERAGENT_UPDATE); wc->getWeb(); if (wc->getDataSize() != MCFCore::MCFHeader::getSizeS()) throw gcException(ERR_BADHEADER); MCFCore::MCFHeader webHeader(wc->getData()); setHeader(&webHeader); if (!webHeader.isValid()) throw gcException(ERR_BADHEADER); wc->cleanUp(); wc->setUserAgent(USERAGENT_UPDATE); wc->setDownloadRange(webHeader.getXmlStart(), webHeader.getXmlSize()); wc->getWeb(); if (wc->getDataSize() == 0 || wc->getDataSize() != webHeader.getXmlSize()) throw gcException(ERR_WEBDL_FAILED, "Failed to download MCF xml from web (size is ether zero or didnt match header size)"); uint32 bz2BuffLen = webHeader.getXmlSize()*25; char* bz2Buff = nullptr; if ( isCompressed() ) { bz2Buff = new char[bz2BuffLen]; AutoDelete<char> ad(bz2Buff); UTIL::STRING::zeroBuffer(bz2Buff, bz2BuffLen); UTIL::BZIP::BZ2DBuff((char*)bz2Buff, &bz2BuffLen, const_cast<char*>(wc->getData()), wc->getDataSize()); parseXml(bz2Buff, bz2BuffLen); } else { parseXml(const_cast<char*>(wc->getData()), wc->getDataSize()); } //we remove the complete flag due to the files not existing in the MCF for (size_t x=0; x< m_pFileList.size(); x++) { m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE); } }
void PipeBase::run() { gcTrace(""); while (!isStopped()) { processEvents(); processLoopback(); } }
void MainApp::goOffline() { gcTrace(""); int res = wxID_NO; { gcMessageDialog msgBox(nullptr, Managers::GetString(L"#MF_OFFLINE"), Managers::GetString(L"#MF_OFFLINE_TITLE"), wxYES_NO | wxICON_QUESTION); AutoScopeMemberVar<gcMessageDialog> asv(m_pOfflineDialog, &msgBox); res = msgBox.ShowModal(); } if (res == wxID_YES) offlineMode(); }
void MainApp::logOut(bool bShowLogin, bool autoLogin, bool webLoggedOut) { gcTrace(""); m_pInternalLink->closeAll(); safe_delete(m_pInternalLink); closeMainForm(); wxTheApp->ProcessIdle(); { std::lock_guard<std::mutex> a(m_UserLock); if (g_pUserHandle) { auto user = g_pUserHandle; g_pUserHandle = nullptr; DesuraJSBinding::gs_pItemManager = nullptr; user->getPipeDisconnectEvent() -= guiDelegate(this, &MainApp::onPipeDisconnect); user->logOut(!autoLogin); user->getAppUpdateProgEvent() -= guiDelegate(this, &MainApp::onAppUpdateProg); user->getAppUpdateCompleteEvent() -= guiDelegate(this, &MainApp::onAppUpdate); user->getWebCore()->getCookieUpdateEvent() -= guiDelegate(this, &MainApp::onCookieUpdate); user->getWebCore()->getLoggedOutEvent() -= delegate(&onLoggedOutEvent); user->destroy(); } } GetCVarManager()->saveAll(); GetCVarManager()->cleanUserCvars(); m_bLoggedIn = false; m_iMode = APP_MODE::MODE_UNINT; if (bShowLogin) showLogin(!autoLogin, webLoggedOut); HideLogForm(); DeleteCookies(); SetCrashDumpSettings(nullptr, true); }
void MainApp::logIn(const char* user, const char* pass) { gcTrace("User: {0}", user); std::lock_guard<std::mutex> a(m_UserLock); safe_delete(g_pUserHandle); gcString path = UTIL::OS::getAppDataPath(); g_pUserHandle = (UserCore::UserI*)UserCore::FactoryBuilderUC(USERCORE); g_pUserHandle->init(path.c_str(), m_strServiceProvider.c_str()); try { //need to do this here as news items will be passed onlogin g_pUserHandle->getNewsUpdateEvent() += delegate(this, &MainApp::onNewsUpdate); g_pUserHandle->getGiftUpdateEvent() += delegate((MainAppNoUI*)this, &MainAppNoUI::onGiftUpdate); g_pUserHandle->getNeedCvarEvent() += delegate(this, &MainApp::onNeedCvar); g_pUserHandle->lockDelete(); g_pUserHandle->logIn(user, pass); g_pUserHandle->unlockDelete(); #ifndef DEBUG if (gc_enable_api_debugging.getBool()) g_pUserHandle->getWebCore()->enableDebugging(); #endif } catch (gcException) { g_pUserHandle->logOut(); g_pUserHandle->getNewsUpdateEvent() -= delegate(this, &MainApp::onNewsUpdate); g_pUserHandle->getGiftUpdateEvent() -= delegate((MainAppNoUI*)this, &MainAppNoUI::onGiftUpdate); g_pUserHandle->getNeedCvarEvent() -= delegate(this, &MainApp::onNeedCvar); g_pUserHandle->unlockDelete(); g_pUserHandle->logOut(false, false); safe_delete(g_pUserHandle); throw; } }
void AppUpdateInstall::onError(gcException& e) { gcTrace("Error: {0}", e); if (m_pPrivates->m_bTestMode) { m_pPrivates->m_iResult = e.getErrId(); return; } if (e.getErrId() != ERR_INVALIDFILE && e.getErrId() != ERR_FAILEDSEEK) { char mbmsg[255]; Safe::snprintf(mbmsg, 255, PRODUCT_NAME " has had a critical error while updating.\n\n%s [%d.%d]", e.getErrMsg(), e.getErrId(), e.getSecErrId()); ::MessageBox(nullptr, mbmsg, PRODUCT_NAME " Critical Update Error", MB_OK); } else { m_pPrivates->m_iResult = 0; } }
void MCF::dlFilesFromHttp(const char* url, const char* installDir) { gcTrace("Url: {0}, Dir: {1}", url, installDir); gcAssert(!m_pTHandle); if (m_bStopped) return; if (!url) throw gcException(ERR_BADURL); //save the header first incase we fail saveMCF_Header(); MCFCore::Thread::HGTController *temp = new MCFCore::Thread::HGTController(url, this, installDir); temp->onProgressEvent +=delegate(&onProgressEvent); temp->onErrorEvent += delegate(&onErrorEvent); runThread(temp); saveMCF_Header(); }
void MCF::dlMCFFromHttp( const char* url, const char* installDir ) { gcTrace( "Url: {0}", url ); if ( m_bStopped ) return; if ( !url ) throw gcException( ERR_BADURL ); //FIXME: Needs error checking on getweb HttpHandle wc( url ); wc->setDownloadRange( 0, MCFCore::MCFHeader::getSizeS() ); wc->setUserAgent( USERAGENT_UPDATE ); wc->getWeb(); if ( wc->getDataSize() != MCFCore::MCFHeader::getSizeS() ) throw gcException( ERR_BADHEADER ); MCFCore::MCFHeader webHeader( wc->getData() ); setHeader( &webHeader ); if ( !webHeader.isValid() ) throw gcException( ERR_BADHEADER ); unsigned int totalSize = webHeader.getXmlStart() + webHeader.getXmlSize(); wc->cleanUp(); wc->setUserAgent( USERAGENT_UPDATE ); wc->setDownloadRange( 0, totalSize ); wc->getWeb(); if ( wc->getDataSize() == 0 || wc->getDataSize() != totalSize ) throw gcException( ERR_WEBDL_FAILED, "Failed to download MCF xml from web (size is ether zero or didnt match header size)" ); UTIL::FS::FileHandle fh( installDir, UTIL::FS::FILE_WRITE ); fh.write( wc->getData(), wc->getDataSize() ); }
void InternalLink::onUploadTrigger(ut& info) { gcTrace("Id: {0}", info.id); FINDFORM(info.id, UploadMCFForm); gcRefPtr<UserCore::Item::ItemInfoI> item = GetUserCore()->getItemManager()->findItemInfo( info.id ); if (!item && !GetUserCore()->isAdmin()) { //cant upload show prompt gcMessageBox(g_pMainApp->getMainWindow(), Managers::GetString(L"#MF_NONDEV_ERROR"), Managers::GetString(L"#MF_PERMISSION_ERRTITLE")); return; } if (item && !HasAllFlags(item->getStatus(), UserCore::Item::ItemInfoI::STATUS_DEVELOPER) && !GetUserCore()->isAdmin()) { //cant upload show prompt gcMessageBox(g_pMainApp->getMainWindow(), Managers::GetString(L"#MF_UPERMISSION_ERROR"), Managers::GetString(L"#MF_PERMISSION_ERRTITLE")); return; } //create new create from UploadMCFForm* form = new UploadMCFForm(m_pParent); form->setInfo_path(info.id, info.path.c_str()); if (info.caller) { wxPoint pos = info.caller->GetScreenPosition(); form->SetPosition(pos); } form->Show(true); form->Raise(); form->run(); m_vSubForms.push_back(form); }
void AppUpdateInstall::startService() { gcTrace(""); uint32 res = UTIL::WIN::queryService(SERVICE_NAME); if (res != SERVICE_STATUS_STOPPED) { try { UTIL::WIN::stopService(SERVICE_NAME); gcSleep(500); } catch (gcException &) { } } std::vector<std::string> args; args.push_back("-wdir"); args.push_back(gcString(UTIL::OS::getCurrentDir())); UTIL::WIN::startService(SERVICE_NAME, args); uint32 count = 0; while (UTIL::WIN::queryService(SERVICE_NAME) != SERVICE_STATUS_RUNNING) { //wait 10 seconds if (count > 40) throw gcException(ERR_SERVICE, "Failed to start desura Service (PipeManager)."); gcSleep(250); count++; } }
void AppUpdateInstall::stopService() { gcTrace(""); UTIL::WIN::stopService(SERVICE_NAME); }