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/.
|
|
|
|
|
2015-10-04 10:24:59 +00:00
|
|
|
#include "Common/Common.h"
|
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2014-11-23 21:25:32 +00:00
|
|
|
#include <memory>
|
2013-09-30 20:00:41 +00:00
|
|
|
#include <algorithm>
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2013-12-09 12:45:17 +00:00
|
|
|
#include "base/logging.h"
|
2013-03-30 14:44:10 +00:00
|
|
|
#include "base/timeutil.h"
|
|
|
|
#include "base/stringutil.h"
|
2013-06-08 15:48:41 +00:00
|
|
|
#include "file/file_util.h"
|
2013-06-22 21:25:22 +00:00
|
|
|
#include "file/zip_read.h"
|
2014-08-17 19:29:36 +00:00
|
|
|
#include "thin3d/thin3d.h"
|
2013-04-13 19:24:07 +00:00
|
|
|
#include "thread/prioritizedworkqueue.h"
|
2013-11-29 11:34:10 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2013-08-19 22:49:25 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2013-03-30 14:44:10 +00:00
|
|
|
#include "Core/FileSystems/ISOFileSystem.h"
|
|
|
|
#include "Core/FileSystems/DirectoryFileSystem.h"
|
2013-07-28 06:46:26 +00:00
|
|
|
#include "Core/FileSystems/VirtualDiscFileSystem.h"
|
2013-04-08 19:46:41 +00:00
|
|
|
#include "Core/ELF/PBPReader.h"
|
2016-01-23 21:06:58 +00:00
|
|
|
#include "Core/SaveState.h"
|
2013-06-09 10:41:12 +00:00
|
|
|
#include "Core/System.h"
|
2017-03-02 11:29:03 +00:00
|
|
|
#include "Core/Loaders.h"
|
2013-11-29 11:34:10 +00:00
|
|
|
#include "Core/Util/GameManager.h"
|
2013-06-08 15:48:41 +00:00
|
|
|
#include "Core/Config.h"
|
2013-11-29 11:34:10 +00:00
|
|
|
#include "UI/GameInfoCache.h"
|
2016-12-27 21:26:49 +00:00
|
|
|
#include "UI/TextureUtil.h"
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2016-02-14 21:07:10 +00:00
|
|
|
GameInfoCache *g_gameInfoCache;
|
2013-03-30 18:23:20 +00:00
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
GameInfo::GameInfo() : fileType(IdentifiedFileType::UNKNOWN) {
|
2017-03-02 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
2014-12-01 07:55:03 +00:00
|
|
|
GameInfo::~GameInfo() {
|
2017-05-18 10:41:42 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
|
|
|
sndDataLoaded = false;
|
|
|
|
icon.Clear();
|
|
|
|
pic0.Clear();
|
|
|
|
pic1.Clear();
|
2014-12-01 07:55:03 +00:00
|
|
|
delete fileLoader;
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:22:16 +00:00
|
|
|
bool GameInfo::Delete() {
|
2013-06-08 15:48:41 +00:00
|
|
|
switch (fileType) {
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
2013-09-30 19:11:42 +00:00
|
|
|
{
|
|
|
|
// Just delete the one file (TODO: handle two-disk games as well somehow).
|
2015-06-10 06:16:21 +00:00
|
|
|
const char *fileToRemove = filePath_.c_str();
|
2015-09-22 21:02:02 +00:00
|
|
|
File::Delete(fileToRemove);
|
2013-09-30 19:11:42 +00:00
|
|
|
auto i = std::find(g_Config.recentIsos.begin(), g_Config.recentIsos.end(), fileToRemove);
|
|
|
|
if (i != g_Config.recentIsos.end()) {
|
|
|
|
g_Config.recentIsos.erase(i);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2013-11-29 11:34:10 +00:00
|
|
|
{
|
|
|
|
// TODO: This could be handled by Core/Util/GameManager too somehow.
|
2016-06-27 03:33:25 +00:00
|
|
|
std::string directoryToRemove = ResolvePBPDirectory(filePath_);
|
2017-03-06 12:10:23 +00:00
|
|
|
INFO_LOG(SYSTEM, "Deleting %s", directoryToRemove.c_str());
|
2013-11-29 11:34:10 +00:00
|
|
|
if (!File::DeleteDirRecursively(directoryToRemove)) {
|
2017-03-06 12:10:23 +00:00
|
|
|
ERROR_LOG(SYSTEM, "Failed to delete file");
|
2013-11-29 11:34:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
g_Config.CleanRecent();
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ELF:
|
|
|
|
case IdentifiedFileType::UNKNOWN_BIN:
|
|
|
|
case IdentifiedFileType::UNKNOWN_ELF:
|
|
|
|
case IdentifiedFileType::ARCHIVE_RAR:
|
|
|
|
case IdentifiedFileType::ARCHIVE_ZIP:
|
|
|
|
case IdentifiedFileType::ARCHIVE_7Z:
|
2013-12-11 14:11:27 +00:00
|
|
|
{
|
2016-01-24 07:41:04 +00:00
|
|
|
const std::string &fileToRemove = filePath_;
|
2015-09-22 21:02:02 +00:00
|
|
|
File::Delete(fileToRemove);
|
2013-12-11 14:11:27 +00:00
|
|
|
return true;
|
2016-01-24 07:41:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PPSSPP_SAVESTATE:
|
2016-01-24 07:41:04 +00:00
|
|
|
{
|
|
|
|
const std::string &ppstPath = filePath_;
|
|
|
|
File::Delete(ppstPath);
|
|
|
|
const std::string screenshotPath = ReplaceAll(filePath_, ".ppst", ".jpg");
|
|
|
|
if (File::Exists(screenshotPath)) {
|
|
|
|
File::Delete(screenshotPath);
|
|
|
|
}
|
|
|
|
return true;
|
2013-12-11 14:11:27 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 03:33:25 +00:00
|
|
|
static int64_t GetDirectoryRecursiveSize(const std::string &path) {
|
2015-06-12 17:48:25 +00:00
|
|
|
std::vector<FileInfo> fileInfo;
|
|
|
|
getFilesInDir(path.c_str(), &fileInfo);
|
|
|
|
int64_t sizeSum = 0;
|
|
|
|
// Note: getFileInDir does not fill in fileSize properly.
|
|
|
|
for (size_t i = 0; i < fileInfo.size(); i++) {
|
|
|
|
FileInfo finfo;
|
|
|
|
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
|
|
|
if (!finfo.isDirectory)
|
|
|
|
sizeSum += finfo.size;
|
|
|
|
else
|
|
|
|
sizeSum += GetDirectoryRecursiveSize(finfo.fullName);
|
|
|
|
}
|
|
|
|
return sizeSum;
|
|
|
|
}
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
u64 GameInfo::GetGameSizeInBytes() {
|
|
|
|
switch (fileType) {
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2016-06-27 03:33:25 +00:00
|
|
|
return GetDirectoryRecursiveSize(ResolvePBPDirectory(filePath_));
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
default:
|
2015-06-10 06:16:21 +00:00
|
|
|
return GetFileLoader()->FileSize();
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:22:16 +00:00
|
|
|
// Not too meaningful if the object itself is a savedata directory...
|
2013-06-09 10:41:12 +00:00
|
|
|
std::vector<std::string> GameInfo::GetSaveDataDirectories() {
|
2013-10-15 06:03:39 +00:00
|
|
|
std::string memc = GetSysDirectory(DIRECTORY_SAVEDATA);
|
2013-06-09 10:41:12 +00:00
|
|
|
|
|
|
|
std::vector<FileInfo> dirs;
|
2013-10-15 06:28:14 +00:00
|
|
|
getFilesInDir(memc.c_str(), &dirs);
|
2013-12-06 10:44:46 +00:00
|
|
|
|
2013-06-09 10:41:12 +00:00
|
|
|
std::vector<std::string> directories;
|
2014-07-21 18:59:03 +00:00
|
|
|
if (id.size() < 5) {
|
2014-04-21 03:50:45 +00:00
|
|
|
return directories;
|
|
|
|
}
|
2013-06-09 10:41:12 +00:00
|
|
|
for (size_t i = 0; i < dirs.size(); i++) {
|
|
|
|
if (startsWith(dirs[i].name, id)) {
|
|
|
|
directories.push_back(dirs[i].fullName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return directories;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 GameInfo::GetSaveDataSizeInBytes() {
|
2017-03-02 11:29:03 +00:00
|
|
|
if (fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY || fileType == IdentifiedFileType::PPSSPP_SAVESTATE) {
|
2015-06-12 09:40:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-06-09 10:41:12 +00:00
|
|
|
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
u64 totalSize = 0;
|
2013-10-03 12:44:16 +00:00
|
|
|
u64 filesSizeInDir = 0;
|
2013-06-09 10:41:12 +00:00
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
|
|
|
std::vector<FileInfo> fileInfo;
|
|
|
|
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
|
|
|
// Note: getFileInDir does not fill in fileSize properly.
|
|
|
|
for (size_t i = 0; i < fileInfo.size(); i++) {
|
|
|
|
FileInfo finfo;
|
|
|
|
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
|
|
|
if (!finfo.isDirectory)
|
2013-10-03 12:44:16 +00:00
|
|
|
filesSizeInDir += finfo.size;
|
2013-06-09 10:41:12 +00:00
|
|
|
}
|
2013-10-03 12:44:16 +00:00
|
|
|
if (filesSizeInDir < 0xA00000) {
|
2015-06-11 18:22:16 +00:00
|
|
|
// HACK: Generally the savedata size in a dir shouldn't be more than 10MB.
|
2013-10-03 12:44:16 +00:00
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
}
|
|
|
|
filesSizeInDir = 0;
|
|
|
|
}
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 GameInfo::GetInstallDataSizeInBytes() {
|
2017-03-02 11:29:03 +00:00
|
|
|
if (fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY || fileType == IdentifiedFileType::PPSSPP_SAVESTATE) {
|
2015-06-12 10:39:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-03 12:44:16 +00:00
|
|
|
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
|
|
|
|
|
|
|
|
u64 totalSize = 0;
|
|
|
|
u64 filesSizeInDir = 0;
|
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
|
|
|
std::vector<FileInfo> fileInfo;
|
|
|
|
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
|
|
|
// Note: getFileInDir does not fill in fileSize properly.
|
|
|
|
for (size_t i = 0; i < fileInfo.size(); i++) {
|
|
|
|
FileInfo finfo;
|
|
|
|
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
|
|
|
if (!finfo.isDirectory)
|
|
|
|
filesSizeInDir += finfo.size;
|
|
|
|
}
|
|
|
|
if (filesSizeInDir >= 0xA00000) {
|
2015-06-11 18:22:16 +00:00
|
|
|
// HACK: Generally the savedata size in a dir shouldn't be more than 10MB.
|
2013-10-03 12:44:16 +00:00
|
|
|
// This is probably GameInstall data.
|
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
}
|
|
|
|
filesSizeInDir = 0;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
2015-06-10 06:16:21 +00:00
|
|
|
bool GameInfo::LoadFromPath(const std::string &gamePath) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2015-06-10 06:19:09 +00:00
|
|
|
// No need to rebuild if we already have it loaded.
|
|
|
|
if (filePath_ != gamePath) {
|
|
|
|
delete fileLoader;
|
|
|
|
fileLoader = ConstructFileLoader(gamePath);
|
2017-03-02 16:07:12 +00:00
|
|
|
if (!fileLoader)
|
|
|
|
return false;
|
2015-06-10 06:19:09 +00:00
|
|
|
filePath_ = gamePath;
|
2015-12-24 21:18:46 +00:00
|
|
|
|
|
|
|
// This is a fallback title, while we're loading / if unable to load.
|
|
|
|
title = File::GetFilename(filePath_);
|
2015-06-10 06:19:09 +00:00
|
|
|
}
|
2015-06-10 06:16:21 +00:00
|
|
|
|
2017-02-27 10:32:40 +00:00
|
|
|
return fileLoader ? fileLoader->Exists() : true;
|
2015-06-10 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileLoader *GameInfo::GetFileLoader() {
|
|
|
|
if (!fileLoader) {
|
|
|
|
fileLoader = ConstructFileLoader(filePath_);
|
|
|
|
}
|
|
|
|
return fileLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfo::DisposeFileLoader() {
|
|
|
|
delete fileLoader;
|
|
|
|
fileLoader = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
bool GameInfo::DeleteAllSaveData() {
|
2013-06-09 10:41:12 +00:00
|
|
|
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
|
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
|
|
|
std::vector<FileInfo> fileInfo;
|
|
|
|
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-06-09 10:41:12 +00:00
|
|
|
u64 totalSize = 0;
|
|
|
|
for (size_t i = 0; i < fileInfo.size(); i++) {
|
2015-09-22 21:02:02 +00:00
|
|
|
File::Delete(fileInfo[i].fullName.c_str());
|
2013-06-09 10:41:12 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2015-09-22 21:02:02 +00:00
|
|
|
File::DeleteDir(saveDataDir[j].c_str());
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2013-12-10 16:23:03 +00:00
|
|
|
void GameInfo::ParseParamSFO() {
|
|
|
|
title = paramSFO.GetValueString("TITLE");
|
|
|
|
id = paramSFO.GetValueString("DISC_ID");
|
|
|
|
id_version = paramSFO.GetValueString("DISC_ID") + "_" + paramSFO.GetValueString("DISC_VERSION");
|
|
|
|
disc_total = paramSFO.GetValueInt("DISC_TOTAL");
|
|
|
|
disc_number = paramSFO.GetValueInt("DISC_NUMBER");
|
|
|
|
// region = paramSFO.GetValueInt("REGION"); // Always seems to be 32768?
|
|
|
|
|
|
|
|
region = GAMEREGION_OTHER;
|
|
|
|
if (id_version.size() >= 4) {
|
|
|
|
std::string regStr = id_version.substr(0, 4);
|
|
|
|
|
|
|
|
// Guesswork
|
|
|
|
switch (regStr[2]) {
|
|
|
|
case 'E': region = GAMEREGION_EUROPE; break;
|
|
|
|
case 'U': region = GAMEREGION_USA; break;
|
|
|
|
case 'J': region = GAMEREGION_JAPAN; break;
|
|
|
|
case 'H': region = GAMEREGION_HONGKONG; break;
|
|
|
|
case 'A': region = GAMEREGION_ASIA; break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (regStr == "NPEZ" || regStr == "NPEG" || regStr == "ULES" || regStr == "UCES" ||
|
|
|
|
regStr == "NPEX") {
|
|
|
|
region = GAMEREGION_EUROPE;
|
|
|
|
} else if (regStr == "NPUG" || regStr == "NPUZ" || regStr == "ULUS" || regStr == "UCUS") {
|
|
|
|
region = GAMEREGION_USA;
|
|
|
|
} else if (regStr == "NPJH" || regStr == "NPJG" || regStr == "ULJM"|| regStr == "ULJS") {
|
|
|
|
region = GAMEREGION_JAPAN;
|
|
|
|
} else if (regStr == "NPHG") {
|
|
|
|
region = GAMEREGION_HONGKONG;
|
|
|
|
} else if (regStr == "UCAS") {
|
|
|
|
region = GAMEREGION_CHINA;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
paramSFOLoaded = true;
|
|
|
|
}
|
|
|
|
|
2015-12-24 21:18:46 +00:00
|
|
|
std::string GameInfo::GetTitle() {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2015-12-24 21:18:46 +00:00
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2016-03-06 21:52:16 +00:00
|
|
|
bool GameInfo::IsPending() {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2016-03-06 21:52:16 +00:00
|
|
|
return pending;
|
|
|
|
}
|
|
|
|
|
2016-03-06 22:00:09 +00:00
|
|
|
bool GameInfo::IsWorking() {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2016-03-06 22:00:09 +00:00
|
|
|
return working;
|
|
|
|
}
|
|
|
|
|
2016-01-23 21:06:58 +00:00
|
|
|
void GameInfo::SetTitle(const std::string &newTitle) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2016-01-23 21:06:58 +00:00
|
|
|
title = newTitle;
|
|
|
|
}
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, std::mutex *mtx) {
|
2013-03-30 14:44:10 +00:00
|
|
|
PSPFileInfo info = fs->GetFileInfo(filename);
|
2013-04-01 10:35:02 +00:00
|
|
|
if (!info.exists) {
|
2013-03-30 14:44:10 +00:00
|
|
|
return false;
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
|
|
|
|
int handle = fs->OpenFile(filename, FILEACCESS_READ);
|
2013-04-01 10:35:02 +00:00
|
|
|
if (!handle) {
|
2013-03-30 14:44:10 +00:00
|
|
|
return false;
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2013-04-13 20:29:42 +00:00
|
|
|
if (mtx) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(*mtx);
|
2013-04-13 20:29:42 +00:00
|
|
|
contents->resize(info.size);
|
|
|
|
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
|
|
|
|
} else {
|
|
|
|
contents->resize(info.size);
|
|
|
|
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
|
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
fs->CloseFile(handle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
static bool ReadVFSToString(const char *filename, std::string *contents, std::mutex *mtx) {
|
2015-12-24 20:45:07 +00:00
|
|
|
size_t sz;
|
|
|
|
uint8_t *data = VFSReadFile(filename, &sz);
|
|
|
|
if (data) {
|
|
|
|
if (mtx) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(*mtx);
|
2015-12-24 20:45:07 +00:00
|
|
|
*contents = std::string((const char *)data, sz);
|
|
|
|
} else {
|
|
|
|
*contents = std::string((const char *)data, sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] data;
|
|
|
|
return data != nullptr;
|
|
|
|
}
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
|
|
|
|
class GameInfoWorkItem : public PrioritizedWorkQueueItem {
|
|
|
|
public:
|
2017-05-18 10:52:03 +00:00
|
|
|
GameInfoWorkItem(const std::string &gamePath, std::shared_ptr<GameInfo> &info)
|
2013-04-13 19:24:07 +00:00
|
|
|
: gamePath_(gamePath), info_(info) {
|
|
|
|
}
|
|
|
|
|
2016-06-27 03:33:25 +00:00
|
|
|
~GameInfoWorkItem() override {
|
|
|
|
info_->DisposeFileLoader();
|
|
|
|
}
|
|
|
|
|
2016-08-28 10:09:01 +00:00
|
|
|
void run() override {
|
2015-06-10 06:16:21 +00:00
|
|
|
if (!info_->LoadFromPath(gamePath_))
|
2013-04-13 19:24:07 +00:00
|
|
|
return;
|
|
|
|
|
2015-12-24 20:37:29 +00:00
|
|
|
{
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2016-03-06 22:00:09 +00:00
|
|
|
info_->working = true;
|
2015-12-24 20:37:29 +00:00
|
|
|
info_->fileType = Identify_File(info_->GetFileLoader());
|
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
switch (info_->fileType) {
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP:
|
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
2013-04-13 19:24:07 +00:00
|
|
|
{
|
2015-12-24 18:40:25 +00:00
|
|
|
FileLoader *pbpLoader = info_->GetFileLoader();
|
|
|
|
std::unique_ptr<FileLoader> altLoader;
|
2017-03-02 11:29:03 +00:00
|
|
|
if (info_->fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
|
2016-06-27 03:33:25 +00:00
|
|
|
std::string ebootPath = ResolvePBPFile(gamePath_);
|
|
|
|
if (ebootPath != gamePath_) {
|
|
|
|
pbpLoader = ConstructFileLoader(ebootPath);
|
|
|
|
altLoader.reset(pbpLoader);
|
|
|
|
}
|
2015-12-24 18:40:25 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2015-12-24 18:40:25 +00:00
|
|
|
PBPReader pbp(pbpLoader);
|
2013-12-11 13:22:25 +00:00
|
|
|
if (!pbp.IsValid()) {
|
|
|
|
if (pbp.IsELF()) {
|
|
|
|
goto handleELF;
|
|
|
|
}
|
2015-12-24 18:40:25 +00:00
|
|
|
ERROR_LOG(LOADER, "invalid pbp %s\n", pbpLoader->Path().c_str());
|
2013-06-08 15:48:41 +00:00
|
|
|
return;
|
2013-12-11 13:22:25 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
// First, PARAM.SFO.
|
2015-12-24 18:20:27 +00:00
|
|
|
std::vector<u8> sfoData;
|
|
|
|
if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2015-12-24 18:20:27 +00:00
|
|
|
info_->paramSFO.ReadSFO(sfoData);
|
2013-12-10 16:23:03 +00:00
|
|
|
info_->ParseParamSFO();
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
// Then, ICON0.PNG.
|
2015-12-24 20:37:29 +00:00
|
|
|
if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2017-03-26 07:00:57 +00:00
|
|
|
pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->icon.data);
|
2015-12-24 20:37:29 +00:00
|
|
|
} else {
|
|
|
|
// Read standard icon
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
info_->icon.dataLoaded = true;
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2014-06-22 01:24:21 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTBG) {
|
2014-06-22 01:29:54 +00:00
|
|
|
if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2017-03-26 07:00:57 +00:00
|
|
|
pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0.data);
|
|
|
|
info_->pic0.dataLoaded = true;
|
2014-06-22 01:29:54 +00:00
|
|
|
}
|
2013-06-22 21:25:22 +00:00
|
|
|
if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2017-03-26 07:00:57 +00:00
|
|
|
pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1.data);
|
|
|
|
info_->pic1.dataLoaded = true;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
2014-06-22 01:38:26 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTSND) {
|
|
|
|
if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2014-06-22 01:38:26 +00:00
|
|
|
pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData);
|
|
|
|
info_->sndDataLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
2013-07-15 16:57:42 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ELF:
|
2013-12-11 13:22:25 +00:00
|
|
|
handleELF:
|
2013-06-08 15:48:41 +00:00
|
|
|
// An elf on its own has no usable information, no icons, no nothing.
|
2015-12-24 20:37:29 +00:00
|
|
|
{
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2015-12-24 20:37:29 +00:00
|
|
|
info_->id = "ELF000000";
|
|
|
|
info_->id_version = "ELF000000_1.00";
|
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
}
|
2015-12-24 20:45:07 +00:00
|
|
|
|
|
|
|
// Read standard icon
|
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because there was an ELF");
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-07-15 16:57:42 +00:00
|
|
|
break;
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2015-06-11 18:22:16 +00:00
|
|
|
{
|
|
|
|
SequentialHandleAllocator handles;
|
|
|
|
VirtualDiscFileSystem umd(&handles, gamePath_.c_str());
|
|
|
|
|
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
|
|
|
std::string paramSFOcontents;
|
|
|
|
if (ReadFileToString(&umd, "/PARAM.SFO", ¶mSFOcontents, 0)) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2015-06-11 18:22:16 +00:00
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
|
|
|
info_->ParseParamSFO();
|
|
|
|
}
|
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadFileToString(&umd, "/ICON0.PNG", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2015-06-11 18:22:16 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTBG) {
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadFileToString(&umd, "/PIC1.PNG", &info_->pic1.data, &info_->lock);
|
|
|
|
info_->pic1.dataLoaded = true;
|
2015-06-11 18:22:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PPSSPP_SAVESTATE:
|
2015-06-11 21:59:02 +00:00
|
|
|
{
|
2016-01-23 21:06:58 +00:00
|
|
|
info_->SetTitle(SaveState::GetTitle(gamePath_));
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(info_->lock);
|
2016-01-23 21:06:58 +00:00
|
|
|
|
2016-01-23 19:27:41 +00:00
|
|
|
// Let's use the screenshot as an icon, too.
|
|
|
|
std::string screenshotPath = ReplaceAll(gamePath_, ".ppst", ".jpg");
|
|
|
|
if (File::Exists(screenshotPath)) {
|
2017-03-26 07:00:57 +00:00
|
|
|
if (readFileToString(false, screenshotPath.c_str(), info_->icon.data)) {
|
|
|
|
info_->icon.dataLoaded = true;
|
2016-01-23 19:27:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-11 21:59:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
2013-07-23 15:35:43 +00:00
|
|
|
{
|
2017-03-02 11:29:03 +00:00
|
|
|
info_->fileType = IdentifiedFileType::PSP_ISO;
|
2013-07-23 15:35:43 +00:00
|
|
|
SequentialHandleAllocator handles;
|
2013-12-06 10:44:46 +00:00
|
|
|
VirtualDiscFileSystem umd(&handles, gamePath_.c_str());
|
|
|
|
|
2013-07-23 15:35:43 +00:00
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
|
|
|
std::string paramSFOcontents;
|
|
|
|
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2013-07-23 15:35:43 +00:00
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
2013-12-10 16:23:03 +00:00
|
|
|
info_->ParseParamSFO();
|
2013-07-23 15:35:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2014-06-22 01:24:21 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTBG) {
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, &info_->lock);
|
|
|
|
info_->pic0.dataLoaded = true;
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1.data, &info_->lock);
|
|
|
|
info_->pic1.dataLoaded = true;
|
2013-07-23 15:35:43 +00:00
|
|
|
}
|
2014-06-22 01:38:26 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTSND) {
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
|
2017-03-26 07:00:57 +00:00
|
|
|
info_->pic1.dataLoaded = true;
|
2014-06-22 01:38:26 +00:00
|
|
|
}
|
2013-07-23 15:35:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-11 21:59:02 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
2013-06-23 14:24:45 +00:00
|
|
|
{
|
2017-03-02 11:29:03 +00:00
|
|
|
info_->fileType = IdentifiedFileType::PSP_ISO;
|
2013-06-23 14:24:45 +00:00
|
|
|
SequentialHandleAllocator handles;
|
|
|
|
// Let's assume it's an ISO.
|
|
|
|
// TODO: This will currently read in the whole directory tree. Not really necessary for just a
|
|
|
|
// few files.
|
2017-02-28 00:47:13 +00:00
|
|
|
FileLoader *fl = info_->GetFileLoader();
|
|
|
|
if (!fl)
|
|
|
|
return; // Happens with UWP currently, TODO...
|
2015-06-10 06:16:21 +00:00
|
|
|
BlockDevice *bd = constructBlockDevice(info_->GetFileLoader());
|
2013-06-23 14:24:45 +00:00
|
|
|
if (!bd)
|
|
|
|
return; // nothing to do here..
|
2016-02-29 00:13:57 +00:00
|
|
|
ISOFileSystem umd(&handles, bd);
|
2013-06-23 14:24:45 +00:00
|
|
|
|
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
|
|
|
std::string paramSFOcontents;
|
2015-12-24 20:37:29 +00:00
|
|
|
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, nullptr)) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2013-06-23 14:24:45 +00:00
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
2013-12-10 16:23:03 +00:00
|
|
|
info_->ParseParamSFO();
|
2013-12-11 14:29:41 +00:00
|
|
|
|
2014-06-22 01:24:21 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTBG) {
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, nullptr);
|
|
|
|
info_->pic0.dataLoaded = true;
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1.data, nullptr);
|
|
|
|
info_->pic1.dataLoaded = true;
|
2013-12-11 14:29:41 +00:00
|
|
|
}
|
2014-06-22 01:38:26 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTSND) {
|
2017-02-27 20:57:46 +00:00
|
|
|
ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, nullptr);
|
2017-03-26 07:00:57 +00:00
|
|
|
info_->pic1.dataLoaded = true;
|
2014-06-22 01:38:26 +00:00
|
|
|
}
|
2014-03-06 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though
|
2017-03-26 07:00:57 +00:00
|
|
|
if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock)) {
|
2013-12-11 14:29:41 +00:00
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
2013-06-23 14:24:45 +00:00
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
info_->icon.dataLoaded = true;
|
2013-06-23 14:24:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-12-06 10:44:46 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_ZIP:
|
2013-12-11 14:11:27 +00:00
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
{
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("zip.png", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-12-11 14:11:27 +00:00
|
|
|
}
|
2013-08-20 14:52:36 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_RAR:
|
2013-12-11 14:24:29 +00:00
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
{
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("rargray.png", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-12-11 14:24:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_7Z:
|
2014-10-20 22:09:24 +00:00
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
{
|
2017-03-26 07:00:57 +00:00
|
|
|
ReadVFSToString("7z.png", &info_->icon.data, &info_->lock);
|
|
|
|
info_->icon.dataLoaded = true;
|
2014-10-20 22:09:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::NORMAL_DIRECTORY:
|
2013-08-20 14:52:36 +00:00
|
|
|
default:
|
2013-12-11 14:11:27 +00:00
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
break;
|
2013-06-09 09:54:03 +00:00
|
|
|
}
|
2014-06-22 01:24:21 +00:00
|
|
|
|
2015-09-10 15:17:26 +00:00
|
|
|
info_->hasConfig = g_Config.hasGameConfig(info_->id);
|
|
|
|
|
2014-06-22 01:24:21 +00:00
|
|
|
if (info_->wantFlags & GAMEINFO_WANTSIZE) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2013-06-09 09:54:03 +00:00
|
|
|
info_->gameSize = info_->GetGameSizeInBytes();
|
|
|
|
info_->saveDataSize = info_->GetSaveDataSizeInBytes();
|
2013-10-03 12:44:16 +00:00
|
|
|
info_->installDataSize = info_->GetInstallDataSizeInBytes();
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
2016-03-06 21:52:16 +00:00
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2016-03-06 21:52:16 +00:00
|
|
|
info_->pending = false;
|
2016-03-06 22:00:09 +00:00
|
|
|
info_->working = false;
|
2016-02-14 21:07:10 +00:00
|
|
|
// ILOG("Completed writing info for %s", info_->GetTitle().c_str());
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 02:41:39 +00:00
|
|
|
float priority() override {
|
2013-04-13 19:24:07 +00:00
|
|
|
return info_->lastAccessedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string gamePath_;
|
2017-05-18 10:52:03 +00:00
|
|
|
std::shared_ptr<GameInfo> info_;
|
2013-04-13 19:24:07 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(GameInfoWorkItem);
|
|
|
|
};
|
|
|
|
|
2016-02-14 21:07:10 +00:00
|
|
|
GameInfoCache::GameInfoCache() : gameInfoWQ_(nullptr) {
|
|
|
|
Init();
|
|
|
|
}
|
2013-04-13 19:24:07 +00:00
|
|
|
|
|
|
|
GameInfoCache::~GameInfoCache() {
|
2013-04-14 09:58:28 +00:00
|
|
|
Clear();
|
2016-02-14 21:07:10 +00:00
|
|
|
Shutdown();
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfoCache::Init() {
|
|
|
|
gameInfoWQ_ = new PrioritizedWorkQueue();
|
|
|
|
ProcessWorkQueueOnThreadWhile(gameInfoWQ_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfoCache::Shutdown() {
|
2016-02-10 14:22:28 +00:00
|
|
|
if (gameInfoWQ_) {
|
|
|
|
StopProcessingWorkQueue(gameInfoWQ_);
|
|
|
|
delete gameInfoWQ_;
|
|
|
|
gameInfoWQ_ = nullptr;
|
|
|
|
}
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 09:58:28 +00:00
|
|
|
void GameInfoCache::Clear() {
|
2016-02-14 21:07:10 +00:00
|
|
|
if (gameInfoWQ_) {
|
2013-07-11 05:27:24 +00:00
|
|
|
gameInfoWQ_->Flush();
|
2016-02-14 21:07:10 +00:00
|
|
|
gameInfoWQ_->WaitUntilDone();
|
|
|
|
}
|
2013-04-14 11:01:01 +00:00
|
|
|
info_.clear();
|
2013-04-14 09:58:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:02 +00:00
|
|
|
void GameInfoCache::FlushBGs() {
|
|
|
|
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(iter->second->lock);
|
2017-03-26 07:00:57 +00:00
|
|
|
iter->second->pic0.Clear();
|
|
|
|
iter->second->pic1.Clear();
|
2014-06-22 07:56:27 +00:00
|
|
|
if (!iter->second->sndFileData.empty()) {
|
|
|
|
iter->second->sndFileData.clear();
|
|
|
|
iter->second->sndDataLoaded = false;
|
|
|
|
}
|
2017-03-26 17:02:34 +00:00
|
|
|
iter->second->wantFlags &= ~(GAMEINFO_WANTBG | GAMEINFO_WANTSND | GAMEINFO_WANTBGDATA);
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 12:46:34 +00:00
|
|
|
void GameInfoCache::PurgeType(IdentifiedFileType fileType) {
|
|
|
|
if (gameInfoWQ_)
|
|
|
|
gameInfoWQ_->Flush();
|
|
|
|
restart:
|
|
|
|
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
|
|
|
|
if (iter->second->fileType == fileType) {
|
|
|
|
info_.erase(iter);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
void GameInfoCache::WaitUntilDone(std::shared_ptr<GameInfo> &info) {
|
2016-03-06 21:52:16 +00:00
|
|
|
while (info->IsPending()) {
|
|
|
|
if (gameInfoWQ_->WaitUntilDone(false)) {
|
|
|
|
// A true return means everything finished, so bail out.
|
|
|
|
// This way even if something gets stuck, we won't hang.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, wait again if it's not done...
|
|
|
|
}
|
2016-03-06 21:16:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 12:46:34 +00:00
|
|
|
|
2014-08-17 19:29:36 +00:00
|
|
|
// Runs on the main thread.
|
2017-05-18 10:52:03 +00:00
|
|
|
std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const std::string &gamePath, int wantFlags) {
|
|
|
|
std::shared_ptr<GameInfo> info;
|
2014-06-21 20:44:07 +00:00
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
auto iter = info_.find(gamePath);
|
|
|
|
if (iter != info_.end()) {
|
2017-05-18 10:52:03 +00:00
|
|
|
info = iter->second;
|
2017-03-26 07:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If wantFlags don't match, we need to start over. We'll just queue the work item again.
|
|
|
|
if (info && (info->wantFlags & wantFlags) == wantFlags) {
|
|
|
|
if (draw && info->icon.dataLoaded && !info->icon.texture) {
|
|
|
|
SetupTexture(info, draw, info->icon);
|
2014-06-21 22:14:20 +00:00
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
if (draw && info->pic0.dataLoaded && !info->pic0.texture) {
|
|
|
|
SetupTexture(info, draw, info->pic0);
|
2014-06-21 22:14:20 +00:00
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
if (draw && info->pic1.dataLoaded && !info->pic1.texture) {
|
|
|
|
SetupTexture(info, draw, info->pic1);
|
2014-06-21 22:14:20 +00:00
|
|
|
}
|
2017-03-26 07:00:57 +00:00
|
|
|
info->lastAccessedTime = time_now_d();
|
|
|
|
return info;
|
2013-03-30 14:44:10 +00:00
|
|
|
}
|
|
|
|
|
2014-06-21 20:44:07 +00:00
|
|
|
if (!info) {
|
2017-05-18 10:52:03 +00:00
|
|
|
info = std::make_shared<GameInfo>();
|
2014-06-21 20:44:07 +00:00
|
|
|
}
|
2016-03-06 22:00:09 +00:00
|
|
|
|
2016-03-08 04:19:07 +00:00
|
|
|
if (info->IsWorking()) {
|
|
|
|
// Uh oh, it's currently in process. It could mark pending = false with the wrong wantFlags.
|
|
|
|
// Let's wait it out, then queue.
|
|
|
|
WaitUntilDone(info);
|
|
|
|
}
|
|
|
|
|
2014-06-21 20:44:07 +00:00
|
|
|
{
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(info->lock);
|
2014-06-22 01:24:21 +00:00
|
|
|
info->wantFlags |= wantFlags;
|
2016-03-06 21:52:16 +00:00
|
|
|
info->pending = true;
|
2014-06-21 20:44:07 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
GameInfoWorkItem *item = new GameInfoWorkItem(gamePath, info);
|
|
|
|
gameInfoWQ_->Add(item);
|
2013-03-30 14:44:10 +00:00
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
// Don't re-insert if we already have it.
|
|
|
|
if (info_.find(gamePath) == info_.end())
|
|
|
|
info_[gamePath] = std::shared_ptr<GameInfo>(info);
|
2013-04-13 19:24:07 +00:00
|
|
|
return info;
|
2013-03-30 14:44:10 +00:00
|
|
|
}
|
2014-06-21 20:49:30 +00:00
|
|
|
|
2017-05-18 10:52:03 +00:00
|
|
|
void GameInfoCache::SetupTexture(std::shared_ptr<GameInfo> &info, Draw::DrawContext *thin3d, GameInfoTex &tex) {
|
2016-12-25 17:18:19 +00:00
|
|
|
using namespace Draw;
|
2017-05-18 10:41:42 +00:00
|
|
|
if (tex.data.size()) {
|
|
|
|
if (!tex.texture) {
|
|
|
|
tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT);
|
|
|
|
if (tex.texture) {
|
|
|
|
tex.timeLoaded = time_now_d();
|
2014-06-21 20:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-26 17:02:34 +00:00
|
|
|
if ((info->wantFlags & GAMEINFO_WANTBGDATA) == 0) {
|
2017-05-18 10:41:42 +00:00
|
|
|
tex.data.clear();
|
|
|
|
tex.dataLoaded = false;
|
2017-03-26 17:02:34 +00:00
|
|
|
}
|
2014-06-21 20:49:30 +00:00
|
|
|
}
|
|
|
|
}
|