void CustomSigAbort(int nSig) { gcTraceS("Sig: {0}", nSig); gcAssert(false); throw std::exception("sig abort"); }
HtmlTabPage::~HtmlTabPage() { if (m_pControlBar) { gcAssert(m_pControlBar.unique()); m_pControlBar.reset(); } if (m_pWebControl) { m_pWebControl->onNewURLEvent -= delegate(this, &HtmlTabPage::onNewUrl); m_pWebControl->onClearCrumbsEvent -= guiDelegate(this, &HtmlTabPage::clearCrumbs); m_pWebControl->onAddCrumbEvent -= guiDelegate(this, &HtmlTabPage::addCrumb); m_pWebControl->onFindEvent -= guiDelegate(this, &HtmlTabPage::onFind); } auto userCore = GetUserCore(); if (userCore) { auto cip = userCore->getCIPManager(); if (cip) cip->getItemsUpdatedEvent() -= guiDelegate(this, &HtmlTabPage::onCIPUpdate); } }
void UMcf::moveOldFiles(const wchar_t* installPath, const wchar_t* fileName) { gcAssert(g_vProblemFilesPath.size() == g_vProblemFiles.size()); size_t x = 0; for (auto p : g_vProblemFiles) { x++; if (Safe::wcsicmp(fileName, p) != 0) continue; auto probFilePath = g_vProblemFilesPath[x - 1]; wchar_t src[255] = {0}; wchar_t dest[255] = {0}; Safe::snwprintf(src, 255, L"%s\\%s", installPath, probFilePath); Safe::snwprintf(dest, 255, L"%s\\%s_old", installPath, probFilePath); //cant copy over a running exe. MoveFileExW(src, dest, MOVEFILE_WRITE_THROUGH); return; } }
void wxGuiDelegateEvent::invoke() { if (m_pDelegate) m_pDelegate->invoke(); else gcAssert(false); }
void setTimeOut() { m_iOwner = -1; m_uiErrCount++; m_tExpTime = gcTime() + std::chrono::seconds(getTimeOut()); gcAssert(isInTimeOut()); }
void gcFrame::setMessageBox(wxWindow *pDialog) { gcAssert((!pDialog && m_pMessageBox) || (pDialog && !m_pMessageBox)); m_pMessageBox = pDialog; if (!pDialog && m_bPendingClose) Close(); }
void installService(const char* szName, const char* szPath, const char* szDispName) { gcAssert(szName); gcAssert(szPath); gcWString wName(szName); gcWString wPath(szPath); gcWString wDispName(szDispName?szDispName:szName); SC_HANDLE newService; SC_HANDLE scm; //open connection to SCM scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE); if (!scm) throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager"); //install service newService = CreateService( scm, //scm database wName.c_str(), //service name wDispName.c_str(), //display name GENERIC_READ|GENERIC_EXECUTE, //access rights to the service SERVICE_WIN32_OWN_PROCESS, //service type SERVICE_DEMAND_START, //service start type SERVICE_ERROR_NORMAL, //error control type wPath.c_str(), //service path nullptr, //no load ordering group nullptr, //no tag identifier nullptr, //no dependencies nullptr, //LocalSystem account nullptr); //no password if(!newService) { CloseServiceHandle(scm); throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to create new service: {0}", szName)); } //clean up CloseServiceHandle(newService); CloseServiceHandle(scm); }
void SMTWorker::doWork() { gcAssert(m_pCurFile); gcAssert(m_phFhSink); uint32 buffSize = BLOCKSIZE; bool endFile = false; if ((m_pCurFile->getSize() - m_uiTotRead) < buffSize) { buffSize = (uint32)(((uint64)m_pCurFile->getSize()) - m_uiTotRead); endFile = true; } if (buffSize == 0) { if (m_pCurFile->isCompressed()) { //need to make sure we finish the compression off doCompression(nullptr, 0, true); } else { finishTask(); m_pCT->endTask(m_uiId); } } else { UTIL::MISC::Buffer buff(buffSize); m_hFhSource.read(buff, buffSize); m_uiTotRead += buffSize; m_uiTotFileRead += buffSize; m_pMD5Norm->update(buff, buffSize); if (!m_pCurFile->isCompressed()) writeFile(buff, buffSize, endFile); else doCompression(buff, buffSize, endFile); } }
void SMTWorker::run() { gcAssert(m_pCT); while (!isStopped()) { MCFThreadStatus status = m_pCT->getStatus(m_uiId); while (status == MCFThreadStatus::SF_STATUS_PAUSE) { gcSleep(500); status = m_pCT->getStatus(m_uiId); } if (status == MCFThreadStatus::SF_STATUS_STOP) break; if (status == MCFThreadStatus::SF_STATUS_NULL) { if (!newTask()) continue; } //make sure we dont do compression if we are ment to be stopped if (!isStopped() && status == MCFThreadStatus::SF_STATUS_CONTINUE) { try { doWork(); } catch (gcException &e) { gcString name("Null File"); if (m_pCurFile) name = m_pCurFile->getName(); gcException e2((ERROR_ID)e.getErrId(), e.getSecErrId(), gcString("{0} [{1}]", e.getErrMsg(), name)); finishTask(); m_pCT->reportError(m_uiId, e2); return; } } } m_phFhSink->close(); }
BaseMCFThread::BaseMCFThread(uint16 num, MCFCore::MCF* caller, const char* name) : BaseThread( name ) , m_rvFileList(caller->getFileList()) { gcAssert(caller); m_szFile = caller->getFile(); m_bCompress = caller->isCompressed(); m_pHeader = caller->getHeader(); m_uiFileOffset = caller->getFileOffset(); m_pUPThread = new MCFCore::Thread::UpdateProgThread(num, 0); m_pUPThread->onProgUpdateEvent += delegate(&onProgressEvent); m_uiNumber = num; }
void stopService(const char* szName) { gcAssert(szName); gcWString wName(szName); SC_HANDLE scm, Service; SERVICE_STATUS ssStatus; //open connection to SCM scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); if (!scm) throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager"); //open service Service = OpenService(scm, wName.c_str(), SERVICE_STOP|SERVICE_QUERY_STATUS); if (!Service) { CloseServiceHandle(scm); throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName)); } // Check the status until the service is no longer start pending. if (!QueryServiceStatus( Service, &ssStatus) ) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName)); } if (ssStatus.dwCurrentState & (SERVICE_STOP_PENDING|SERVICE_STOPPED)) return; BOOL SUCCES = ControlService(Service, SERVICE_CONTROL_STOP, &ssStatus); CloseServiceHandle(Service); CloseServiceHandle(scm); if (!SUCCES) throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to stop service: {0}", szName)); }
void InternalLink::showPrompt(DesuraId id, LinkArgs args) { std::string prompt = args.getArgValue("prompt"); gcRefPtr<UserCore::Item::ItemInfoI> item = GetUserCore()->getItemManager()->findItemInfo( id ); if (prompt == "update") { args.push_back("reminder=true"); showUpdateForm(id, args); } else if (prompt == "launch") { LaunchItemDialog* form = new LaunchItemDialog(m_pParent); regForm(id, form); form->setInfo(item); form->Show(true); form->Raise(); } else if (prompt == "eula") { showEULA(id); } else if (prompt == "preload") { showPreorderPrompt(id, true); } else if (prompt == "needtorunfirst") { std::string parentId = args.getArgValue("parentid"); DesuraId pid(parentId.c_str(), "games"); showNeedToRun(id, pid); } else { gcAssert(false); } }
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(); }
bool PipeBase::performRead(PipeData* data, IPCManager* mng) { if (!data || !mng) return true; DWORD read; BOOL fSuccess = ReadFile(data->hPipe, data->buffer, BUFSIZE, &read, &data->oOverlap); if (fSuccess) { data->size = read; finishRead(data, mng); } else if (!fSuccess && (GetLastError() == ERROR_IO_PENDING)) { data->fPendingIO = TRUE; } else { gcAssert(false); } return false; }
bool PipeBase::performWrite(PipeData* data, IPCManager* mng) { if (!data || !mng) return true; if (!mng->getMessageToSend(data->buffer, BUFSIZE, data->size)) return true; #ifdef IPC_DEBUG if (fh) { fprintf(fh, "Sending Data %d\n", data->size); printBuffer(fh, data->buffer, data->size); fprintf(fh, "\n\n"); fflush(fh); } #endif BOOL fSuccess = WriteFile( data->hPipe, data->buffer, data->size, nullptr, &data->oOverlap); if (fSuccess) { data->size = 0; data->fPendingIO = FALSE; } else if (!fSuccess && (GetLastError() == ERROR_IO_PENDING)) { data->fPendingIO = TRUE; } else { gcAssert(false); } return false; }
void startService(const char* szName, std::vector<std::string> &args) { gcAssert(szName); gcWString wName(szName); SC_HANDLE scm, Service; SERVICE_STATUS ssStatus; DWORD dwWaitTime; //open connection to SCM scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); if (!scm) throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager"); //open service Service = OpenService(scm, wName.c_str(), SERVICE_START|SERVICE_QUERY_STATUS); if (!Service) { CloseServiceHandle(scm); throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName)); } // Check the status until the service is no longer start pending. if (!QueryServiceStatus( Service, &ssStatus) ) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName)); } while (ssStatus.dwCurrentState == SERVICE_STOP_PENDING) { gcSleep(1000); } if (ssStatus.dwCurrentState != SERVICE_STOPPED) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: Service {0} is not stopped [{1}]", szName, ssStatus.dwCurrentState)); } BOOL res = doStartService(Service, szName, args); if (res == 0) { if (GetLastError() == 1058) throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service {0} as the service is disabled. Please use msconfig and renable service.", szName)); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: {0}", szName)); } // Check the status until the service is no longer start pending. if (!QueryServiceStatus( Service, &ssStatus) ) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName)); } DWORD totalTime = 0; while (ssStatus.dwCurrentState != SERVICE_RUNNING) { if (ssStatus.dwCurrentState == SERVICE_STOPPED) { //start service BOOL res = doStartService(Service, szName, args); if (res == 0) throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: {0}", szName)); } dwWaitTime = 1000; totalTime += dwWaitTime; gcSleep( dwWaitTime ); // Check the status again. if (!QueryServiceStatus( Service, &ssStatus) ) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName)); } if (totalTime > 30000) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, gcString("Service {0} Startup timed out after 30 seconds.", szName)); } } // Check the status again. if (!QueryServiceStatus( Service, &ssStatus) ) { CloseServiceHandle(Service); CloseServiceHandle(scm); throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName)); } CloseServiceHandle(scm); CloseServiceHandle(Service); if (ssStatus.dwCurrentState != SERVICE_RUNNING) throw gcException(ERR_SERVICE, gcString("Failed to start service: {0} [{1}]", szName, ssStatus.dwCurrentState)); }
wxGuiDelegateEvent::wxGuiDelegateEvent(std::shared_ptr<Invoker> &invoker, int winId) : wxNotifyEvent(wxEVT_GUIDELEGATE, winId) , m_pDelegate(invoker) { gcAssert(m_pDelegate); }
void changeServiceAccess(const char* szName) { gcAssert(szName); SC_HANDLE scm = nullptr; SC_HANDLE Service = nullptr; BOOL bDaclPresent = FALSE; BOOL bDaclDefaulted = FALSE; DWORD dwSize = 0; EXPLICIT_ACCESS ea; PACL pacl = nullptr; PACL pNewAcl = nullptr; PSECURITY_DESCRIPTOR psd = nullptr; SECURITY_DESCRIPTOR sd; //open connection to SCM scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT); if (!scm) throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager"); gcWString wName(szName); try { //open service Service = OpenService(scm, wName.c_str(), READ_CONTROL|WRITE_DAC); if (!Service) throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName)); // Get the current security descriptor. if (!QueryServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, psd, 0, &dwSize)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { psd = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize); if (!psd) throw gcException(ERR_SERVICE, gcString("Failed heap allocation for service service: {0}", szName)); //get securtty info if (!QueryServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, psd, dwSize, &dwSize)) throw gcException(ERR_SERVICE, GetLastError(), gcString("QueryServiceObjectSecurity failed for service: {0}", szName)); } } if (!psd) throw gcException(ERR_SERVICE, gcString("Failed heap allocation for service service: {0}", szName)); // Get the DACL. if (!GetSecurityDescriptorDacl(psd, &bDaclPresent, &pacl, &bDaclDefaulted)) throw gcException(ERR_SERVICE, GetLastError(), gcString("GetSecurityDescriptorDacl failed for service: {0}", szName)); DWORD SidSize; PSID TheSID; SidSize = SECURITY_MAX_SID_SIZE; // Allocate enough memory for the largest possible SID. if(!(TheSID = LocalAlloc(LMEM_FIXED, SidSize))) { LocalFree(TheSID); throw gcException(ERR_SERVICE, GetLastError(), gcString("LocalAlloc failed for service: {0}", szName)); } if(!CreateWellKnownSid(WinWorldSid, nullptr, TheSID, &SidSize)) { LocalFree(TheSID); throw gcException(ERR_SERVICE, GetLastError(), gcString("CreateWellKnownSid failed for service: {0}", szName)); } wchar_t everyone[255]; wchar_t domain[255]; DWORD eSize = 255; DWORD dSize = 255; SID_NAME_USE rSidNameUse; if (!LookupAccountSid(nullptr, TheSID, everyone, &eSize, domain, &dSize, &rSidNameUse)) { LocalFree(TheSID); throw gcException(ERR_SERVICE, GetLastError(), gcString("LookupAccountSid failed for service: {0}", szName)); } LocalFree(TheSID); // Build the ACE. BuildExplicitAccessWithName(&ea, everyone, SERVICE_START|SERVICE_STOP|READ_CONTROL|SERVICE_QUERY_STATUS|PROCESS_QUERY_INFORMATION, SET_ACCESS, NO_INHERITANCE); if (SetEntriesInAcl(1, &ea, pacl, &pNewAcl) != ERROR_SUCCESS) { throw gcException(ERR_SERVICE, GetLastError(), gcString("SetEntriesInAcl failed for service: {0}", szName)); } // Initialize a NEW Security Descriptor. if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) throw gcException(ERR_SERVICE, GetLastError(), gcString("InitializeSecurityDescriptor failed for service: {0}", szName)); // Set the new DACL in the Security Descriptor. if (!SetSecurityDescriptorDacl(&sd, TRUE, pNewAcl, FALSE)) throw gcException(ERR_SERVICE, GetLastError(), gcString("SetSecurityDescriptorDacl failed for service: {0}", szName)); // Set the new DACL for the service object. if (!SetServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, &sd)) throw gcException(ERR_SERVICE, GetLastError(), gcString("SetServiceObjectSecurity failed for service: {0}", szName)); } catch (gcException &e) { if (Service) CloseServiceHandle(Service); if (scm) CloseServiceHandle(scm); // Free buffers. LocalFree((HLOCAL)pNewAcl); HeapFree(GetProcessHeap(), 0, (LPVOID)psd); throw e; } CloseServiceHandle(scm); CloseServiceHandle(Service); // Free buffers. LocalFree((HLOCAL)pNewAcl); HeapFree(GetProcessHeap(), 0, (LPVOID)psd); }
static void gcAssertHandler(const wxString &file, int line, const wxString &func, const wxString &cond, const wxString &msg) { gcAssert(false); }