2013-11-20 13:42:48 +00: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-05 15:04:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-27 19:51:36 +00:00
|
|
|
#include <thread>
|
2021-05-05 23:31:38 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/Net/HTTPClient.h"
|
2021-05-05 23:31:38 +00:00
|
|
|
#include "Common/File/Path.h"
|
2013-11-20 13:42:48 +00:00
|
|
|
|
2017-03-06 14:43:38 +00:00
|
|
|
enum class GameManagerState {
|
|
|
|
IDLE,
|
|
|
|
DOWNLOADING,
|
|
|
|
INSTALLING,
|
|
|
|
};
|
|
|
|
|
2019-07-07 21:12:26 +00:00
|
|
|
struct zip;
|
2019-07-15 00:43:51 +00:00
|
|
|
class FileLoader;
|
|
|
|
struct ZipFileInfo;
|
2019-07-07 21:12:26 +00:00
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
class GameManager {
|
|
|
|
public:
|
2013-12-05 12:01:00 +00:00
|
|
|
GameManager();
|
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
bool IsGameInstalled(std::string name);
|
|
|
|
|
|
|
|
// This starts off a background process.
|
|
|
|
bool DownloadAndInstall(std::string storeZipUrl);
|
2021-05-01 17:49:44 +00:00
|
|
|
bool IsDownloading(std::string storeZipUrl);
|
2013-11-20 18:48:44 +00:00
|
|
|
bool Uninstall(std::string name);
|
2013-11-20 13:42:48 +00:00
|
|
|
|
2017-03-06 14:43:38 +00:00
|
|
|
// Cancels the download in progress, if any.
|
|
|
|
bool CancelDownload();
|
|
|
|
|
2021-05-01 17:40:34 +00:00
|
|
|
float DownloadSpeedKBps();
|
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
// Call from time to time to check on completed downloads from the
|
|
|
|
// main UI thread.
|
|
|
|
void Update();
|
|
|
|
|
2017-03-06 14:43:38 +00:00
|
|
|
GameManagerState GetState() {
|
|
|
|
if (installInProgress_)
|
|
|
|
return GameManagerState::INSTALLING;
|
|
|
|
if (curDownload_)
|
|
|
|
return GameManagerState::DOWNLOADING;
|
|
|
|
return GameManagerState::IDLE;
|
2015-07-04 15:40:40 +00:00
|
|
|
}
|
2017-03-06 14:43:38 +00:00
|
|
|
|
|
|
|
float GetCurrentInstallProgressPercentage() const {
|
2013-12-05 12:01:00 +00:00
|
|
|
return installProgress_;
|
|
|
|
}
|
2021-10-17 00:53:05 +00:00
|
|
|
void ResetInstallError();
|
2013-12-06 11:49:57 +00:00
|
|
|
std::string GetInstallError() const {
|
|
|
|
return installError_;
|
|
|
|
}
|
2013-12-05 12:01:00 +00:00
|
|
|
|
2013-12-05 13:11:35 +00:00
|
|
|
// Only returns false if there's already an installation in progress.
|
2021-05-09 16:38:48 +00:00
|
|
|
bool InstallGameOnThread(const Path &url, const Path &tempFileName, bool deleteAfter);
|
2013-12-05 13:11:35 +00:00
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
private:
|
2021-05-09 16:38:48 +00:00
|
|
|
bool InstallGame(Path url, Path tempFileName, bool deleteAfter);
|
2021-05-13 09:08:27 +00:00
|
|
|
bool InstallMemstickGame(struct zip *z, const Path &zipFile, const Path &dest, const ZipFileInfo &info, bool allowRoot, bool deleteAfter);
|
2022-10-30 19:18:43 +00:00
|
|
|
bool InstallMemstickZip(struct zip *z, const Path &zipFile, const Path &dest, const ZipFileInfo &info, bool deleteAfter);
|
2021-05-09 16:38:48 +00:00
|
|
|
bool InstallZippedISO(struct zip *z, int isoFileIndex, const Path &zipfile, bool deleteAfter);
|
|
|
|
bool InstallRawISO(const Path &zipFile, const std::string &originalName, bool deleteAfter);
|
2013-12-05 16:49:37 +00:00
|
|
|
void InstallDone();
|
2021-05-05 23:31:38 +00:00
|
|
|
bool ExtractFile(struct zip *z, int file_index, const Path &outFilename, size_t *bytesCopied, size_t allBytes);
|
|
|
|
bool DetectTexturePackDest(struct zip *z, int iniIndex, Path &dest);
|
2019-07-15 00:43:51 +00:00
|
|
|
void SetInstallError(const std::string &err);
|
2013-12-05 16:49:37 +00:00
|
|
|
|
2021-05-15 05:46:03 +00:00
|
|
|
Path GetTempFilename() const;
|
2021-05-09 16:38:48 +00:00
|
|
|
std::string GetGameID(const Path &path) const;
|
2019-07-15 00:43:51 +00:00
|
|
|
std::string GetPBPGameID(FileLoader *loader) const;
|
|
|
|
std::string GetISOGameID(FileLoader *loader) const;
|
2013-11-20 13:42:48 +00:00
|
|
|
std::shared_ptr<http::Download> curDownload_;
|
2013-12-05 16:49:37 +00:00
|
|
|
std::shared_ptr<std::thread> installThread_;
|
2019-09-28 18:30:43 +00:00
|
|
|
bool installInProgress_ = false;
|
|
|
|
bool installDonePending_ = false;
|
|
|
|
float installProgress_ = 0.0f;
|
2013-12-06 11:49:57 +00:00
|
|
|
std::string installError_;
|
2013-11-20 13:42:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern GameManager g_GameManager;
|
2019-07-08 21:03:27 +00:00
|
|
|
|
|
|
|
enum class ZipFileContents {
|
|
|
|
UNKNOWN,
|
|
|
|
PSP_GAME_DIR,
|
|
|
|
ISO_FILE,
|
2019-07-15 00:43:51 +00:00
|
|
|
TEXTURE_PACK,
|
2019-07-08 21:03:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ZipFileInfo {
|
|
|
|
int numFiles;
|
|
|
|
int stripChars; // for PSP game
|
|
|
|
int isoFileIndex; // for ISO
|
2019-07-15 00:43:51 +00:00
|
|
|
int textureIniIndex; // for textures
|
|
|
|
bool ignoreMetaFiles;
|
2019-07-08 21:03:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ZipFileContents DetectZipFileContents(struct zip *z, ZipFileInfo *info);
|
2021-05-09 16:38:48 +00:00
|
|
|
ZipFileContents DetectZipFileContents(const Path &fileName, ZipFileInfo *info);
|