2013-03-30 14:44:10 +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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "base/mutex.h"
|
2013-06-08 15:48:41 +00:00
|
|
|
#include "file/file_util.h"
|
2013-04-13 19:24:07 +00:00
|
|
|
#include "thread/prioritizedworkqueue.h"
|
2013-03-30 14:44:10 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2013-04-13 20:39:19 +00:00
|
|
|
#include "Core/Loaders.h"
|
|
|
|
|
2014-08-17 19:29:36 +00:00
|
|
|
class Thin3DContext;
|
|
|
|
class Thin3DTexture;
|
|
|
|
|
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,
|
|
|
|
GAMEREGION_OTHER,
|
|
|
|
GAMEREGION_MAX,
|
|
|
|
};
|
|
|
|
|
2014-06-22 01:24:21 +00:00
|
|
|
enum GameInfoWantFlags {
|
|
|
|
GAMEINFO_WANTBG = 0x01,
|
|
|
|
GAMEINFO_WANTSIZE = 0x02,
|
2014-06-22 01:38:26 +00:00
|
|
|
GAMEINFO_WANTSND = 0x04,
|
2014-06-22 01:24:21 +00:00
|
|
|
};
|
|
|
|
|
2014-06-21 22:14:20 +00:00
|
|
|
// TODO: Need to fix c++11 still on Symbian and use std::atomic<bool> instead.
|
|
|
|
class CompletionFlag {
|
|
|
|
public:
|
|
|
|
CompletionFlag() : pending(1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDone() {
|
|
|
|
#if defined(_WIN32)
|
|
|
|
_WriteBarrier();
|
|
|
|
pending = 0;
|
|
|
|
#else
|
|
|
|
__sync_lock_release(&pending);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDone() {
|
|
|
|
const bool done = pending == 0;
|
|
|
|
#if defined(_WIN32)
|
|
|
|
_ReadBarrier();
|
|
|
|
#else
|
|
|
|
__sync_synchronize();
|
|
|
|
#endif
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompletionFlag &operator =(const bool &v) {
|
|
|
|
pending = v ? 0 : 1;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() {
|
|
|
|
return IsDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
volatile u32 pending;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CompletionFlag);
|
|
|
|
};
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
class GameInfo {
|
|
|
|
public:
|
2013-11-20 13:42:48 +00:00
|
|
|
GameInfo()
|
2014-01-11 06:13:11 +00:00
|
|
|
: disc_total(0), disc_number(0), region(-1), fileType(FILETYPE_UNKNOWN), paramSFOLoaded(false),
|
2015-09-10 15:17:26 +00:00
|
|
|
hasConfig(false), iconTexture(nullptr), pic0Texture(nullptr), pic1Texture(nullptr), wantFlags(0),
|
2015-06-12 10:39:22 +00:00
|
|
|
lastAccessedTime(0.0), timeIconWasLoaded(0.0), timePic0WasLoaded(0.0), timePic1WasLoaded(0.0),
|
2015-10-03 21:18:54 +00:00
|
|
|
gameSize(0), saveDataSize(0), installDataSize(0), pending(true), fileLoader(nullptr) {}
|
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();
|
2015-06-10 06:16:21 +00:00
|
|
|
bool LoadFromPath(const std::string &gamePath);
|
2015-06-12 12:46:34 +00:00
|
|
|
|
2015-06-10 06:16:21 +00:00
|
|
|
FileLoader *GetFileLoader();
|
|
|
|
void DisposeFileLoader();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
u64 GetGameSizeInBytes();
|
|
|
|
u64 GetSaveDataSizeInBytes();
|
2013-10-03 12:44:16 +00:00
|
|
|
u64 GetInstallDataSizeInBytes();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-12-10 16:23:03 +00:00
|
|
|
void ParseParamSFO();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-06-09 10:41:12 +00:00
|
|
|
std::vector<std::string> 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
|
|
|
|
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.
|
|
|
|
recursive_mutex lock;
|
|
|
|
|
2013-06-09 11:41:15 +00:00
|
|
|
std::string id;
|
|
|
|
std::string id_version;
|
2013-11-25 17:14:11 +00:00
|
|
|
int disc_total;
|
|
|
|
int disc_number;
|
2013-12-10 16:23:03 +00:00
|
|
|
int region;
|
2013-08-10 17:56:47 +00:00
|
|
|
IdentifiedFileType fileType;
|
2013-03-30 14:44:10 +00:00
|
|
|
ParamSFOData paramSFO;
|
2013-06-08 20:42:31 +00:00
|
|
|
bool paramSFOLoaded;
|
2015-09-10 15:17:26 +00:00
|
|
|
bool hasConfig;
|
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..)
|
|
|
|
std::string iconTextureData;
|
2014-08-17 19:29:36 +00:00
|
|
|
Thin3DTexture *iconTexture;
|
2013-04-01 10:35:02 +00:00
|
|
|
std::string pic0TextureData;
|
2014-08-17 19:29:36 +00:00
|
|
|
Thin3DTexture *pic0Texture;
|
2013-04-01 10:35:02 +00:00
|
|
|
std::string pic1TextureData;
|
2014-08-17 19:29:36 +00:00
|
|
|
Thin3DTexture *pic1Texture;
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2014-06-22 01:38:26 +00:00
|
|
|
std::string sndFileData;
|
|
|
|
|
2014-06-22 01:24:21 +00:00
|
|
|
int wantFlags;
|
2013-03-31 00:04:46 +00:00
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
double lastAccessedTime;
|
|
|
|
|
|
|
|
// The time at which the Icon and the BG were loaded.
|
|
|
|
// Can be useful to fade them in smoothly once they appear.
|
|
|
|
double timeIconWasLoaded;
|
2013-04-01 10:35:02 +00:00
|
|
|
double timePic0WasLoaded;
|
|
|
|
double timePic1WasLoaded;
|
2013-06-09 09:54:03 +00:00
|
|
|
|
2014-06-21 22:14:20 +00:00
|
|
|
CompletionFlag iconDataLoaded;
|
|
|
|
CompletionFlag pic0DataLoaded;
|
|
|
|
CompletionFlag pic1DataLoaded;
|
2014-06-22 01:38:26 +00:00
|
|
|
CompletionFlag sndDataLoaded;
|
2014-06-21 22:14:20 +00:00
|
|
|
|
2013-06-09 09:54:03 +00:00
|
|
|
u64 gameSize;
|
|
|
|
u64 saveDataSize;
|
2013-10-03 12:44:16 +00:00
|
|
|
u64 installDataSize;
|
2015-10-03 21:18:54 +00:00
|
|
|
bool pending;
|
2014-12-01 07:55:03 +00:00
|
|
|
|
2015-06-10 06:16:21 +00:00
|
|
|
protected:
|
2015-12-24 21:18:46 +00:00
|
|
|
// Note: this can change while loading, use GetTitle().
|
|
|
|
std::string title;
|
|
|
|
|
2014-12-01 07:55:03 +00:00
|
|
|
FileLoader *fileLoader;
|
2015-06-10 06:16:21 +00:00
|
|
|
std::string filePath_;
|
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();
|
2016-02-14 21:07:10 +00:00
|
|
|
void ClearTextures();
|
2015-06-12 12:46:34 +00:00
|
|
|
void PurgeType(IdentifiedFileType fileType);
|
2013-04-13 19:24:07 +00:00
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
// All data in GameInfo including iconTexture may be zero the first time you call this
|
|
|
|
// 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.
|
2014-08-17 19:29:36 +00:00
|
|
|
GameInfo *GetInfo(Thin3DContext *thin3d, const std::string &gamePath, int 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
|
|
|
|
2014-12-31 14:33:43 +00:00
|
|
|
PrioritizedWorkQueue *WorkQueue() { return gameInfoWQ_; }
|
|
|
|
|
2015-10-03 22:00:46 +00:00
|
|
|
void WaitUntilDone(GameInfo *info) {
|
|
|
|
// Hack - should really wait specifically for that item.
|
|
|
|
gameInfoWQ_->WaitUntilDone();
|
|
|
|
}
|
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
private:
|
2016-02-14 21:07:10 +00:00
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
2014-08-17 19:29:36 +00:00
|
|
|
void SetupTexture(GameInfo *info, std::string &textureData, Thin3DContext *thin3d, Thin3DTexture *&tex, double &loadTime);
|
2014-06-21 20:49:30 +00:00
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
// Maps ISO path to info.
|
|
|
|
std::map<std::string, GameInfo *> info_;
|
2013-04-13 19:24:07 +00:00
|
|
|
|
|
|
|
// Work queue and management
|
|
|
|
PrioritizedWorkQueue *gameInfoWQ_;
|
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;
|