From 66c3f31ff9d17c12ae31bb327014b950af30702b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 10 Jul 2019 23:37:10 +0200 Subject: [PATCH] More GameManager improvements. --- Core/Util/GameManager.cpp | 29 +++++++++++++++++++---------- Core/Util/GameManager.h | 6 +++--- UI/InstallZipScreen.cpp | 2 +- UI/Store.cpp | 13 ++++++++----- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 8997ea97b3..e17bd5db2a 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -30,6 +30,7 @@ #include "Common/Log.h" #include "Common/FileUtil.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/System.h" #include "Core/Util/GameManager.h" @@ -116,9 +117,10 @@ void GameManager::Update() { return; } // Game downloaded to temporary file - install it! - InstallGameOnThread(fileName, true); + InstallGameOnThread(curDownload_->url(), fileName, true); } else { - ERROR_LOG(HLE, "Expected HTTP status code 200, got status code %i. Install cancelled, deleting partial file.", curDownload_->ResultCode()); + ERROR_LOG(HLE, "Expected HTTP status code 200, got status code %d. Install cancelled, deleting partial file '%s'", + curDownload_->ResultCode(), fileName.c_str()); File::Delete(fileName.c_str()); } curDownload_.reset(); @@ -203,7 +205,7 @@ ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info) { } } -bool GameManager::InstallGame(std::string fileName, bool deleteAfter) { +bool GameManager::InstallGame(std::string url, std::string fileName, bool deleteAfter) { if (installInProgress_) { ERROR_LOG(HLE, "Cannot have two installs in progress at the same time"); return false; @@ -214,9 +216,11 @@ bool GameManager::InstallGame(std::string fileName, bool deleteAfter) { return false; } - bool isRawISO = false; // TODO: Make it possible to pass in this information. - if (isRawISO) { - return InstallRawISO(fileName, fileName); + // Examine the URL to guess out what we're installing. + if (endsWithNoCase(url, ".cso") || endsWithNoCase(url, ".iso")) { + // It's a raw ISO or CSO file. We just copy it to the destination. + std::string shortFilename = GetFilenameFromPath(url); + return InstallRawISO(fileName, shortFilename, deleteAfter); } I18NCategory *sy = GetI18NCategory("System"); @@ -414,18 +418,23 @@ bool GameManager::InstallZippedISO(struct zip *z, int isoFileIndex, std::string return true; } -bool GameManager::InstallGameOnThread(std::string zipFile, bool deleteAfter) { +bool GameManager::InstallGameOnThread(std::string url, std::string fileName, bool deleteAfter) { if (installInProgress_) { return false; } - installThread_.reset(new std::thread(std::bind(&GameManager::InstallGame, this, zipFile, deleteAfter))); + installThread_.reset(new std::thread(std::bind(&GameManager::InstallGame, this, url, fileName, deleteAfter))); installThread_->detach(); return true; } -bool GameManager::InstallRawISO(std::string file, std::string originalName) { +bool GameManager::InstallRawISO(std::string file, std::string originalName, bool deleteAfter) { std::string destPath = g_Config.currentDirectory + "/" + originalName; - File::Copy(file, destPath); + // TODO: To save disk space, we should probably attempt a move first. + if (File::Copy(file, destPath)) { + if (deleteAfter) { + File::Delete(file.c_str()); + } + } installProgress_ = 1.0f; installInProgress_ = false; installError_ = ""; diff --git a/Core/Util/GameManager.h b/Core/Util/GameManager.h index b654fb8655..92ba4bd7e0 100644 --- a/Core/Util/GameManager.h +++ b/Core/Util/GameManager.h @@ -66,13 +66,13 @@ public: } // Only returns false if there's already an installation in progress. - bool InstallGameOnThread(std::string zipFile, bool deleteAfter); + bool InstallGameOnThread(std::string url, std::string tempFileName, bool deleteAfter); private: - bool InstallGame(std::string zipfile, bool deleteAfter); + bool InstallGame(std::string url, std::string tempFileName, bool deleteAfter); bool InstallMemstickGame(struct zip *z, std::string zipFile, std::string pspGame, int numFiles, int stripChars, bool deleteAfter); bool InstallZippedISO(struct zip *z, int isoFileIndex, std::string zipfile, bool deleteAfter); - bool InstallRawISO(std::string zipFile, std::string originalName); + bool InstallRawISO(std::string zipFile, std::string originalName, bool deleteAfter); void InstallDone(); bool ExtractFile(struct zip *z, int file_index, std::string outFilename, size_t *bytesCopied, size_t allBytes); diff --git a/UI/InstallZipScreen.cpp b/UI/InstallZipScreen.cpp index a5ab9d9634..ea7d206d8a 100644 --- a/UI/InstallZipScreen.cpp +++ b/UI/InstallZipScreen.cpp @@ -81,7 +81,7 @@ bool InstallZipScreen::key(const KeyInput &key) { } UI::EventReturn InstallZipScreen::OnInstall(UI::EventParams ¶ms) { - if (g_GameManager.InstallGameOnThread(zipPath_, deleteZipFile_)) { + if (g_GameManager.InstallGameOnThread(zipPath_, zipPath_, deleteZipFile_)) { installStarted_ = true; installChoice_->SetEnabled(false); } diff --git a/UI/Store.cpp b/UI/Store.cpp index 58e780dbda..f403505c65 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -284,13 +284,16 @@ void ProductView::Update() { } UI::EventReturn ProductView::OnInstall(UI::EventParams &e) { - std::string zipUrl; + std::string fileUrl; if (entry_.downloadURL.empty()) { // Construct the URL, easy to predict from our server - zipUrl = storeBaseUrl + "files/" + entry_.file + ".zip"; + std::string shortName = entry_.file; + if (shortName.find('.') == std::string::npos) + shortName += ".zip"; + fileUrl = storeBaseUrl + "files/" + shortName; } else { // Use the provided URL, for external hosting. - zipUrl = entry_.downloadURL; + fileUrl = entry_.downloadURL; } if (installButton_) { installButton_->SetEnabled(false); @@ -298,8 +301,8 @@ UI::EventReturn ProductView::OnInstall(UI::EventParams &e) { if (cancelButton_) { cancelButton_->SetVisibility(UI::V_VISIBLE); } - INFO_LOG(SYSTEM, "Triggering install of %s", zipUrl.c_str()); - g_GameManager.DownloadAndInstall(zipUrl); + INFO_LOG(SYSTEM, "Triggering install of '%s'", fileUrl.c_str()); + g_GameManager.DownloadAndInstall(fileUrl); return UI::EVENT_DONE; }