void WebCoreClass::newUpload(DesuraId id, const char* hash, uint64 fileSize, char **key) { gcString size("{0}", fileSize); XML::gcXMLDocument doc; PostMap post; post["siteareaid"] = id.getItem(); post["sitearea"] = id.getTypeString(); post["action"] = "newupload"; post["filehash"] = hash; post["filesize"] = size; auto uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc); auto iNode = uNode.FirstChildElement("mcf"); if (!iNode.IsValid()) throw gcException(ERR_BADXML); if (key) { const std::string text = iNode.GetAtt("key"); if (text.empty()) throw gcException(ERR_BADXML); Safe::strcpy(key, text.c_str(), text.size()); } }
void WebCoreClass::resumeUpload(DesuraId id, const char* key, WebCore::Misc::ResumeUploadInfo &info) { XML::gcXMLDocument doc; PostMap post; post["siteareaid"] = id.getItem(); post["sitearea"] = id.getTypeString(); post["action"] = "resumeupload"; post["key"] = key; auto uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc); auto iNode = uNode.FirstChildElement("mcf"); if (!iNode.IsValid()) throw gcException(ERR_BADXML); gcString complete; iNode.GetChild("complete", complete); if (complete == "1") throw gcException(ERR_COMPLETED); iNode.GetChild("date", info.szDate); iNode.GetChild("filehash", info.szHash); iNode.GetChild("filesize", info.size); iNode.GetChild("filesizeup", info.upsize); }
void ToolManager::cancelDownload(Misc::ToolTransInfo* info, bool force) { if (!info) return; m_DownloadLock.lock(); std::vector<DesuraId> idList; info->getIds(idList); for (size_t x=0; x<idList.size(); x++) { DesuraId id = idList[x]; ToolInfo* info = findItem(id.toInt64()); //This should not happen as there is a check before a download starts to make sure all tool ids are valid if (!info) continue; std::map<uint64, UserCore::Task::DownloadToolTask*>::iterator it = m_mDownloads.find(id.toInt64()); if (it != m_mDownloads.end()) it->second->decreaseRefCount(force); } m_DownloadLock.unlock(); }
gcString MCFManager::getMcfPath(DesuraId id, MCFBranch branch, MCFBuild build, bool isUnAuthed) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); std::string res; try { int flags = isUnAuthed?FLAG_UNAUTHED:FLAG_NONE; sqlite3x::sqlite3_connection db(szItemDb.c_str()); if (flags == FLAG_NONE) { sqlite3x::sqlite3_command cmd(db, "SELECT path FROM mcfitem WHERE internalid=? AND mcfbuild=? AND branch=?;"); cmd.bind(1, (long long int)id.toInt64()); cmd.bind(2, (int)build); cmd.bind(3, (int)branch); res = cmd.executestring(); } else { sqlite3x::sqlite3_command cmd(db, "SELECT path FROM mcfitem WHERE internalid=? AND mcfbuild=? AND branch=? AND flags & ?;"); cmd.bind(1, (long long int)id.toInt64()); cmd.bind(2, (int)build); cmd.bind(3, (int)branch); cmd.bind(4, (int)flags); res = UTIL::OS::getAbsPath(cmd.executestring()); } } catch (std::exception &) { } return res; }
gcString MCFManager::getMcfBackup(DesuraId gid, DesuraId mid) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); std::string res; try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "SELECT path FROM mcfbackup WHERE gid=? AND mid=?;"); cmd.bind(1, (long long int)gid.toInt64()); cmd.bind(2, (long long int)mid.toInt64()); res = UTIL::OS::getRelativePath(cmd.executestring()); if (!UTIL::FS::isValidFile(UTIL::FS::PathWithFile(res))) { properDelMcfBackup(gid, mid); res = ""; } } catch (std::exception &) { } return res; }
void WebCoreClass::resumeUpload(DesuraId id, const char* key, WebCore::Misc::ResumeUploadInfo &info) { TiXmlDocument doc; PostMap post; post["siteareaid"] = id.getItem(); post["sitearea"] = id.getTypeString(); post["action"] = "resumeupload"; post["key"] = key; TiXmlNode *uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc); TiXmlNode* mNode = uNode->FirstChild("mcf"); if (!mNode) throw gcException(ERR_BADXML); gcString complete; XML::GetChild("complete", complete, mNode); if (complete == "1") throw gcException(ERR_COMPLETED); XML::GetChild("date", info.szDate, mNode); XML::GetChild("filehash", info.szHash, mNode); XML::GetChild("filesize", info.size, mNode); XML::GetChild("filesizeup", info.upsize, mNode); }
void WebCoreClass::newUpload(DesuraId id, const char* hash, uint64 fileSize, char **key) { gcString size("{0}", fileSize); TiXmlDocument doc; PostMap post; post["siteareaid"] = id.getItem(); post["sitearea"] = id.getTypeString(); post["action"] = "newupload"; post["filehash"] = hash; post["filesize"] = size; TiXmlNode *uNode = postToServer(getMcfUploadUrl(), "itemupload", post, doc); TiXmlNode* iNode = uNode->FirstChild("mcf"); if (!iNode) throw gcException(ERR_BADXML); TiXmlElement* cEl = iNode->ToElement(); if (cEl) { const char* text = cEl->Attribute("key"); if (!text) throw gcException(ERR_BADXML); Safe::strcpy(key, text, 255); } }
void MCFManager::delAllMcfPath(DesuraId id) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); sqlite3x::sqlite3_connection db(szItemDb.c_str()); try { sqlite3x::sqlite3_command cmd(db, "SELECT path FROM mcfitem WHERE internalid=?;"); cmd.bind(1, (long long int)id.toInt64()); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { std::string path = reader.getstring(0); UTIL::FS::delFile(UTIL::FS::PathWithFile(path)); } } catch (std::exception &) { } try { sqlite3x::sqlite3_command cmd(db, "DELETE FROM mcfitem WHERE internalid=?;"); cmd.bind(1, (long long int)id.toInt64()); cmd.executenonquery(); } catch (std::exception &e) { Warning("Failed to delete mcf items: {0}\n", e.what()); } }
void MCF::setHeader(DesuraId id, MCFBranch branch, MCFBuild build) { assert(m_sHeader); m_sHeader->setBranch(branch); m_sHeader->setType(id.getType()); m_sHeader->setBuild(build); m_sHeader->setId(id.getItem()); }
bool UpdateThreadOld::pollUpdates() { if (!m_pWebCore || !m_pUser) return false; updateBuildVer(); std::map<std::string, std::string> post; #ifdef DESURA_NONGPL_BUILD post["appid"] = gcString("{0}", m_iAppId); post["build"] = gcString("{0}", m_iAppVersion); #endif for (uint32 x=0; x< m_pUser->getItemManager()->getCount(); x++) { UserCore::Item::ItemInfoI* item = m_pUser->getItemManager()->getItemInfo(x); if (!item) continue; if (!(item->getStatus() & UserCore::Item::ItemInfoI::STATUS_ONCOMPUTER) || (item->getStatus()&UserCore::Item::ItemInfoI::STATUS_ONACCOUNT)) continue; DesuraId id = item->getId(); if (id.getType() == DesuraId::TYPE_LINK) continue; gcString key("updates[{0}][{1}]", id.getTypeString().c_str(), id.getItem()); post[key] = "1"; } TiXmlDocument doc; try { m_pWebCore->getUpdatePoll(doc, post); } catch (gcException &e) { Warning(gcString("Update poll failed: {0}\n", e)); return false; } parseXML(doc); #ifdef WIN32 checkFreeSpace(); #endif m_hHttpHandle->cleanPostInfo(); m_hHttpHandle->cleanUp(); m_hHttpHandle->clearCookies(); return true; }
void MCF::setHeader(DesuraId id, MCFBranch branch, MCFBuild build) { if (!m_sHeader) m_sHeader = new MCFCore::MCFHeader(); m_sHeader->setBranch(branch); m_sHeader->setType(id.getType()); m_sHeader->setBuild(build); m_sHeader->setId(id.getItem()); }
void WebCoreClass::updateAccountItem(DesuraId id, bool add) { TiXmlDocument doc; PostMap post; post["siteareaid"] = id.getItem(); post["sitearea"] = id.getTypeString(); post["action"] = add?"add":"delete"; postToServer(getUpdateAccountUrl(), "iteminstall", post, doc); }
ToolStartRes ToolTransInfo::startNextInstall(std::shared_ptr<IPCToolMain> pToolMain, DesuraId &toolId) { gcTrace("ToolId {0}", toolId); if (m_uiCompleteCount == m_pTransaction->size()) return ToolStartRes::NoToolsLeft; toolId = m_pTransaction->get(m_uiCompleteCount); ToolInfo* info = m_pToolManager->findItem(toolId.toInt64()); if (!info) { Warning("Failed to find tool for tool install with id {0}", toolId.toInt64()); m_uiCompleteCount++; return startNextInstall(pToolMain, toolId); } if (info->isInstalled()) { onINComplete(); return startNextInstall(pToolMain, toolId); } DesuraId id = info->getId(); m_pTransaction->onStartInstallEvent(id); gcException e = pToolMain->installTool(info); #ifdef NIX if (e.getErrId() == ERR_COMPLETED) { onINComplete(); return startNextInstall(pToolMain, toolId); } #endif if (e.getErrId() != WARN_OK && e.getErrId() != ERR_UNKNOWNERROR) { onINError(e); return ToolStartRes::Failed; } else { UserCore::Misc::ToolProgress prog; prog.done = m_uiCompleteCount; prog.total = m_pTransaction->size(); prog.percent = prog.done*100/prog.total; m_pTransaction->onProgressEvent(prog); } return ToolStartRes::Success; }
void WebCoreClass::getDownloadProviders(DesuraId id, XML::gcXMLDocument &xmlDocument, MCFBranch mcfBranch, MCFBuild mcfBuild) { PostMap postData; postData["siteareaid"] = id.getItem(); postData["sitearea"] = id.getTypeString(); postData["branch"] = (size_t) mcfBranch; if (mcfBuild != 0) postData["build"] = (size_t) mcfBuild; postToServer(getMCFDownloadUrl(), "itemdownloadurl", postData, xmlDocument); }
void InternalLink::handleInternalLink(DesuraId id, uint8 action, const std::vector<std::string> &argsList) { if (g_pMainApp->isOffline() && action != ACTION_LAUNCH) return; Args args(argsList); bool handled = true; switch (action) { case ACTION_UPLOAD : uploadMCF( id ); break; case ACTION_CREATE : createMCF( id ); break; case ACTION_RESUPLOAD : resumeUploadMCF( id, args ); break; #ifdef WIN32 case ACTION_INSTALLEDW : installedWizard(); break; #endif case ACTION_SHOWSETTINGS: showSettings(args); break; case ACTION_APPUPDATELOG: showUpdateLogApp( id.getItem() ); break; case ACTION_PAUSE : setPauseItem( id , true ); break; case ACTION_UNPAUSE : setPauseItem( id , false ); break; case ACTION_UNINSTALL : uninstallMCF( id ); break; case ACTION_PROMPT : showPrompt(id, args); break; case ACTION_UPDATELOG : showUpdateLog(id); break; case ACTION_DISPCDKEY : showCDKey(id, args); break; default: handled = false; break; } if (handled || checkForm(id)) return; switch (action) { case ACTION_INSTALL : installItem(id, args); break; case ACTION_LAUNCH : launchItem(id, args); break; case ACTION_VERIFY : verifyItem(id, args); break; case ACTION_UPDATE : updateItem(id, args); break; case ACTION_TEST : installTestMCF(id, args); break; case ACTION_INSCHECK : installCheck(id); break; case ACTION_SHOWUPDATE : showUpdateForm(id, args); break; case ACTION_SWITCHBRANCH: switchBranch(id, args); break; case ACTION_CLEANCOMPLEXMOD: cleanComplexMod(id); break; default: Warning(gcString("Unknown internal link {0} for item {1}\n.", (uint32)action, id.toInt64())); break; } }
void MCFManager::getAllMcfPaths(DesuraId id, std::vector<McfPathData> &vList) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); std::string res; try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "SELECT path, mcfbuild, branch FROM mcfitem WHERE internalid=?"); cmd.bind(1, (long long int)id.toInt64()); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { McfPathData mpd; mpd.path = UTIL::OS::getAbsPath(reader.getstring(0)); mpd.build = MCFBuild::BuildFromInt(reader.getint(1)); mpd.branch = MCFBranch::BranchFromInt(reader.getint(2)); vList.push_back(mpd); } } catch (std::exception &) { } }
void MCFManager::getMCFFiles(std::vector<mcfInfo*> &validFiles, DesuraId id) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "SELECT path, mcfbuild FROM mcfitem WHERE internalid=?;"); cmd.bind(1, (long long int)id.toInt64()); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { std::string p = UTIL::OS::getAbsPath(reader.getstring(0)); uint32 v = reader.getint(1); validFiles.push_back(new mcfInfo(p.c_str(), v, MCFBranch())); } } catch (std::exception &) { } }
void InternalLink::installCheck(DesuraId id) { UI::Forms::ItemForm* form = showItemForm(id, UI::Forms::INSTALL_ACTION::IA_INSTALL_CHECK); if (!form) Warning(gcString("Cant find item (or item not ready) for install check [{0}].\n", id.toInt64())); }
void InternalLink::installItem(DesuraId id, Args args) { std::string branch = args.getArgValue("branch"); std::string global = args.getArgValue("global"); MCFBranch iBranch; if (branch == "shortcut" || global == "shortcut") { iBranch = MCFBranch::BranchFromInt(-1); } else if (global.size() > 0) { iBranch = MCFBranch::BranchFromInt(Safe::atoi(global.c_str()), true); } else { iBranch = MCFBranch::BranchFromInt(Safe::atoi(branch.c_str())); } g_pMainApp->showPlay(); if (iBranch == 0 && !args.containsArg("skippreorder") && checkForPreorder(id)) return; UI::Forms::ItemForm* form = showItemForm(id, UI::Forms::INSTALL_ACTION::IA_INSTALL, iBranch); if (!form) Warning(gcString("Cant find item (or item not ready) for install [{0}].\n", id.toInt64())); }
void MCFManager::properDelMcfBackup(DesuraId gid, DesuraId mid) { gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "DELETE FROM mcfbackup WHERE gid=? AND mid=?;"); cmd.bind(1, (long long int)gid.toInt64()); cmd.bind(2, (long long int)mid.toInt64()); cmd.executenonquery(); } catch (std::exception &e) { Warning("Failed to delete mcf backup: {0}\n", e.what()); } }
void InternalLink::cleanComplexMod(DesuraId id) { UI::Forms::ItemForm* form = showItemForm(id, UI::Forms::INSTALL_ACTION::IA_CLEANCOMPLEX, true); if (!form) Warning("Cant find item (or item not ready) for clean complex mod [{0}].\n", id.toInt64()); }
gcString MCFManager::newMcfPath(DesuraId id, MCFBranch branch, MCFBuild build, bool isUnAuthed) { gcString curPath = getMcfPath(id, branch, build, isUnAuthed); if (curPath != "") return curPath; curPath = generatePath(id, branch, build, isUnAuthed); gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); try { int flags = isUnAuthed?FLAG_UNAUTHED:FLAG_NONE; sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "INSERT INTO mcfitem VALUES (?,?,?,?,?);"); cmd.bind(1, (long long int)id.toInt64()); cmd.bind(2, (int)build); cmd.bind(3, UTIL::OS::getRelativePath(curPath)); cmd.bind(4, (int)branch); cmd.bind(5, (int)flags); cmd.executenonquery(); } catch (std::exception &e) { curPath = ""; Warning("Failed to insert mcf item: {0}\n", e.what()); } return curPath; }
void User::removeUninstallInfo(DesuraId id) { #ifdef WIN32 if (getServiceMain()) getServiceMain()->removeUninstallRegKey(id.toInt64()); #endif }
void User::updateUninstallInfo(DesuraId id, uint64 installSize) { #ifdef WIN32 if (getServiceMain()) getServiceMain()->setUninstallRegKey(id.toInt64(), installSize); #endif }
void UpdateInfoForm::setInfo(DesuraId id, bool launch) { m_bLaunch = launch; m_uiInternId = id; m_cbReminder->Enable(m_bLaunch); m_cbReminder->Show(m_bLaunch); UserCore::Item::ItemInfoI* item = GetUserCore()->getItemManager()->findItemInfo( id ); if (!item) { Warning("Cant find item for update form.\n"); return; } if (item->getIcon() && UTIL::FS::isValidFile(UTIL::FS::PathWithFile(item->getIcon()))) setIcon(item->getIcon()); m_cbReminder->SetValue(m_bLaunch && item->getOptions() & UserCore::Item::ItemInfoI::OPTION_NOTREMINDUPDATE); SetLabel(gcWString(L"{0} {1}", Managers::GetString(L"#UI_TITLE"), item->getName())); m_ieBrowser->loadUrl(gcWString(L"http://www.desura.com/{0}/{1}/changelog", id.getTypeString(), item->getShortName())); }
void GameExplorerManager::removeItem(DesuraId item) { Misc::GameExplorerInfo* gei = BaseManager::findItem(item.toInt64()); if (gei) gei->removeDll(); }
void UploadPrepThread::doRun() { UTIL::FS::Path path = UTIL::FS::PathWithFile(m_szFile); if (!UTIL::FS::isValidFile(path)) throw gcException(ERR_INVALIDFILE); McfHandle mcfHandle;; bool validMcf = false; mcfHandle->setFile(m_szFile.c_str()); mcfHandle->parseMCF(); MCFCore::MCFHeaderI* mcfHead = mcfHandle->getHeader(); DesuraId mcfId = mcfHead->getDesuraId(); DesuraId itemId = getItemId(); validMcf = (mcfHead->isValid() && (!mcfId.isOk() || mcfId == itemId)); if (!validMcf) throw gcException(ERR_INVALIDMCF); std::string hash = UTIL::MISC::hashFile(path.getFullPath().c_str()); uint64 fileSize = UTIL::FS::getFileSize(path); char* key = NULL; try { getWebCore()->newUpload(getItemId(), hash.c_str(), fileSize, &key); } catch (gcException &) { safe_delete(key); throw; } getUploadManager()->addUpload(getItemId(), key, m_szFile.c_str()); m_szKey = gcString(key); safe_delete(key); onCompleteStrEvent(m_szKey); }
gcString MCFManager::newMcfBackup(DesuraId gid, DesuraId mid) { gcString curPath = getMcfBackup(gid, mid); if (curPath != "") return curPath; gcString parPath; gcString parFile; size_t x=0; do { if (x==0) parFile = gcString("backup_{0}.mcf", mid.toInt64()); else parFile = gcString("backup_{0}_{1}.mcf", mid.toInt64(), x); parPath = gcString("{0}{1}{2}", m_szMCFSavePath, DIRS_STR, gid.getFolderPathExtension(parFile.c_str())); x++; } while ( UTIL::FS::isValidFile(UTIL::FS::PathWithFile(parPath)) ); gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "INSERT INTO mcfbackup VALUES (?,?,?);"); cmd.bind(1, (long long int)gid.toInt64()); cmd.bind(2, (long long int)mid.toInt64()); cmd.bind(3, UTIL::OS::getRelativePath(parPath)); cmd.executenonquery(); } catch (std::exception &e) { Warning("Failed to update mcf backup: {0}\n", e.what()); } return parPath; }
void MCFManager::validateMcf(const char* mcf) { if (!UTIL::FS::isValidFile(UTIL::FS::PathWithFile(mcf))) return; McfHandle mcfHandle; mcfHandle->setFile(mcf); try { mcfHandle->parseMCF(); } catch (gcException &) { return; } MCFCore::MCFHeaderI *mcfHead = mcfHandle->getHeader(); DesuraId id = mcfHead->getDesuraId(); MCFBuild build = mcfHead->getBuild(); MCFBranch branch = mcfHead->getBranch(); bool isPatch = strstr(mcf, "patch")?true:false; bool isUnAuthed = strstr(mcf, "unauth")?true:false; int flags = (isPatch?FLAG_PATCH:FLAG_NONE) + (isUnAuthed?FLAG_UNAUTHED:FLAG_NONE); gcString szItemDb = getMcfDb(m_szAppDataPath.c_str()); try { sqlite3x::sqlite3_connection db(szItemDb.c_str()); sqlite3x::sqlite3_command cmd(db, "INSERT INTO mcfitem VALUES (?,?,?,?,?);"); cmd.bind(1, (long long int)id.toInt64()); cmd.bind(2, (int)build); cmd.bind(3, UTIL::OS::getRelativePath(mcf)); cmd.bind(4, (int)branch); cmd.bind(5, (int)flags); cmd.executenonquery(); } catch (std::exception &) { } }
std::string ToolManager::getToolName(DesuraId toolId) { ToolInfo* info = findItem(toolId.toInt64()); if (!info) return ""; return info->getName(); }