//checks local files. returns true if they are good false if they are bad bool UMcf::checkFiles(IBadFileCallback *pCallback) { uint32 prog = 0; onProgressEvent(prog); size_t size = m_pFileList.size(); if (size == 0) return false; auto bValidInstall = true; for(size_t x=0; x<size; x++) { prog = (uint32)((x*100)/size); onProgressEvent(prog); if (!m_pFileList[x]) continue; if (!m_pFileList[x]->checkFile(L".")) { if (!pCallback || pCallback->foundBadFile(m_pFileList[x]->getName(), m_pFileList[x]->getPath())) return false; bValidInstall = false; } } return bValidInstall; }
bool MCF::verifyInstall(const char* path, bool flagMissing, bool useDiffs) { if (!path) throw gcException(ERR_BADPATH); bool complete = true; size_t size = m_pFileList.size(); for (size_t x=0; x<size; x++) { if (m_bStopped) { complete = false; break; } MCFCore::Misc::ProgressInfo temp; temp.percent = (uint8)(x*100/size); onProgressEvent(temp); if (!m_pFileList[x]) continue; try { bool isComplete = m_pFileList[x]->isComplete(); m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE); m_pFileList[x]->setDir(path); m_pFileList[x]->verifyFile(useDiffs); m_pFileList[x]->setDir(NULL); if ( !m_pFileList[x]->isComplete() ) { complete = false; if (flagMissing) m_pFileList[x]->addFlag(MCFCore::MCFFileI::FLAG_SAVE); } else { if (flagMissing) m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_SAVE); } m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE); if (isComplete) m_pFileList[x]->addFlag(MCFCore::MCFFileI::FLAG_COMPLETE); } catch (gcException &) { m_pFileList[x]->setDir(NULL); throw; } } return complete; }
//cant stop remove files :P void MCF::removeFiles(const char* szPath, bool removeNonSave) { if (!szPath) throw gcException(ERR_BADPATH); size_t size = m_pFileList.size(); for (size_t x=0; x<size; x++) { MCFCore::Misc::ProgressInfo temp; temp.percent = (uint8)(x*100/size); onProgressEvent(temp); if (!m_pFileList[x]) continue; if (!removeNonSave && !m_pFileList[x]->isSaved()) continue; m_pFileList[x]->setDir(szPath); m_pFileList[x]->delFile(); m_pFileList[x]->setDir(NULL); } UTIL::FS::Path path(szPath, "", false); UTIL::FS::delEmptyFolders(path); if (UTIL::FS::isFolderEmpty(path)) UTIL::FS::delFolder(path); }
void UMcf::onFileProgress(ProgressCB& prog) { prog.cancel = m_bCanceled; uint32 per = (uint32)( (uint64)(m_uiCurProgress + prog.done)*100/m_uiTotProgress ); onProgressEvent(per); }
void UninstallAllThread::removeDesuraCache() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_CACHE")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); UTIL::FS::Path path(getCachePath(), "", false); std::vector<std::string> extList; extList.push_back("mcf"); for (size_t x=0; x<20; x++) extList.push_back(gcString("part_{0}", x)); UTIL::FS::Path dbDir(UTIL::OS::getAppDataPath(), L"", false); delLeftOverMcf(path, extList); delLeftOverMcf(dbDir, extList); UTIL::FS::Path mcfUploads = dbDir; UTIL::FS::Path mcfStore = dbDir; mcfUploads += UTIL::FS::File("mcf_uploads.sqlite"); mcfStore += UTIL::FS::File("mcfstoreb.sqlite"); UTIL::FS::delFile(mcfUploads); UTIL::FS::delFile(mcfStore); }
void UninstallAllThread::removeGameExplorerInfo() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_GAMEEXPLORER")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); std::vector<std::string> regKeys; UTIL::WIN::getAllRegKeys("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\Games", regKeys, true); for (size_t x=0; x<regKeys.size(); x++) { gcString regKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\Games\\{0}\\AppExePath", regKeys[x]); std::string value = UTIL::WIN::getRegValue(regKey, true); if (value.find("desura://") != 0) continue; regKey = gcString("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\Games\\{0}", regKeys[x]); UTIL::WIN::delRegTree(regKey.c_str(), true); } UTIL::FS::Path gdfFolder(UTIL::OS::getAppDataPath(), L"", false); gdfFolder += "GDF"; UTIL::FS::delFolder(gdfFolder); }
void UninstallProcess::onProgress(MCFCore::Misc::ProgressInfo& p) { uint64 val = p.toInt64(); if (val == m_uiLastProg) return; onProgressEvent(val); m_uiLastProg = val; }
void HGTController::onProgress() { MCFCore::Misc::ProgressInfo prog; prog.doneAmmount = m_uiDownloaded; prog.totalAmmount = m_uiTotal; prog.percent = (uint8)(m_uiDownloaded*100/m_uiTotal); onProgressEvent(prog); }
void DownloadToolTask::onProgress(Prog_s& prog) { UserCore::Misc::ToolProgress p; p.done = (uint32)prog.dlnow; p.total = (uint32)prog.dltotal; p.percent = (uint32)(prog.dlnow * 100.0 / prog.dltotal); onProgressEvent(p); m_uiPercent = p.percent; }
void ChangeDirThread::updateDb(FileList &list) { if (isStopped()) return; uint32 prog = 0; onProgressEvent(prog); uint32 stage = 1; onStageEvent(stage); gcString path = UTIL::OS::getAppDataPath(); UTIL::FS::Path dbDir(path, "", false); fixMcfUploads(dbDir, list); fixMcfStore(dbDir, list); }
bool MCF::verifyMCF() { if (m_sHeader) m_sHeader->addFlags(MCFCore::MCFHeaderI::FLAG_NONVERIFYED); bool complete = true; UTIL::FS::FileHandle hFile; getReadHandle(hFile); size_t size = m_pFileList.size(); for (size_t x=0; x<size; x++) { if (m_bStopped) { complete = false; break; } MCFCore::Misc::ProgressInfo temp; temp.percent = (uint8)(x*100/size); onProgressEvent(temp); if (!m_pFileList[x] || !m_pFileList[x]->isSaved()) continue; try { m_pFileList[x]->verifyMcf(hFile, m_bStopped); } catch (gcException &) { } if (m_pFileList[x]->isComplete() == false) complete = false; } if (complete) { if (m_sHeader) m_sHeader->delFlags(MCFCore::MCFHeaderI::FLAG_NONVERIFYED); } return complete; }
void ChangeDirThread::copyFiles(FileList &list) { uint32 stage = 2; onStageEvent(stage); for (size_t x=0; x<list.size(); x++) { uint32 prog = x*100/list.size(); onProgressEvent(prog); UTIL::FS::recMakeFolder(list[x].second); UTIL::FS::moveFile(list[x].first, list[x].second); if (isStopped()) break; } delLeftOverMcf(); UTIL::FS::delEmptyFolders(m_szCurDir); }
void MCF::parseFolder(const char *path, bool hashFile, bool reportProgress) { parseFolder(NULL, path); if (hashFile) { MCFCore::Misc::ProgressInfo p; p.totalAmmount = m_pFileList.size(); for (size_t x=0; x<m_pFileList.size(); x++) { m_pFileList[x]->hashFile(); if (reportProgress) { p.doneAmmount = x+1; p.percent = (uint8)(p.doneAmmount*100/p.totalAmmount); onProgressEvent(p); } } } }
void MCF::preAllocateFile() { uint64 offset = getDLSize() + m_sHeader->getSize(); UTIL::FS::recMakeFolder(UTIL::FS::PathWithFile(m_szFile)); UTIL::FS::FileHandle hFile(m_szFile.c_str(), UTIL::FS::FILE_APPEND); uint64 pos = UTIL::FS::getFileSize(m_szFile.c_str()); MCFCore::Misc::ProgressInfo prog; prog.totalAmmount = offset; //we do this as if its a massive file. Seeking will zero the end and take ages while (pos < offset) { if (m_bStopped) break; pos += 10*1024*1024; if (pos > offset) pos = offset; hFile.seek(pos); prog.percent = (uint8)(pos * 100 / offset); prog.doneAmmount = pos; onProgressEvent(prog); } if (!m_bStopped) return; // Got canceled hFile.close(); UTIL::FS::delFile(m_szFile.c_str()); }
void UninstallAllThread::removeUninstallInfo() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_UNINSTALL")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); std::vector<std::string> regKeys; UTIL::WIN::getAllRegKeys("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", regKeys); for (size_t x=0; x<regKeys.size(); x++) { std::string key = regKeys[x]; if (key.find("Desura") != 0) continue; gcString regKey("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0}", key); UTIL::WIN::delRegTree(regKey.c_str()); } }
void UninstallAllThread::removeDesuraSettings() { gcString logStr("{0}\n", Managers::GetString("#DUN_THREAD_SETTINGS")); onLogEvent(logStr); m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); UTIL::FS::Path dbDir(UTIL::OS::getAppDataPath(), L"", false); std::vector<UTIL::FS::Path> fileList; std::vector<UTIL::FS::Path> folderList; UTIL::FS::getAllFiles(dbDir, fileList, nullptr); UTIL::FS::getAllFolders(dbDir, folderList); for (size_t x=0; x<fileList.size(); x++) { std::string fileName = fileList[x].getFile().getFile(); if (fileName == "mcfstoreb.sqlite" || fileName == "mcf_uploads.sqlite") continue; UTIL::FS::delFile(fileList[x]); } for (size_t x=0; x<folderList.size(); x++) { std::string folderName = folderList[x].getLastFolder(); if (folderName == "mods" || folderName == "games" || folderName == "GDF") continue; UTIL::FS::delFolder(folderList[x]); } }
void UMcfEx::downloadMcf() { uint32 prog = 0; onProgressEvent(prog); if (m_szUrl == "") { ::MessageBox(NULL, "Invalid Download URL.", "Desura: Error", MB_OK); exit(-1); } if (m_szFile == L"") { ::MessageBox(NULL, "Invalid MCF file path.", "Desura: Error", MB_OK); exit(-1); } HttpHandle wc(m_szUrl.c_str()); wc->setOutFile(gcString(m_szFile).c_str()); wc->getProgressEvent() += delegate((UMcf*)this, &UMcf::updateAllCB); try { wc->getWebToFile(); } catch (gcException &e) { char msg[255]; _snprintf_s(msg, 255, _TRUNCATE, "Failed to download Desura Files. \n\n%s [%d.%d]", e.getErrMsg(), e.getErrId(), e.getSecErrId()); ::MessageBox(NULL, msg, "Desura: Error", MB_OK); exit(-1); } m_sHeader->setBuild(MCFBuild::BuildFromInt(m_iAppBuild)); m_sHeader->setId(m_iAppId); }
void UninstallAllThread::onMcfProgress(MCFCore::Misc::ProgressInfo& info) { uint32 prog = info.percent; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, prog); onProgressEvent(pair); }
void UninstallAllThread::run() { if (!m_pUser) return; bool removeSimple = HasAnyFlags(m_iFlags, REMOVE_SIMPLE); bool removeCache = HasAnyFlags(m_iFlags, REMOVE_CACHE); bool removeSettings = HasAnyFlags(m_iFlags, REMOVE_SETTINGS); std::vector<UserCore::Item::ItemHandleI*> uninstallList; std::vector<UserCore::Item::ItemInfoI*> gamesList; m_pUser->getItemManager()->getGameList(gamesList); for (size_t x=0; x<gamesList.size(); x++) { UserCore::Item::ItemInfoI* game = gamesList[x]; std::vector<UserCore::Item::ItemInfoI*> modList; for (size_t y=0; y<modList.size(); y++) { if (modList[x]->isInstalled() && (modList[x]->isComplex() || removeSimple)) uninstallList.push_back(m_pUser->getItemManager()->findItemHandle(modList[x]->getId())); } if (removeSimple && game->isInstalled()) uninstallList.push_back(m_pUser->getItemManager()->findItemHandle(game->getId())); } { gcString str("{0}\n", Managers::GetString("#DUN_THREAD_UNINSTALL")); onLogEvent(str); } m_iTotal = uninstallList.size() + (removeCache?1:0) + (removeSettings?1:0) + 2; for (size_t x=0; x<uninstallList.size(); x++) { m_iTotalPos++; std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, 0); onProgressEvent(pair); if (isStopped()) break; UserCore::Item::ItemHandleI* itemHandle = uninstallList[x]; if (!itemHandle) continue; gcString logStr("\t{0}\n", gcString(Managers::GetString("#DUN_THREAD_UNINSTALL_SUB"), itemHandle->getItemInfo()->getName())); onLogEvent(logStr); itemHandle->addHelper(this); itemHandle->uninstall(this, true, false); m_WaitCondition.wait(); itemHandle->delHelper(this); } m_pUser->logOut(); removeUninstallInfo(); removeGameExplorerInfo(); if (removeCache) removeDesuraCache(); if (removeSettings) removeDesuraSettings(); gcString finalLogStr("{0}\n", Managers::GetString("#DUN_THREAD_FINAL")); onLogEvent(finalLogStr); UTIL::WIN::delRegValue(APPID); UTIL::WIN::delRegValue(APPBUILD); UTIL::WIN::delRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Desura\\DesuraApp\\InstallPath"); UTIL::FS::Path path(UTIL::OS::getCommonProgramFilesPath(), L"", false); UTIL::FS::delFolder(path); UTIL::FS::delEmptyFolders(m_pUser->getAppDataPath()); UTIL::WIN::delRegKey("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura"); onCompleteEvent(); }
void IPCInstallMcf::onProgress(uint64& prog) { MCFCore::Misc::ProgressInfo pi(prog); onProgressEvent(pi); }
void UninstallAllThread::onProgressUpdate(uint32 progress) { std::pair<uint32,uint32> pair(m_iTotalPos*100/m_iTotal, progress); onProgressEvent(pair); }
void IPCComplexLaunch::onProgress(uint64& prog) { MCFCore::Misc::ProgressInfo pi(prog); onProgressEvent(pi); }
void IPCUninstallBranch::onProgress(uint64& prog) { MCFCore::Misc::ProgressInfo pi(prog); onProgressEvent(pi); }