2013-11-20 14:42:48 +01:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
|
|
|
|
// Manages the PSP/GAME directory contents.
|
|
|
|
//
|
|
|
|
// Not concerned with full ISOs.
|
|
|
|
|
2013-12-06 01:04:50 +10:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-27 20:51:36 +01:00
|
|
|
#include <thread>
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/Net/HTTPClient.h"
|
2013-11-20 14:42:48 +01:00
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
enum class GameManagerState {
|
|
|
|
IDLE,
|
|
|
|
DOWNLOADING,
|
|
|
|
INSTALLING,
|
|
|
|
};
|
|
|
|
|
2019-07-07 23:12:26 +02:00
|
|
|
struct zip;
|
2019-07-14 17:43:51 -07:00
|
|
|
class FileLoader;
|
|
|
|
struct ZipFileInfo;
|
2019-07-07 23:12:26 +02:00
|
|
|
|
2013-11-20 14:42:48 +01:00
|
|
|
class GameManager {
|
|
|
|
public:
|
2013-12-05 13:01:00 +01:00
|
|
|
GameManager();
|
|
|
|
|
2013-11-20 14:42:48 +01:00
|
|
|
bool IsGameInstalled(std::string name);
|
|
|
|
|
|
|
|
// This starts off a background process.
|
|
|
|
bool DownloadAndInstall(std::string storeZipUrl);
|
2013-11-20 19:48:44 +01:00
|
|
|
bool Uninstall(std::string name);
|
2013-11-20 14:42:48 +01:00
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
// Cancels the download in progress, if any.
|
|
|
|
bool CancelDownload();
|
|
|
|
|
2013-11-20 14:42:48 +01:00
|
|
|
// Call from time to time to check on completed downloads from the
|
|
|
|
// main UI thread.
|
|
|
|
void Update();
|
|
|
|
|
2017-03-06 15:43:38 +01:00
|
|
|
GameManagerState GetState() {
|
|
|
|
if (installInProgress_)
|
|
|
|
return GameManagerState::INSTALLING;
|
|
|
|
if (curDownload_)
|
|
|
|
return GameManagerState::DOWNLOADING;
|
|
|
|
return GameManagerState::IDLE;
|
2015-07-04 08:40:40 -07:00
|
|
|
}
|
2017-03-06 15:43:38 +01:00
|
|
|
|
|
|
|
float GetCurrentInstallProgressPercentage() const {
|
2013-12-05 13:01:00 +01:00
|
|
|
return installProgress_;
|
|
|
|
}
|
2013-12-06 12:49:57 +01:00
|
|
|
std::string GetInstallError() const {
|
|
|
|
return installError_;
|
|
|
|
}
|
2013-12-05 13:01:00 +01:00
|
|
|
|
2013-12-05 14:11:35 +01:00
|
|
|
// Only returns false if there's already an installation in progress.
|
2019-07-10 23:37:10 +02:00
|
|
|
bool InstallGameOnThread(std::string url, std::string tempFileName, bool deleteAfter);
|
2013-12-05 14:11:35 +01:00
|
|
|
|
2013-11-20 14:42:48 +01:00
|
|
|
private:
|
2019-07-14 11:32:32 +02:00
|
|
|
bool InstallGame(const std::string &url, const std::string &tempFileName, bool deleteAfter);
|
2019-07-14 17:43:51 -07:00
|
|
|
bool InstallMemstickGame(struct zip *z, const std::string &zipFile, const std::string &pspGame, const ZipFileInfo &info, bool allowRoot, bool deleteAfter);
|
2019-07-07 23:12:26 +02:00
|
|
|
bool InstallZippedISO(struct zip *z, int isoFileIndex, std::string zipfile, bool deleteAfter);
|
2019-07-14 11:32:32 +02:00
|
|
|
bool InstallRawISO(const std::string &zipFile, const std::string &originalName, bool deleteAfter);
|
2013-12-05 17:49:37 +01:00
|
|
|
void InstallDone();
|
2019-07-07 23:55:17 +02:00
|
|
|
bool ExtractFile(struct zip *z, int file_index, std::string outFilename, size_t *bytesCopied, size_t allBytes);
|
2019-07-14 17:43:51 -07:00
|
|
|
bool DetectTexturePackDest(struct zip *z, int iniIndex, std::string *dest);
|
|
|
|
void SetInstallError(const std::string &err);
|
2013-12-05 17:49:37 +01:00
|
|
|
|
2013-11-20 16:36:58 +01:00
|
|
|
std::string GetTempFilename() const;
|
2019-07-14 17:43:51 -07:00
|
|
|
std::string GetGameID(const std::string &path) const;
|
|
|
|
std::string GetPBPGameID(FileLoader *loader) const;
|
|
|
|
std::string GetISOGameID(FileLoader *loader) const;
|
2013-11-20 14:42:48 +01:00
|
|
|
std::shared_ptr<http::Download> curDownload_;
|
2013-12-05 17:49:37 +01:00
|
|
|
std::shared_ptr<std::thread> installThread_;
|
2019-09-28 11:30:43 -07:00
|
|
|
bool installInProgress_ = false;
|
|
|
|
bool installDonePending_ = false;
|
|
|
|
float installProgress_ = 0.0f;
|
2013-12-06 12:49:57 +01:00
|
|
|
std::string installError_;
|
2013-11-20 14:42:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern GameManager g_GameManager;
|
2019-07-08 23:03:27 +02:00
|
|
|
|
|
|
|
enum class ZipFileContents {
|
|
|
|
UNKNOWN,
|
|
|
|
PSP_GAME_DIR,
|
|
|
|
ISO_FILE,
|
2019-07-14 17:43:51 -07:00
|
|
|
TEXTURE_PACK,
|
2019-07-08 23:03:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ZipFileInfo {
|
|
|
|
int numFiles;
|
|
|
|
int stripChars; // for PSP game
|
|
|
|
int isoFileIndex; // for ISO
|
2019-07-14 17:43:51 -07:00
|
|
|
int textureIniIndex; // for textures
|
|
|
|
bool ignoreMetaFiles;
|
2019-07-08 23:03:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info);
|
|
|
|
ZipFileContents DetectZipFileContents(std::string fileName, ZipFileInfo *info);
|