void UpdateManager::StartCheckForUpdates(GameDownloader downloader, Gui & gui) { const bool verbose = true; gui.ActivatePage("Downloading", 0.25, error_output); // download svn folder view to a temporary folder const std::string url = autoupdate.GetMetaUrl() + group + "/"; if (!downloader(url)) { gui.ActivatePage("DataConnectionError", 0.25, error_output); return; } // get the downloaded page info_output << "Checking for updates..." << std::endl; std::ifstream page(downloader.GetHttp().GetDownloadPath(url).c_str()); if (!page) { error_output << "File not found: " << downloader.GetHttp().GetDownloadPath(url) << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return; } const std::map <std::string, int> res = REPO::ParseFolderView(page); // check the current SVN picture against what's in our update manager to find things we can update autoupdate.SetAvailableUpdates(group, res); std::pair <std::vector <std::string>, std::vector <std::string> > updates = autoupdate.CheckUpdate(group); info_output << "Updates: " << updates.first.size() << " update(s), " << updates.second.size() << " deletion(s) found" << std::endl; if (verbose) { info_output << "Updates: ["; Utils::print_vector(updates.first, info_output); info_output << "]" << std::endl; info_output << "Deletions: ["; Utils::print_vector(updates.second, info_output); info_output << "]" << std::endl; } updates_num = updates.first.size(); // store the new set of available updates autoupdate.Write(updatefile); // attempt to download updates.config DownloadRemoteConfig(downloader); }
void UPDATE_MANAGER::StartCheckForUpdates(GAME_DOWNLOADER downloader, GUI & gui) { const bool verbose = true; gui.ActivatePage("Downloading", 0.25, error_output); // download the SVN folder views to a temporary folder repo_type svn; std::string url = autoupdate.GetUrl() + group + "/"; if (!downloader(url)) { gui.ActivatePage("DataConnectionError", 0.25, error_output); return; } // get the downloaded page info_output << "Checking for updates..." << std::endl; std::string page = UTILS::LoadFileIntoString(downloader.GetHttp().GetDownloadPath(url), error_output); std::map <std::string, int> res = svn.ParseFolderView(page); // check the current SVN picture against what's in our update manager to find things we can update autoupdate.SetAvailableUpdates(group, res); std::pair <std::vector <std::string>, std::vector <std::string> > updates = autoupdate.CheckUpdate(group); info_output << "Updates: " << updates.first.size() << " update(s), " << updates.second.size() << " deletion(s) found" << std::endl; if (verbose) { info_output << "Updates: ["; UTILS::print_vector(updates.first, info_output); info_output << "]" << std::endl; info_output << "Deletions: ["; UTILS::print_vector(updates.second, info_output); info_output << "]" << std::endl; } updates_num = updates.first.size(); // store the new set of available updates autoupdate.Write(updatefile); // attempt to download updates.config DownloadRemoteConfig(downloader); }
bool UPDATE_MANAGER::ApplyUpdate(GAME_DOWNLOADER downloader, GUI & gui, const PATHMANAGER & pathmanager) { const bool debug = false; std::string objectname; if (!gui.GetLabelText(guipage, "name", objectname)) { error_output << "Couldn't find the name label to update in " + guipage + "." << std::endl; return false; } std::pair <int, int> revs = autoupdate.GetVersions(group, objectname); if (revs.first == revs.second) { error_output << "ApplyUpdate: " << objectname << " is already up to date" << std::endl; return false; } // check that we have a recent enough release if (!DownloadRemoteConfig(downloader)) { error_output << "ApplyUpdate: unable to retrieve version information" << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return false; } // DownloadRemoteConfig should only return true if remoteconfig is set assert(remoteconfig.size()); int version = 0; if (!remoteconfig.get("formats", group, version, error_output)) { error_output << "ApplyUpdate: missing version information" << std::endl; return false; } int localversion = autoupdate.GetFormatVersion(group); if (localversion != version) { error_output << "ApplyUpdate: remote format for " << group << " is " << version << " but this version of VDrift only understands " << localversion << std::endl; gui.ActivatePage("UpdateFailedVersion", 0.25, error_output); return false; } // download archive std::string url = repo_type::GetDownloadLink(autoupdate.GetUrl(), group, objectname); std::string archivepath = downloader.GetHttp().GetDownloadPath(url); if (!(debug && pathmanager.FileExists(archivepath))) // if in debug mode, don't redownload files { info_output << "ApplyUpdate: attempting to download " + url << std::endl; bool success = downloader(url); if (!success) { error_output << "ApplyUpdate: download failed" << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return false; } } info_output << "ApplyUpdate: download successful: " << archivepath << std::endl; // decompress and write output if (!Decompress(archivepath, pathmanager.GetWriteableDataPath()+"/"+group, info_output, error_output)) { error_output << "ApplyUpdate: unable to decompress update" << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return false; } // record update if (!autoupdate.empty()) autoupdate.Write(updatefilebackup); // save a backup before changing it autoupdate.SetVersion(group, objectname, revs.second); autoupdate.Write(updatefile); // remove temporary file if (!debug) { PATHMANAGER::DeleteFile1(archivepath); } gui.ActivatePage("UpdateSuccessful", 0.25, error_output); return true; }
bool UpdateManager::ApplyUpdate(GameDownloader downloader, Gui & gui, const PathManager & pathmanager) { std::string objectname; if (!gui.GetLabelText(guipage, "name", objectname)) { error_output << "Couldn't find the name label to update in " + guipage + "." << std::endl; return false; } std::pair <int, int> revs = autoupdate.GetVersions(group, objectname); if (revs.first == revs.second) { error_output << "ApplyUpdate: " << objectname << " is already up to date" << std::endl; return false; } // check that we have a recent enough release if (!DownloadRemoteConfig(downloader)) { error_output << "ApplyUpdate: unable to retrieve version information" << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return false; } // DownloadRemoteConfig should only return true if remoteconfig is set assert(remoteconfig.size()); int version = 0; if (!remoteconfig.get("formats", group, version, error_output)) { error_output << "ApplyUpdate: missing version information" << std::endl; return false; } int localversion = autoupdate.GetFormatVersion(group); if (localversion != version) { error_output << "ApplyUpdate: remote format for " << group << " is " << version << " but this version of VDrift only understands " << localversion << std::endl; gui.ActivatePage("UpdateFailedVersion", 0.25, error_output); return false; } // make sure group dir exists PathManager::MakeDir(pathmanager.GetWriteableDataPath() + "/" + group + "/"); // download object const std::string folder_url = autoupdate.GetFileUrl() + group + "/" + objectname + "/"; const std::string folder_path = pathmanager.GetWriteableDataPath() + "/" + group + "/" + objectname + "/"; if (!REPO::DownloadFolder(folder_url, folder_path, downloader, error_output)) { error_output << "ApplyUpdate: download failed" << std::endl; gui.ActivatePage("DataConnectionError", 0.25, error_output); return false; } info_output << "ApplyUpdate: download successful: " << folder_path << std::endl; // record update if (!autoupdate.empty()) autoupdate.Write(updatefilebackup); // save a backup before changing it autoupdate.SetVersion(group, objectname, revs.second); autoupdate.Write(updatefile); gui.ActivatePage("UpdateSuccessful", 0.25, error_output); return true; }