2017-05-26 21:15:04 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
2013-03-30 14:44:10 +00:00
|
|
|
|
|
|
|
// 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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2017-12-10 01:26:26 +00:00
|
|
|
#include <memory>
|
2017-02-27 20:57:46 +00:00
|
|
|
#include <mutex>
|
2017-03-12 16:16:38 +00:00
|
|
|
#include <atomic>
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2020-11-30 15:46:52 +00:00
|
|
|
#include "Common/Thread/Event.h"
|
2013-03-30 14:44:10 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2021-05-05 23:31:38 +00:00
|
|
|
#include "Common/File/Path.h"
|
2013-04-13 20:39:19 +00:00
|
|
|
|
2016-12-25 17:18:19 +00:00
|
|
|
namespace Draw {
|
2016-12-25 20:01:57 +00:00
|
|
|
class DrawContext;
|
2016-12-25 19:54:37 +00:00
|
|
|
class Texture;
|
2016-12-25 17:18:19 +00:00
|
|
|
}
|
2014-08-17 19:29:36 +00:00
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
// A GameInfo holds information about a game, and also lets you do things that the VSH
|
|
|
|
// does on the PSP, namely checking for and deleting savedata, and similar things.
|
2013-11-20 13:42:48 +00:00
|
|
|
// Only cares about games that are installed on the current device.
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2015-06-11 18:22:16 +00:00
|
|
|
// A GameInfo object can also represent a piece of savedata.
|
|
|
|
|
2013-12-10 16:23:03 +00:00
|
|
|
// Guessed from GameID, not necessarily accurate
|
|
|
|
enum GameRegion {
|
|
|
|
GAMEREGION_JAPAN,
|
|
|
|
GAMEREGION_USA,
|
|
|
|
GAMEREGION_EUROPE,
|
|
|
|
GAMEREGION_HONGKONG,
|
|
|
|
GAMEREGION_ASIA,
|
2020-02-23 07:33:44 +00:00
|
|
|
GAMEREGION_KOREA,
|
2013-12-10 16:23:03 +00:00
|
|
|
GAMEREGION_OTHER,
|
|
|
|
GAMEREGION_MAX,
|
|
|
|
};
|
|
|
|
|
2024-01-28 15:23:27 +00:00
|
|
|
enum class GameInfoFlags {
|
|
|
|
FILE_TYPE = 0x01, // Don't need to specify this, always included.
|
|
|
|
PARAM_SFO = 0x02,
|
|
|
|
ICON = 0x04,
|
|
|
|
BG = 0x08,
|
|
|
|
SND = 0x10,
|
|
|
|
SIZE = 0x20,
|
|
|
|
UNCOMPRESSED_SIZE = 0x40,
|
2014-06-22 01:24:21 +00:00
|
|
|
};
|
2024-01-28 15:23:27 +00:00
|
|
|
ENUM_CLASS_BITOPS(GameInfoFlags);
|
2014-06-22 01:24:21 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
class FileLoader;
|
|
|
|
enum class IdentifiedFileType;
|
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
struct GameInfoTex {
|
|
|
|
std::string data;
|
2023-12-12 21:34:31 +00:00
|
|
|
Draw::Texture *texture = nullptr;
|
2017-03-26 07:00:57 +00:00
|
|
|
// The time at which the Icon and the BG were loaded.
|
|
|
|
// Can be useful to fade them in smoothly once they appear.
|
2024-01-29 09:44:46 +00:00
|
|
|
// Also, timeLoaded != 0 && texture == nullptr means that the load failed.
|
2017-03-26 07:00:57 +00:00
|
|
|
double timeLoaded = 0.0;
|
2017-03-26 11:07:36 +00:00
|
|
|
std::atomic<bool> dataLoaded{};
|
2017-03-26 07:00:57 +00:00
|
|
|
|
2023-12-12 21:34:31 +00:00
|
|
|
// Can ONLY be called from the main thread!
|
2023-12-12 22:10:46 +00:00
|
|
|
void Clear();
|
2024-01-29 09:44:46 +00:00
|
|
|
bool Failed() const {
|
|
|
|
return timeLoaded != 0.0 && !texture;
|
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
};
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
class GameInfo {
|
|
|
|
public:
|
2024-01-30 11:26:23 +00:00
|
|
|
GameInfo(const Path &gamePath);
|
2014-12-01 07:55:03 +00:00
|
|
|
~GameInfo();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2015-06-11 18:22:16 +00:00
|
|
|
bool Delete(); // Better be sure what you're doing when calling this.
|
2013-06-08 15:48:41 +00:00
|
|
|
bool DeleteAllSaveData();
|
2024-01-30 11:26:23 +00:00
|
|
|
bool CreateLoader();
|
2015-06-12 12:46:34 +00:00
|
|
|
|
2022-04-11 22:15:52 +00:00
|
|
|
bool HasFileLoader() const {
|
|
|
|
return fileLoader.get() != nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-10 01:26:26 +00:00
|
|
|
std::shared_ptr<FileLoader> GetFileLoader();
|
2015-06-10 06:16:21 +00:00
|
|
|
void DisposeFileLoader();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2024-09-07 13:01:13 +00:00
|
|
|
u64 GetSizeUncompressedInBytes(); // NOTE: More expensive than GetGameSizeOnDiskInBytes().
|
|
|
|
u64 GetSizeOnDiskInBytes();
|
|
|
|
u64 GetGameSavedataSizeInBytes(); // For games
|
2013-10-03 12:44:16 +00:00
|
|
|
u64 GetInstallDataSizeInBytes();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2024-09-07 13:01:13 +00:00
|
|
|
// For various kinds of savedata, mainly.
|
|
|
|
// NOTE: This one actually performs I/O directly, not cached.
|
|
|
|
std::string GetMTime() const;
|
|
|
|
|
2013-12-10 16:23:03 +00:00
|
|
|
void ParseParamSFO();
|
2024-09-07 13:01:13 +00:00
|
|
|
const ParamSFOData &GetParamSFO() const {
|
|
|
|
_dbg_assert_(hasFlags & GameInfoFlags::PARAM_SFO);
|
|
|
|
return paramSFO;
|
|
|
|
}
|
2024-01-28 13:50:16 +00:00
|
|
|
void FinishPendingTextureLoads(Draw::DrawContext *draw);
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
std::vector<Path> GetSaveDataDirectories();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2015-12-24 21:18:46 +00:00
|
|
|
std::string GetTitle();
|
2016-01-23 21:06:58 +00:00
|
|
|
void SetTitle(const std::string &newTitle);
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2024-05-13 22:02:59 +00:00
|
|
|
const Path &GetFilePath() const {
|
|
|
|
return filePath_;
|
|
|
|
}
|
|
|
|
|
2024-01-28 15:23:27 +00:00
|
|
|
bool Ready(GameInfoFlags flags) {
|
|
|
|
std::unique_lock<std::mutex> guard(lock);
|
2024-01-31 22:17:51 +00:00
|
|
|
// Avoid the operator, we want to check all the bits.
|
|
|
|
return ((int)hasFlags & (int)flags) == (int)flags;
|
2024-01-28 15:23:27 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 11:26:23 +00:00
|
|
|
void MarkReadyNoLock(GameInfoFlags flags) {
|
|
|
|
hasFlags |= flags;
|
|
|
|
pendingFlags &= ~flags;
|
|
|
|
}
|
|
|
|
|
2021-04-04 17:57:40 +00:00
|
|
|
GameInfoTex *GetBGPic() {
|
|
|
|
if (pic1.texture)
|
|
|
|
return &pic1;
|
2021-04-05 04:39:16 +00:00
|
|
|
if (pic0.texture)
|
|
|
|
return &pic0;
|
2021-04-04 17:57:40 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
// Hold this when reading or writing from the GameInfo.
|
|
|
|
// Don't need to hold it when just passing around the pointer,
|
|
|
|
// and obviously also not when creating it and holding the only pointer
|
|
|
|
// to it.
|
2017-02-27 20:57:46 +00:00
|
|
|
std::mutex lock;
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2023-05-04 07:20:05 +00:00
|
|
|
// Controls access to the fileLoader pointer.
|
|
|
|
std::mutex loaderLock;
|
|
|
|
|
2024-01-28 15:23:27 +00:00
|
|
|
// Keep track of what we have, or what we're processing.
|
|
|
|
// These are protected by the mutex. While pendingFlags != 0, something is being loaded.
|
|
|
|
GameInfoFlags hasFlags{};
|
|
|
|
GameInfoFlags pendingFlags{};
|
|
|
|
|
2013-06-09 11:41:15 +00:00
|
|
|
std::string id;
|
|
|
|
std::string id_version;
|
2017-03-02 11:29:03 +00:00
|
|
|
int disc_total = 0;
|
|
|
|
int disc_number = 0;
|
|
|
|
int region = -1;
|
2013-08-10 17:56:47 +00:00
|
|
|
IdentifiedFileType fileType;
|
2017-03-26 07:00:57 +00:00
|
|
|
bool hasConfig = false;
|
2013-11-20 13:42:48 +00:00
|
|
|
|
2013-03-30 18:23:20 +00:00
|
|
|
// Pre read the data, create a texture the next time (GL thread..)
|
2017-03-26 07:00:57 +00:00
|
|
|
GameInfoTex icon;
|
|
|
|
GameInfoTex pic0;
|
|
|
|
GameInfoTex pic1;
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2014-06-22 01:38:26 +00:00
|
|
|
std::string sndFileData;
|
2017-03-26 11:07:36 +00:00
|
|
|
std::atomic<bool> sndDataLoaded{};
|
2014-06-22 01:38:26 +00:00
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
double lastAccessedTime = 0.0;
|
2014-06-21 22:14:20 +00:00
|
|
|
|
2023-10-22 17:10:42 +00:00
|
|
|
u64 gameSizeUncompressed = 0;
|
|
|
|
u64 gameSizeOnDisk = 0; // compressed size, in case of CSO
|
2017-03-26 07:00:57 +00:00
|
|
|
u64 saveDataSize = 0;
|
|
|
|
u64 installDataSize = 0;
|
2020-11-30 15:46:52 +00:00
|
|
|
|
2015-06-10 06:16:21 +00:00
|
|
|
protected:
|
2024-09-07 13:01:13 +00:00
|
|
|
ParamSFOData paramSFO;
|
2015-12-24 21:18:46 +00:00
|
|
|
// Note: this can change while loading, use GetTitle().
|
|
|
|
std::string title;
|
|
|
|
|
2019-02-25 19:51:19 +00:00
|
|
|
// TODO: Get rid of this shared_ptr and managae lifetime better instead.
|
2017-12-10 01:26:26 +00:00
|
|
|
std::shared_ptr<FileLoader> fileLoader;
|
2021-05-05 23:31:38 +00:00
|
|
|
Path filePath_;
|
2017-05-18 10:41:42 +00:00
|
|
|
|
2024-01-28 13:50:16 +00:00
|
|
|
void SetupTexture(Draw::DrawContext *draw, GameInfoTex &tex);
|
|
|
|
|
2017-05-18 10:41:42 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(GameInfo);
|
2024-09-07 13:01:13 +00:00
|
|
|
friend class GameInfoWorkItem;
|
2013-03-30 14:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GameInfoCache {
|
|
|
|
public:
|
2016-02-14 21:07:10 +00:00
|
|
|
GameInfoCache();
|
2013-03-30 14:44:10 +00:00
|
|
|
~GameInfoCache();
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
// This creates a background worker thread!
|
2013-04-14 09:58:28 +00:00
|
|
|
void Clear();
|
2015-06-12 12:46:34 +00:00
|
|
|
void PurgeType(IdentifiedFileType fileType);
|
2013-04-13 19:24:07 +00:00
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
// All data in GameInfo including icon.texture may be zero the first time you call this
|
2013-03-30 14:44:10 +00:00
|
|
|
// but filled in later asynchronously in the background. So keep calling this,
|
2014-06-22 07:56:27 +00:00
|
|
|
// redrawing the UI often. Only set flags to GAMEINFO_WANTBG or WANTSND if you really want them
|
|
|
|
// because they're big. bgTextures and sound may be discarded over time as well.
|
2024-09-07 13:01:13 +00:00
|
|
|
// NOTE: This never returns null, so you don't need to check for that. Do check Ready() flags though.
|
2024-01-28 15:23:27 +00:00
|
|
|
std::shared_ptr<GameInfo> GetInfo(Draw::DrawContext *draw, const Path &gamePath, GameInfoFlags wantFlags);
|
2014-06-22 07:56:27 +00:00
|
|
|
void FlushBGs(); // Gets rid of all BG textures. Also gets rid of bg sounds.
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2017-12-10 00:48:38 +00:00
|
|
|
void CancelAll();
|
2015-10-03 22:00:46 +00:00
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
private:
|
2016-02-14 21:07:10 +00:00
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
2014-06-21 20:49:30 +00:00
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
// Maps ISO path to info. Need to use shared_ptr as we can return these pointers -
|
|
|
|
// and if they get destructed while being in use, that's bad.
|
|
|
|
std::map<std::string, std::shared_ptr<GameInfo> > info_;
|
2024-01-28 15:23:27 +00:00
|
|
|
std::mutex mapLock_;
|
2013-03-30 18:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This one can be global, no good reason not to.
|
2016-02-14 21:07:10 +00:00
|
|
|
extern GameInfoCache *g_gameInfoCache;
|