2013-03-30 15:44:10 +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/.
|
|
|
|
|
|
2015-10-04 12:24:59 +02:00
|
|
|
#include "Common/Common.h"
|
|
|
|
|
|
2013-03-30 15:44:10 +01:00
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
2014-11-23 13:25:32 -08:00
|
|
|
#include <memory>
|
2013-09-30 16:00:41 -04:00
|
|
|
#include <algorithm>
|
2013-03-30 15:44:10 +01:00
|
|
|
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/thin3d.h"
|
2020-11-30 16:46:52 +01:00
|
|
|
#include "Common/Thread/ThreadManager.h"
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Common/File/VFS/VFS.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/File/FileUtil.h"
|
2021-05-06 01:31:38 +02:00
|
|
|
#include "Common/File/Path.h"
|
2023-12-12 23:10:46 +01:00
|
|
|
#include "Common/Render/ManagedTexture.h"
|
2013-08-20 00:49:25 +02:00
|
|
|
#include "Common/StringUtils.h"
|
2020-08-15 20:53:08 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
2013-03-30 15:44:10 +01:00
|
|
|
#include "Core/FileSystems/ISOFileSystem.h"
|
|
|
|
|
#include "Core/FileSystems/DirectoryFileSystem.h"
|
2013-07-27 23:46:26 -07:00
|
|
|
#include "Core/FileSystems/VirtualDiscFileSystem.h"
|
2013-04-08 21:46:41 +02:00
|
|
|
#include "Core/ELF/PBPReader.h"
|
2016-01-23 13:06:58 -08:00
|
|
|
#include "Core/SaveState.h"
|
2013-06-09 12:41:12 +02:00
|
|
|
#include "Core/System.h"
|
2017-03-02 12:29:03 +01:00
|
|
|
#include "Core/Loaders.h"
|
2013-11-29 12:34:10 +01:00
|
|
|
#include "Core/Util/GameManager.h"
|
2013-06-08 17:48:41 +02:00
|
|
|
#include "Core/Config.h"
|
2013-11-29 12:34:10 +01:00
|
|
|
#include "UI/GameInfoCache.h"
|
2013-06-08 17:48:41 +02:00
|
|
|
|
2016-02-14 22:07:10 +01:00
|
|
|
GameInfoCache *g_gameInfoCache;
|
2013-03-30 19:23:20 +01:00
|
|
|
|
2023-12-12 23:10:46 +01:00
|
|
|
void GameInfoTex::Clear() {
|
|
|
|
|
if (!data.empty()) {
|
|
|
|
|
data.clear();
|
|
|
|
|
dataLoaded = false;
|
|
|
|
|
}
|
|
|
|
|
if (texture) {
|
|
|
|
|
texture->Release();
|
|
|
|
|
texture = nullptr;
|
|
|
|
|
}
|
2024-05-10 14:15:07 +02:00
|
|
|
timeLoaded = 0.0;
|
2023-12-12 23:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 12:26:23 +01:00
|
|
|
GameInfo::GameInfo(const Path &gamePath) : filePath_(gamePath) {
|
2024-01-28 16:23:27 +01:00
|
|
|
// here due to a forward decl.
|
|
|
|
|
fileType = IdentifiedFileType::UNKNOWN;
|
2017-03-02 12:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:55:03 -08:00
|
|
|
GameInfo::~GameInfo() {
|
2017-05-18 12:41:42 +02:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
|
|
|
|
sndDataLoaded = false;
|
|
|
|
|
icon.Clear();
|
|
|
|
|
pic0.Clear();
|
|
|
|
|
pic1.Clear();
|
2017-12-09 17:26:26 -08:00
|
|
|
fileLoader.reset();
|
2014-11-30 23:55:03 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-11 20:22:16 +02:00
|
|
|
bool GameInfo::Delete() {
|
2013-06-08 17:48:41 +02:00
|
|
|
switch (fileType) {
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
2013-09-30 15:11:42 -04:00
|
|
|
{
|
|
|
|
|
// Just delete the one file (TODO: handle two-disk games as well somehow).
|
2021-05-14 22:48:04 -07:00
|
|
|
Path fileToRemove = filePath_;
|
2024-01-22 10:08:50 +01:00
|
|
|
INFO_LOG(SYSTEM, "Deleting file %s", fileToRemove.c_str());
|
2015-09-22 23:02:02 +02:00
|
|
|
File::Delete(fileToRemove);
|
2021-05-06 01:31:38 +02:00
|
|
|
g_Config.RemoveRecent(filePath_.ToString());
|
2013-09-30 15:11:42 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
|
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2013-11-29 12:34:10 +01:00
|
|
|
{
|
|
|
|
|
// TODO: This could be handled by Core/Util/GameManager too somehow.
|
2021-05-09 18:38:48 +02:00
|
|
|
Path directoryToRemove = ResolvePBPDirectory(filePath_);
|
2024-01-22 10:08:50 +01:00
|
|
|
INFO_LOG(SYSTEM, "Deleting directory %s", directoryToRemove.c_str());
|
2013-11-29 12:34:10 +01:00
|
|
|
if (!File::DeleteDirRecursively(directoryToRemove)) {
|
2017-03-06 13:10:23 +01:00
|
|
|
ERROR_LOG(SYSTEM, "Failed to delete file");
|
2013-11-29 12:34:10 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
g_Config.CleanRecent();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_ELF:
|
|
|
|
|
case IdentifiedFileType::UNKNOWN_BIN:
|
|
|
|
|
case IdentifiedFileType::UNKNOWN_ELF:
|
2022-04-30 17:47:17 +02:00
|
|
|
case IdentifiedFileType::UNKNOWN_ISO:
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::ARCHIVE_RAR:
|
|
|
|
|
case IdentifiedFileType::ARCHIVE_ZIP:
|
|
|
|
|
case IdentifiedFileType::ARCHIVE_7Z:
|
2019-03-21 19:49:32 -07:00
|
|
|
case IdentifiedFileType::PPSSPP_GE_DUMP:
|
2013-12-11 15:11:27 +01:00
|
|
|
{
|
2021-05-06 01:31:38 +02:00
|
|
|
const Path &fileToRemove = filePath_;
|
2024-01-22 10:08:50 +01:00
|
|
|
INFO_LOG(SYSTEM, "Deleting file %s", fileToRemove.c_str());
|
2015-09-22 23:02:02 +02:00
|
|
|
File::Delete(fileToRemove);
|
2021-05-06 01:31:38 +02:00
|
|
|
g_Config.RemoveRecent(filePath_.ToString());
|
2013-12-11 15:11:27 +01:00
|
|
|
return true;
|
2016-01-23 23:41:04 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PPSSPP_SAVESTATE:
|
2016-01-23 23:41:04 -08:00
|
|
|
{
|
2021-05-06 01:31:38 +02:00
|
|
|
const Path &ppstPath = filePath_;
|
2024-01-22 10:08:50 +01:00
|
|
|
INFO_LOG(SYSTEM, "Deleting file %s", ppstPath.c_str());
|
2016-01-23 23:41:04 -08:00
|
|
|
File::Delete(ppstPath);
|
2021-05-11 23:58:54 +02:00
|
|
|
const Path screenshotPath = filePath_.WithReplacedExtension(".ppst", ".jpg");
|
2016-01-23 23:41:04 -08:00
|
|
|
if (File::Exists(screenshotPath)) {
|
|
|
|
|
File::Delete(screenshotPath);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2013-12-11 15:11:27 +01:00
|
|
|
}
|
2013-06-08 17:48:41 +02:00
|
|
|
|
|
|
|
|
default:
|
2024-01-22 10:08:50 +01:00
|
|
|
INFO_LOG(SYSTEM, "Don't know how to delete this type of file: %s", filePath_.c_str());
|
2013-06-08 17:48:41 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 11:10:42 -06:00
|
|
|
u64 GameInfo::GetGameSizeOnDiskInBytes() {
|
2013-06-08 17:48:41 +02:00
|
|
|
switch (fileType) {
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
|
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2021-09-11 17:50:07 +02:00
|
|
|
return File::ComputeRecursiveDirectorySize(ResolvePBPDirectory(filePath_));
|
2024-01-12 15:37:35 +01:00
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
|
|
|
|
return File::ComputeRecursiveDirectorySize(GetFileLoader()->GetPath());
|
2013-06-08 17:48:41 +02:00
|
|
|
default:
|
2015-06-09 23:16:21 -07:00
|
|
|
return GetFileLoader()->FileSize();
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 11:10:42 -06:00
|
|
|
u64 GameInfo::GetGameSizeUncompressedInBytes() {
|
|
|
|
|
switch (fileType) {
|
|
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
|
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
|
|
|
|
return File::ComputeRecursiveDirectorySize(ResolvePBPDirectory(filePath_));
|
2024-01-12 15:37:35 +01:00
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
|
|
|
|
return File::ComputeRecursiveDirectorySize(GetFileLoader()->GetPath());
|
2023-10-22 11:10:42 -06:00
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
BlockDevice *blockDevice = constructBlockDevice(GetFileLoader().get());
|
2023-12-02 23:40:56 +01:00
|
|
|
if (blockDevice) {
|
|
|
|
|
u64 size = blockDevice->GetUncompressedSize();
|
|
|
|
|
delete blockDevice;
|
|
|
|
|
return size;
|
|
|
|
|
} else {
|
|
|
|
|
return GetFileLoader()->FileSize();
|
|
|
|
|
}
|
2023-10-22 11:10:42 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-11 20:22:16 +02:00
|
|
|
// Not too meaningful if the object itself is a savedata directory...
|
2024-01-31 22:08:26 +01:00
|
|
|
// Call this under lock.
|
2021-05-06 01:31:38 +02:00
|
|
|
std::vector<Path> GameInfo::GetSaveDataDirectories() {
|
2024-01-31 22:08:26 +01:00
|
|
|
_dbg_assert_(hasFlags & GameInfoFlags::PARAM_SFO); // so we know we have the ID.
|
2021-05-06 01:31:38 +02:00
|
|
|
Path memc = GetSysDirectory(DIRECTORY_SAVEDATA);
|
2013-06-09 12:41:12 +02:00
|
|
|
|
2021-04-25 20:38:22 +02:00
|
|
|
std::vector<File::FileInfo> dirs;
|
2021-05-06 01:31:38 +02:00
|
|
|
File::GetFilesInDir(memc, &dirs);
|
2013-12-06 11:44:46 +01:00
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
std::vector<Path> directories;
|
2014-07-21 20:59:03 +02:00
|
|
|
if (id.size() < 5) {
|
2014-04-20 20:50:45 -07:00
|
|
|
return directories;
|
|
|
|
|
}
|
2013-06-09 12:41:12 +02:00
|
|
|
for (size_t i = 0; i < dirs.size(); i++) {
|
|
|
|
|
if (startsWith(dirs[i].name, id)) {
|
2021-05-14 22:48:04 -07:00
|
|
|
directories.push_back(dirs[i].fullName);
|
2013-06-09 12:41:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return directories;
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 GameInfo::GetSaveDataSizeInBytes() {
|
2017-03-02 12:29:03 +01:00
|
|
|
if (fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY || fileType == IdentifiedFileType::PPSSPP_SAVESTATE) {
|
2015-06-12 11:40:50 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
2021-05-06 01:31:38 +02:00
|
|
|
std::vector<Path> saveDataDir = GetSaveDataDirectories();
|
2013-06-08 17:48:41 +02:00
|
|
|
|
|
|
|
|
u64 totalSize = 0;
|
2013-10-03 20:44:16 +08:00
|
|
|
u64 filesSizeInDir = 0;
|
2013-06-09 12:41:12 +02:00
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
2021-04-25 20:38:22 +02:00
|
|
|
std::vector<File::FileInfo> fileInfo;
|
2021-05-06 01:31:38 +02:00
|
|
|
File::GetFilesInDir(saveDataDir[j], &fileInfo);
|
2021-09-11 15:11:56 +02:00
|
|
|
for (auto const &file : fileInfo) {
|
|
|
|
|
if (!file.isDirectory)
|
|
|
|
|
filesSizeInDir += file.size;
|
2013-06-09 12:41:12 +02:00
|
|
|
}
|
2013-10-03 20:44:16 +08:00
|
|
|
if (filesSizeInDir < 0xA00000) {
|
2015-06-11 20:22:16 +02:00
|
|
|
// HACK: Generally the savedata size in a dir shouldn't be more than 10MB.
|
2013-10-03 20:44:16 +08:00
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
|
}
|
|
|
|
|
filesSizeInDir = 0;
|
|
|
|
|
}
|
|
|
|
|
return totalSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 GameInfo::GetInstallDataSizeInBytes() {
|
2017-03-02 12:29:03 +01:00
|
|
|
if (fileType == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY || fileType == IdentifiedFileType::PPSSPP_SAVESTATE) {
|
2015-06-12 12:39:22 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
2021-05-06 01:31:38 +02:00
|
|
|
std::vector<Path> saveDataDir = GetSaveDataDirectories();
|
2013-10-03 20:44:16 +08:00
|
|
|
|
|
|
|
|
u64 totalSize = 0;
|
|
|
|
|
u64 filesSizeInDir = 0;
|
|
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
2021-04-25 20:38:22 +02:00
|
|
|
std::vector<File::FileInfo> fileInfo;
|
2021-05-06 01:31:38 +02:00
|
|
|
File::GetFilesInDir(saveDataDir[j], &fileInfo);
|
2021-09-11 15:12:55 +02:00
|
|
|
for (auto const &file : fileInfo) {
|
|
|
|
|
// TODO: Might want to recurse here? Don't know games that use directories
|
|
|
|
|
// for install-data though.
|
|
|
|
|
if (!file.isDirectory)
|
|
|
|
|
filesSizeInDir += file.size;
|
2013-10-03 20:44:16 +08:00
|
|
|
}
|
|
|
|
|
if (filesSizeInDir >= 0xA00000) {
|
2015-06-11 20:22:16 +02:00
|
|
|
// HACK: Generally the savedata size in a dir shouldn't be more than 10MB.
|
2013-10-03 20:44:16 +08:00
|
|
|
// This is probably GameInstall data.
|
|
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
|
}
|
|
|
|
|
filesSizeInDir = 0;
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
return totalSize;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 12:26:23 +01:00
|
|
|
bool GameInfo::CreateLoader() {
|
|
|
|
|
if (!fileLoader) {
|
2024-01-18 22:52:56 +01:00
|
|
|
std::lock_guard<std::mutex> guard(loaderLock);
|
2024-01-30 12:26:23 +01:00
|
|
|
fileLoader.reset(ConstructFileLoader(filePath_));
|
2024-01-18 22:52:56 +01:00
|
|
|
if (!fileLoader)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-12-29 08:56:27 -08:00
|
|
|
return true;
|
2015-06-09 23:16:21 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-09 17:26:26 -08:00
|
|
|
std::shared_ptr<FileLoader> GameInfo::GetFileLoader() {
|
2019-02-25 20:51:19 +01:00
|
|
|
if (filePath_.empty()) {
|
2020-11-30 16:46:52 +01:00
|
|
|
// Happens when workqueue tries to figure out priorities,
|
|
|
|
|
// because Priority() calls GetFileLoader()... gnarly.
|
2019-02-25 20:51:19 +01:00
|
|
|
return fileLoader;
|
|
|
|
|
}
|
2023-05-04 09:20:05 +02:00
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(loaderLock);
|
2015-06-09 23:16:21 -07:00
|
|
|
if (!fileLoader) {
|
2023-05-04 09:20:05 +02:00
|
|
|
FileLoader *loader = ConstructFileLoader(filePath_);
|
|
|
|
|
fileLoader.reset(loader);
|
|
|
|
|
return fileLoader;
|
2015-06-09 23:16:21 -07:00
|
|
|
}
|
|
|
|
|
return fileLoader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameInfo::DisposeFileLoader() {
|
2023-05-04 09:20:05 +02:00
|
|
|
std::lock_guard<std::mutex> guard(loaderLock);
|
2017-12-09 17:26:26 -08:00
|
|
|
fileLoader.reset();
|
2015-06-09 23:16:21 -07:00
|
|
|
}
|
|
|
|
|
|
2013-06-08 17:48:41 +02:00
|
|
|
bool GameInfo::DeleteAllSaveData() {
|
2021-05-06 01:31:38 +02:00
|
|
|
std::vector<Path> saveDataDir = GetSaveDataDirectories();
|
2013-06-09 12:41:12 +02:00
|
|
|
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
2021-04-25 20:38:22 +02:00
|
|
|
std::vector<File::FileInfo> fileInfo;
|
2021-05-06 01:31:38 +02:00
|
|
|
File::GetFilesInDir(saveDataDir[j], &fileInfo);
|
2013-06-08 17:48:41 +02:00
|
|
|
|
2013-06-09 12:41:12 +02:00
|
|
|
for (size_t i = 0; i < fileInfo.size(); i++) {
|
2021-05-14 22:48:04 -07:00
|
|
|
File::Delete(fileInfo[i].fullName);
|
2013-06-09 12:41:12 +02:00
|
|
|
}
|
2013-06-08 17:48:41 +02:00
|
|
|
|
2021-05-09 15:02:23 +02:00
|
|
|
File::DeleteDir(saveDataDir[j]);
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-03-30 15:44:10 +01:00
|
|
|
|
2013-12-10 17:23:03 +01:00
|
|
|
void GameInfo::ParseParamSFO() {
|
|
|
|
|
title = paramSFO.GetValueString("TITLE");
|
|
|
|
|
id = paramSFO.GetValueString("DISC_ID");
|
2017-05-26 23:15:04 +02:00
|
|
|
id_version = id + "_" + paramSFO.GetValueString("DISC_VERSION");
|
2013-12-10 17:23:03 +01:00
|
|
|
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;
|
2020-02-23 08:33:44 +01:00
|
|
|
case 'K': region = GAMEREGION_KOREA; break;
|
2013-12-10 17:23:03 +01:00
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
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;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-24 13:18:46 -08:00
|
|
|
std::string GameInfo::GetTitle() {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2024-01-30 12:31:56 +01:00
|
|
|
if ((hasFlags & GameInfoFlags::PARAM_SFO) && !title.empty()) {
|
2024-01-28 16:23:27 +01:00
|
|
|
return title;
|
|
|
|
|
} else {
|
|
|
|
|
return filePath_.GetFilename();
|
|
|
|
|
}
|
2015-12-24 13:18:46 -08:00
|
|
|
}
|
|
|
|
|
|
2016-01-23 13:06:58 -08:00
|
|
|
void GameInfo::SetTitle(const std::string &newTitle) {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> guard(lock);
|
2016-01-23 13:06:58 -08:00
|
|
|
title = newTitle;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-28 14:50:16 +01:00
|
|
|
void GameInfo::FinishPendingTextureLoads(Draw::DrawContext *draw) {
|
|
|
|
|
if (draw && icon.dataLoaded && !icon.texture) {
|
|
|
|
|
SetupTexture(draw, icon);
|
|
|
|
|
}
|
|
|
|
|
if (draw && pic0.dataLoaded && !pic0.texture) {
|
|
|
|
|
SetupTexture(draw, pic0);
|
|
|
|
|
}
|
|
|
|
|
if (draw && pic1.dataLoaded && !pic1.texture) {
|
|
|
|
|
SetupTexture(draw, pic1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameInfo::SetupTexture(Draw::DrawContext *thin3d, GameInfoTex &tex) {
|
2024-01-29 10:44:46 +01:00
|
|
|
if (tex.timeLoaded) {
|
|
|
|
|
// Failed before, skip.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tex.data.empty()) {
|
|
|
|
|
tex.timeLoaded = time_now_d();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-01-28 14:50:16 +01:00
|
|
|
using namespace Draw;
|
2024-01-28 16:23:27 +01:00
|
|
|
// TODO: Use TempImage to semi-load the image in the worker task, then here we
|
|
|
|
|
// could just call CreateTextureFromTempImage.
|
2024-04-02 19:03:12 +03:00
|
|
|
tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), tex.data.size(), ImageFileType::DETECT, false, GetTitle().c_str());
|
2024-01-29 10:44:46 +01:00
|
|
|
tex.timeLoaded = time_now_d();
|
|
|
|
|
if (!tex.texture) {
|
2024-04-13 01:05:55 +02:00
|
|
|
ERROR_LOG(G3D, "Failed creating texture (%s) from %d-byte file", GetTitle().c_str(), (int)tex.data.size());
|
2024-01-28 14:50:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 21:57:46 +01:00
|
|
|
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, std::mutex *mtx) {
|
2013-03-30 15:44:10 +01:00
|
|
|
PSPFileInfo info = fs->GetFileInfo(filename);
|
2013-04-01 12:35:02 +02:00
|
|
|
if (!info.exists) {
|
2013-03-30 15:44:10 +01:00
|
|
|
return false;
|
2013-04-01 12:35:02 +02:00
|
|
|
}
|
2013-03-30 15:44:10 +01:00
|
|
|
|
|
|
|
|
int handle = fs->OpenFile(filename, FILEACCESS_READ);
|
2019-10-20 11:03:37 -07:00
|
|
|
if (handle < 0) {
|
2013-03-30 15:44:10 +01:00
|
|
|
return false;
|
2013-04-01 12:35:02 +02:00
|
|
|
}
|
2013-04-13 22:29:42 +02:00
|
|
|
if (mtx) {
|
2024-01-18 20:04:29 +01:00
|
|
|
std::string data;
|
|
|
|
|
data.resize(info.size);
|
2024-01-25 09:43:06 +01:00
|
|
|
size_t readSize = fs->ReadFile(handle, (u8 *)data.data(), info.size);
|
2024-01-18 20:04:29 +01:00
|
|
|
fs->CloseFile(handle);
|
2024-01-25 09:43:06 +01:00
|
|
|
if (readSize != info.size) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(*mtx);
|
2024-01-18 20:04:29 +01:00
|
|
|
*contents = std::move(data);
|
2013-04-13 22:29:42 +02:00
|
|
|
} else {
|
|
|
|
|
contents->resize(info.size);
|
2024-01-25 09:43:06 +01:00
|
|
|
size_t readSize = fs->ReadFile(handle, (u8 *)contents->data(), info.size);
|
2024-01-18 20:04:29 +01:00
|
|
|
fs->CloseFile(handle);
|
2024-01-25 09:43:06 +01:00
|
|
|
if (readSize != info.size) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-04-13 22:29:42 +02:00
|
|
|
}
|
2013-03-30 15:44:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 11:25:46 +01:00
|
|
|
static bool ReadLocalFileToString(const Path &path, std::string *contents, std::mutex *mtx) {
|
|
|
|
|
std::string data;
|
2024-01-25 09:55:54 +01:00
|
|
|
if (!File::ReadBinaryFileToString(path, &data)) {
|
2024-01-19 11:25:46 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (mtx) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(*mtx);
|
|
|
|
|
*contents = std::move(data);
|
|
|
|
|
} else {
|
|
|
|
|
*contents = std::move(data);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 21:57:46 +01:00
|
|
|
static bool ReadVFSToString(const char *filename, std::string *contents, std::mutex *mtx) {
|
2015-12-24 12:45:07 -08:00
|
|
|
size_t sz;
|
2023-03-06 14:23:56 +01:00
|
|
|
uint8_t *data = g_VFS.ReadFile(filename, &sz);
|
2015-12-24 12:45:07 -08:00
|
|
|
if (data) {
|
|
|
|
|
if (mtx) {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(*mtx);
|
2015-12-24 12:45:07 -08:00
|
|
|
*contents = std::string((const char *)data, sz);
|
|
|
|
|
} else {
|
|
|
|
|
*contents = std::string((const char *)data, sz);
|
|
|
|
|
}
|
2024-01-18 20:04:29 +01:00
|
|
|
} else {
|
|
|
|
|
return false;
|
2015-12-24 12:45:07 -08:00
|
|
|
}
|
|
|
|
|
delete [] data;
|
2024-01-18 20:04:29 +01:00
|
|
|
return true;
|
2015-12-24 12:45:07 -08:00
|
|
|
}
|
|
|
|
|
|
2020-11-30 16:46:52 +01:00
|
|
|
class GameInfoWorkItem : public Task {
|
2013-04-13 21:24:07 +02:00
|
|
|
public:
|
2024-01-28 16:23:27 +01:00
|
|
|
GameInfoWorkItem(const Path &gamePath, std::shared_ptr<GameInfo> &info, GameInfoFlags flags)
|
|
|
|
|
: gamePath_(gamePath), info_(info), flags_(flags) {}
|
2013-04-13 21:24:07 +02:00
|
|
|
|
2022-12-10 20:32:12 -08:00
|
|
|
~GameInfoWorkItem() {
|
2016-06-26 20:33:25 -07:00
|
|
|
info_->DisposeFileLoader();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 19:22:13 -08:00
|
|
|
TaskType Type() const override {
|
|
|
|
|
return TaskType::IO_BLOCKING;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 07:55:07 -08:00
|
|
|
TaskPriority Priority() const override {
|
|
|
|
|
switch (gamePath_.Type()) {
|
|
|
|
|
case PathType::NATIVE:
|
|
|
|
|
case PathType::CONTENT_URI:
|
|
|
|
|
return TaskPriority::NORMAL;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// Remote/network access.
|
|
|
|
|
return TaskPriority::LOW;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-30 16:46:52 +01:00
|
|
|
void Run() override {
|
2021-06-12 22:16:03 +02:00
|
|
|
// An early-return will result in the destructor running, where we can set
|
|
|
|
|
// flags like working and pending.
|
2024-03-26 15:10:06 +01:00
|
|
|
if (!info_->CreateLoader() || !info_->GetFileLoader() || !info_->GetFileLoader()->Exists()) {
|
|
|
|
|
// Mark everything requested as done, so
|
|
|
|
|
std::unique_lock<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->MarkReadyNoLock(flags_);
|
2024-05-14 00:02:59 +02:00
|
|
|
ERROR_LOG(LOADER, "Failed getting game info for %s", info_->GetFilePath().ToVisualString().c_str());
|
2021-06-12 22:16:03 +02:00
|
|
|
return;
|
2017-12-29 08:56:27 -08:00
|
|
|
}
|
2013-04-13 21:24:07 +02:00
|
|
|
|
2021-08-07 11:54:45 +02:00
|
|
|
std::string errorString;
|
|
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::FILE_TYPE) {
|
|
|
|
|
info_->fileType = Identify_File(info_->GetFileLoader().get(), &errorString);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-08 17:48:41 +02:00
|
|
|
switch (info_->fileType) {
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_PBP:
|
|
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
2013-06-08 17:48:41 +02:00
|
|
|
{
|
2017-12-09 17:26:26 -08:00
|
|
|
auto pbpLoader = info_->GetFileLoader();
|
2017-03-02 12:29:03 +01:00
|
|
|
if (info_->fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
|
2021-05-09 18:38:48 +02:00
|
|
|
Path ebootPath = ResolvePBPFile(gamePath_);
|
2016-06-26 20:33:25 -07:00
|
|
|
if (ebootPath != gamePath_) {
|
2021-05-09 18:38:48 +02:00
|
|
|
pbpLoader.reset(ConstructFileLoader(ebootPath));
|
2016-06-26 20:33:25 -07:00
|
|
|
}
|
2015-12-24 10:40:25 -08:00
|
|
|
}
|
2013-06-08 17:48:41 +02:00
|
|
|
|
2017-12-09 17:26:26 -08:00
|
|
|
PBPReader pbp(pbpLoader.get());
|
2013-12-11 14:22:25 +01:00
|
|
|
if (!pbp.IsValid()) {
|
|
|
|
|
if (pbp.IsELF()) {
|
|
|
|
|
goto handleELF;
|
|
|
|
|
}
|
2020-11-30 16:46:52 +01:00
|
|
|
ERROR_LOG(LOADER, "invalid pbp '%s'\n", pbpLoader->GetPath().c_str());
|
2021-06-12 22:16:03 +02:00
|
|
|
return;
|
2013-12-11 14:22:25 +01:00
|
|
|
}
|
2013-06-08 17:48:41 +02:00
|
|
|
|
|
|
|
|
// First, PARAM.SFO.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
|
|
|
|
std::vector<u8> sfoData;
|
|
|
|
|
if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->paramSFO.ReadSFO(sfoData);
|
|
|
|
|
info_->ParseParamSFO();
|
2017-05-26 23:15:04 +02:00
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
// Assuming PSP_PBP_DIRECTORY without ID or with disc_total < 1 in GAME dir must be homebrew
|
|
|
|
|
if ((info_->id.empty() || !info_->disc_total)
|
|
|
|
|
&& gamePath_.FilePathContainsNoCase("PSP/GAME/")
|
|
|
|
|
&& info_->fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
|
|
|
|
|
info_->id = g_paramSFO.GenerateFakeID(gamePath_);
|
|
|
|
|
info_->id_version = info_->id + "_1.00";
|
|
|
|
|
info_->region = GAMEREGION_MAX + 1; // Homebrew
|
|
|
|
|
}
|
2024-01-30 12:26:23 +01:00
|
|
|
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
|
2017-05-26 23:15:04 +02:00
|
|
|
}
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then, ICON0.PNG.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->icon.data);
|
|
|
|
|
} else {
|
|
|
|
|
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.jpg");
|
|
|
|
|
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
|
|
|
|
|
// Try using png/jpg screenshots first
|
|
|
|
|
if (File::Exists(screenshot_png))
|
|
|
|
|
ReadLocalFileToString(screenshot_png, &info_->icon.data, &info_->lock);
|
|
|
|
|
else if (File::Exists(screenshot_jpg))
|
|
|
|
|
ReadLocalFileToString(screenshot_jpg, &info_->icon.data, &info_->lock);
|
|
|
|
|
else
|
|
|
|
|
// Read standard icon
|
|
|
|
|
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
}
|
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::BG) {
|
2014-06-21 18:29:54 -07:00
|
|
|
if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) {
|
2024-01-18 22:52:56 +01:00
|
|
|
std::string data;
|
|
|
|
|
pbp.GetSubFileAsString(PBP_PIC0_PNG, &data);
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2024-01-18 22:52:56 +01:00
|
|
|
info_->pic0.data = std::move(data);
|
2017-03-26 00:00:57 -07:00
|
|
|
info_->pic0.dataLoaded = true;
|
2014-06-21 18:29:54 -07:00
|
|
|
}
|
2013-06-22 23:25:22 +02:00
|
|
|
if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
|
2024-01-18 22:52:56 +01:00
|
|
|
std::string data;
|
|
|
|
|
pbp.GetSubFileAsString(PBP_PIC1_PNG, &data);
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2024-01-18 22:52:56 +01:00
|
|
|
info_->pic1.data = std::move(data);
|
2017-03-26 00:00:57 -07:00
|
|
|
info_->pic1.dataLoaded = true;
|
2013-06-08 17:48:41 +02:00
|
|
|
}
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::SND) {
|
2014-06-21 18:38:26 -07:00
|
|
|
if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) {
|
2024-01-18 22:52:56 +01:00
|
|
|
std::string data;
|
|
|
|
|
pbp.GetSubFileAsString(PBP_SND0_AT3, &data);
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2024-01-18 22:52:56 +01:00
|
|
|
info_->sndFileData = std::move(data);
|
2014-06-21 18:38:26 -07:00
|
|
|
info_->sndDataLoaded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
2013-07-15 18:57:42 +02:00
|
|
|
break;
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_ELF:
|
2013-12-11 14:22:25 +01:00
|
|
|
handleELF:
|
2013-06-08 17:48:41 +02:00
|
|
|
// An elf on its own has no usable information, no icons, no nothing.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
2024-01-22 23:46:28 +01:00
|
|
|
info_->id = g_paramSFO.GenerateFakeID(gamePath_);
|
2017-05-26 23:15:04 +02:00
|
|
|
info_->id_version = info_->id + "_1.00";
|
|
|
|
|
info_->region = GAMEREGION_MAX + 1; // Homebrew
|
2015-12-24 12:37:29 -08:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
|
|
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
std::string id = g_paramSFO.GenerateFakeID(gamePath_);
|
|
|
|
|
// Due to the dependency of the BASIC info, we fetch it already here.
|
|
|
|
|
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (id + "_00000.jpg");
|
|
|
|
|
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (id + "_00000.png");
|
2017-05-27 20:49:40 +02:00
|
|
|
// Try using png/jpg screenshots first
|
2018-02-26 09:26:07 +01:00
|
|
|
if (File::Exists(screenshot_png)) {
|
2024-01-19 11:25:46 +01:00
|
|
|
ReadLocalFileToString(screenshot_png, &info_->icon.data, &info_->lock);
|
2018-02-26 09:26:07 +01:00
|
|
|
} else if (File::Exists(screenshot_jpg)) {
|
2024-01-19 11:25:46 +01:00
|
|
|
ReadLocalFileToString(screenshot_jpg, &info_->icon.data, &info_->lock);
|
2018-02-26 09:26:07 +01:00
|
|
|
} else {
|
2017-05-27 20:49:40 +02:00
|
|
|
// Read standard icon
|
2018-02-26 09:26:07 +01:00
|
|
|
VERBOSE_LOG(LOADER, "Loading unknown.png because there was an ELF");
|
2017-05-27 20:49:40 +02:00
|
|
|
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
}
|
|
|
|
|
info_->icon.dataLoaded = true;
|
|
|
|
|
}
|
2013-07-15 18:57:42 +02:00
|
|
|
break;
|
2013-06-08 17:48:41 +02:00
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2015-06-11 20:22:16 +02:00
|
|
|
{
|
|
|
|
|
SequentialHandleAllocator handles;
|
2021-05-09 18:38:48 +02:00
|
|
|
VirtualDiscFileSystem umd(&handles, gamePath_);
|
2015-06-11 20:22:16 +02:00
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
|
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
|
|
|
|
std::string paramSFOcontents;
|
|
|
|
|
if (ReadFileToString(&umd, "/PARAM.SFO", ¶mSFOcontents, 0)) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
|
|
|
|
info_->ParseParamSFO();
|
2024-01-30 12:26:23 +01:00
|
|
|
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
|
2024-01-28 16:23:27 +01:00
|
|
|
}
|
2015-06-11 20:22:16 +02:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
ReadFileToString(&umd, "/ICON0.PNG", &info_->icon.data, &info_->lock);
|
|
|
|
|
info_->icon.dataLoaded = true;
|
|
|
|
|
}
|
|
|
|
|
if (flags_ & GameInfoFlags::BG) {
|
2017-03-26 00:00:57 -07:00
|
|
|
ReadFileToString(&umd, "/PIC1.PNG", &info_->pic1.data, &info_->lock);
|
|
|
|
|
info_->pic1.dataLoaded = true;
|
2015-06-11 20:22:16 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PPSSPP_SAVESTATE:
|
2015-06-11 23:59:02 +02:00
|
|
|
{
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
2024-01-19 11:25:46 +01:00
|
|
|
info_->SetTitle(SaveState::GetTitle(gamePath_));
|
2024-01-30 12:26:23 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
|
2024-01-19 11:25:46 +01:00
|
|
|
}
|
2016-01-23 13:06:58 -08:00
|
|
|
|
2016-01-23 11:27:41 -08:00
|
|
|
// Let's use the screenshot as an icon, too.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
Path screenshotPath = gamePath_.WithReplacedExtension(".ppst", ".jpg");
|
|
|
|
|
if (ReadLocalFileToString(screenshotPath, &info_->icon.data, &info_->lock)) {
|
|
|
|
|
info_->icon.dataLoaded = true;
|
|
|
|
|
} else {
|
|
|
|
|
ERROR_LOG(G3D, "Error loading screenshot data: '%s'", screenshotPath.c_str());
|
|
|
|
|
}
|
2022-01-08 16:12:48 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case IdentifiedFileType::PPSSPP_GE_DUMP:
|
|
|
|
|
{
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
Path screenshotPath = gamePath_.WithReplacedExtension(".ppdmp", ".png");
|
|
|
|
|
// Let's use the comparison screenshot as an icon, if it exists.
|
|
|
|
|
if (ReadLocalFileToString(screenshotPath, &info_->icon.data, &info_->lock)) {
|
|
|
|
|
info_->icon.dataLoaded = true;
|
|
|
|
|
}
|
2016-01-23 11:27:41 -08:00
|
|
|
}
|
2015-06-11 23:59:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
2013-07-23 17:35:43 +02:00
|
|
|
{
|
|
|
|
|
SequentialHandleAllocator handles;
|
2021-05-09 18:38:48 +02:00
|
|
|
VirtualDiscFileSystem umd(&handles, gamePath_);
|
2013-12-06 11:44:46 +01:00
|
|
|
|
2013-07-23 17:35:43 +02:00
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
|
|
|
|
std::string paramSFOcontents;
|
2024-01-31 10:22:03 +01:00
|
|
|
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, nullptr)) {
|
2024-01-28 16:23:27 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
|
|
|
|
info_->ParseParamSFO();
|
|
|
|
|
}
|
2013-07-23 17:35:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 12:26:23 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock);
|
|
|
|
|
info_->icon.dataLoaded = true;
|
|
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::BG) {
|
2017-03-26 00:00:57 -07: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 17:35:43 +02:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::SND) {
|
2014-06-21 18:38:26 -07:00
|
|
|
ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
|
2017-03-26 00:00:57 -07:00
|
|
|
info_->pic1.dataLoaded = true;
|
2014-06-21 18:38:26 -07:00
|
|
|
}
|
2013-07-23 17:35:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-06-11 23:59:02 +02:00
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
2013-06-23 16:24:45 +02: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-12-09 17:26:26 -08:00
|
|
|
auto fl = info_->GetFileLoader();
|
2017-12-29 08:55:49 -08:00
|
|
|
if (!fl) {
|
2021-06-12 22:16:03 +02:00
|
|
|
return;
|
2017-12-29 08:55:49 -08:00
|
|
|
}
|
2017-12-09 17:26:26 -08:00
|
|
|
BlockDevice *bd = constructBlockDevice(info_->GetFileLoader().get());
|
2017-12-29 08:55:49 -08:00
|
|
|
if (!bd) {
|
2021-06-12 22:16:03 +02:00
|
|
|
return;
|
2017-12-29 08:55:49 -08:00
|
|
|
}
|
2016-02-29 01:13:57 +01:00
|
|
|
ISOFileSystem umd(&handles, bd);
|
2013-04-13 21:24:07 +02:00
|
|
|
|
2013-06-23 16:24:45 +02:00
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
|
|
|
|
std::string paramSFOcontents;
|
|
|
|
|
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, nullptr)) {
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
|
|
|
|
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
|
|
|
|
|
info_->ParseParamSFO();
|
2024-01-30 12:26:23 +01:00
|
|
|
|
|
|
|
|
// quick-update the info while we have the lock, so we don't need to wait for the image load to display the title.
|
|
|
|
|
info_->MarkReadyNoLock(GameInfoFlags::PARAM_SFO);
|
2024-01-28 16:23:27 +01:00
|
|
|
}
|
2014-06-21 18:38:26 -07:00
|
|
|
}
|
2014-03-06 08:16:19 -05:00
|
|
|
}
|
|
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::BG) {
|
|
|
|
|
info_->pic0.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, &info_->lock);
|
|
|
|
|
info_->pic1.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1.data, &info_->lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags_ & GameInfoFlags::SND) {
|
|
|
|
|
info_->sndDataLoaded = ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-06 08:16:19 -05:00
|
|
|
// Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
|
|
|
|
if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->icon.data, &info_->lock)) {
|
|
|
|
|
Path screenshot_jpg = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.jpg");
|
|
|
|
|
Path screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) / (info_->id + "_00000.png");
|
|
|
|
|
// Try using png/jpg screenshots first
|
|
|
|
|
if (File::Exists(screenshot_png))
|
|
|
|
|
info_->icon.dataLoaded = ReadLocalFileToString(screenshot_png, &info_->icon.data, &info_->lock);
|
|
|
|
|
else if (File::Exists(screenshot_jpg))
|
|
|
|
|
info_->icon.dataLoaded = ReadLocalFileToString(screenshot_jpg, &info_->icon.data, &info_->lock);
|
|
|
|
|
else {
|
|
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
|
|
|
|
|
info_->icon.dataLoaded = ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
info_->icon.dataLoaded = true;
|
2017-05-27 20:49:40 +02:00
|
|
|
}
|
2013-06-23 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
2013-12-06 11:44:46 +01:00
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::ARCHIVE_ZIP:
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
2017-03-26 00:00:57 -07:00
|
|
|
ReadVFSToString("zip.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-12-11 15:11:27 +01:00
|
|
|
}
|
2013-08-20 16:52:36 +02:00
|
|
|
break;
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::ARCHIVE_RAR:
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
2017-03-26 00:00:57 -07:00
|
|
|
ReadVFSToString("rargray.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
info_->icon.dataLoaded = true;
|
2013-12-11 15:24:29 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::ARCHIVE_7Z:
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::ICON) {
|
2017-03-26 00:00:57 -07:00
|
|
|
ReadVFSToString("7z.png", &info_->icon.data, &info_->lock);
|
|
|
|
|
info_->icon.dataLoaded = true;
|
2014-10-21 00:09:24 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::NORMAL_DIRECTORY:
|
2013-08-20 16:52:36 +02:00
|
|
|
default:
|
2013-12-11 15:11:27 +01:00
|
|
|
break;
|
2013-06-09 11:54:03 +02:00
|
|
|
}
|
2014-06-21 18:24:21 -07:00
|
|
|
|
2024-01-29 18:59:15 +01:00
|
|
|
if (flags_ & GameInfoFlags::PARAM_SFO) {
|
|
|
|
|
// We fetch the hasConfig together with the params, since that's what fills out the id.
|
|
|
|
|
info_->hasConfig = g_Config.hasGameConfig(info_->id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::SIZE) {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(info_->lock);
|
2023-10-22 11:10:42 -06:00
|
|
|
info_->gameSizeOnDisk = info_->GetGameSizeOnDiskInBytes();
|
2013-06-09 11:54:03 +02:00
|
|
|
info_->saveDataSize = info_->GetSaveDataSizeInBytes();
|
2013-10-03 20:44:16 +08:00
|
|
|
info_->installDataSize = info_->GetInstallDataSizeInBytes();
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
if (flags_ & GameInfoFlags::UNCOMPRESSED_SIZE) {
|
2023-10-22 11:10:42 -06:00
|
|
|
info_->gameSizeUncompressed = info_->GetGameSizeUncompressedInBytes();
|
|
|
|
|
}
|
2016-03-06 13:52:16 -08:00
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
// Time to update the flags.
|
|
|
|
|
std::unique_lock<std::mutex> lock(info_->lock);
|
2024-01-30 12:26:23 +01:00
|
|
|
info_->MarkReadyNoLock(flags_);
|
2020-08-15 12:25:39 +02:00
|
|
|
// INFO_LOG(SYSTEM, "Completed writing info for %s", info_->GetTitle().c_str());
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2021-05-06 01:31:38 +02:00
|
|
|
Path gamePath_;
|
2017-05-18 12:52:03 +02:00
|
|
|
std::shared_ptr<GameInfo> info_;
|
2024-01-28 16:23:27 +01:00
|
|
|
GameInfoFlags flags_{};
|
|
|
|
|
|
2013-04-13 21:24:07 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(GameInfoWorkItem);
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-30 16:46:52 +01:00
|
|
|
GameInfoCache::GameInfoCache() {
|
2016-02-14 22:07:10 +01:00
|
|
|
Init();
|
|
|
|
|
}
|
2013-04-13 21:24:07 +02:00
|
|
|
|
|
|
|
|
GameInfoCache::~GameInfoCache() {
|
2013-04-14 11:58:28 +02:00
|
|
|
Clear();
|
2016-02-14 22:07:10 +01:00
|
|
|
Shutdown();
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-30 16:46:52 +01:00
|
|
|
void GameInfoCache::Init() {}
|
2013-04-13 21:24:07 +02:00
|
|
|
|
|
|
|
|
void GameInfoCache::Shutdown() {
|
2017-12-09 16:48:38 -08:00
|
|
|
CancelAll();
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
2013-04-14 11:58:28 +02:00
|
|
|
void GameInfoCache::Clear() {
|
2017-12-09 16:48:38 -08:00
|
|
|
CancelAll();
|
|
|
|
|
|
2024-01-29 00:08:03 +01:00
|
|
|
std::lock_guard<std::mutex> lock(mapLock_);
|
2013-04-14 13:01:01 +02:00
|
|
|
info_.clear();
|
2013-04-14 11:58:28 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-09 16:48:38 -08:00
|
|
|
void GameInfoCache::CancelAll() {
|
2024-01-29 00:08:03 +01:00
|
|
|
std::lock_guard<std::mutex> lock(mapLock_);
|
2017-12-09 16:48:38 -08:00
|
|
|
for (auto info : info_) {
|
2022-04-12 00:15:52 +02:00
|
|
|
// GetFileLoader will create one if there isn't one already.
|
|
|
|
|
// Avoid that by checking.
|
|
|
|
|
if (info.second->HasFileLoader()) {
|
|
|
|
|
auto fl = info.second->GetFileLoader();
|
|
|
|
|
if (fl) {
|
|
|
|
|
fl->Cancel();
|
|
|
|
|
}
|
2017-12-09 16:48:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 12:35:02 +02:00
|
|
|
void GameInfoCache::FlushBGs() {
|
2024-01-29 00:08:03 +01:00
|
|
|
std::lock_guard<std::mutex> lock(mapLock_);
|
2013-04-01 12:35:02 +02:00
|
|
|
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
|
2017-02-27 21:57:46 +01:00
|
|
|
std::lock_guard<std::mutex> lock(iter->second->lock);
|
2017-03-26 00:00:57 -07:00
|
|
|
iter->second->pic0.Clear();
|
|
|
|
|
iter->second->pic1.Clear();
|
2014-06-22 09:56:27 +02:00
|
|
|
if (!iter->second->sndFileData.empty()) {
|
|
|
|
|
iter->second->sndFileData.clear();
|
|
|
|
|
iter->second->sndDataLoaded = false;
|
|
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
iter->second->hasFlags &= ~(GameInfoFlags::BG | GameInfoFlags::SND);
|
2013-04-01 12:35:02 +02:00
|
|
|
}
|
2013-03-30 15:44:10 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 14:46:34 +02:00
|
|
|
void GameInfoCache::PurgeType(IdentifiedFileType fileType) {
|
2024-01-29 00:08:03 +01:00
|
|
|
bool retry = false;
|
2024-01-30 12:26:23 +01:00
|
|
|
int retryCount = 10;
|
2024-01-29 00:08:03 +01:00
|
|
|
// Trickery to avoid sleeping with the lock held.
|
|
|
|
|
do {
|
2024-01-30 12:26:23 +01:00
|
|
|
if (retry) {
|
|
|
|
|
retryCount--;
|
|
|
|
|
if (retryCount == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
retry = false;
|
2024-01-29 00:08:03 +01:00
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(mapLock_);
|
|
|
|
|
for (auto iter = info_.begin(); iter != info_.end();) {
|
|
|
|
|
auto &info = iter->second;
|
2024-01-30 12:26:23 +01:00
|
|
|
if (!(info->hasFlags & GameInfoFlags::FILE_TYPE)) {
|
|
|
|
|
iter++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (info->fileType != fileType) {
|
|
|
|
|
iter++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-01-29 00:08:03 +01:00
|
|
|
// TODO: Find a better way to wait here.
|
2024-01-30 12:26:23 +01:00
|
|
|
if (info->pendingFlags != (GameInfoFlags)0) {
|
2024-01-30 18:11:22 +01:00
|
|
|
INFO_LOG(LOADER, "%s: pending flags %08x, retrying", info->GetTitle().c_str(), (int)info->pendingFlags);
|
2024-01-29 00:08:03 +01:00
|
|
|
retry = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-01-30 12:26:23 +01:00
|
|
|
iter = info_.erase(iter);
|
2024-01-29 00:08:03 +01:00
|
|
|
}
|
2024-01-28 16:23:27 +01:00
|
|
|
}
|
2024-01-30 12:26:23 +01:00
|
|
|
|
|
|
|
|
sleep_ms(10);
|
2024-01-29 00:08:03 +01:00
|
|
|
} while (retry);
|
2015-06-12 14:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
// Call on the main thread ONLY - that is from stuff called from NativeFrame.
|
2023-12-12 22:24:13 +01:00
|
|
|
// Can also be called from the audio thread for menu background music, but that cannot request images!
|
2024-01-28 16:23:27 +01:00
|
|
|
std::shared_ptr<GameInfo> GameInfoCache::GetInfo(Draw::DrawContext *draw, const Path &gamePath, GameInfoFlags wantFlags) {
|
2023-12-04 13:22:32 +01:00
|
|
|
const std::string &pathStr = gamePath.ToString();
|
2021-05-06 01:31:38 +02:00
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
// This is always needed to determine the method to get the other info, so make sure it's computed first.
|
|
|
|
|
wantFlags |= GameInfoFlags::FILE_TYPE;
|
|
|
|
|
|
|
|
|
|
mapLock_.lock();
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
auto iter = info_.find(pathStr);
|
2013-03-30 15:44:10 +01:00
|
|
|
if (iter != info_.end()) {
|
2024-01-28 16:23:27 +01:00
|
|
|
// There's already a structure about this game. Let's check.
|
|
|
|
|
std::shared_ptr<GameInfo> info = iter->second;
|
|
|
|
|
mapLock_.unlock();
|
2013-03-30 15:44:10 +01:00
|
|
|
|
2024-01-28 14:50:16 +01:00
|
|
|
info->FinishPendingTextureLoads(draw);
|
2017-03-26 00:00:57 -07:00
|
|
|
info->lastAccessedTime = time_now_d();
|
2024-01-28 16:23:27 +01:00
|
|
|
GameInfoFlags wanted = (GameInfoFlags)0;
|
|
|
|
|
{
|
|
|
|
|
// Careful now!
|
|
|
|
|
std::unique_lock<std::mutex> lock(info->lock);
|
|
|
|
|
GameInfoFlags hasFlags = info->hasFlags | info->pendingFlags; // We don't want to re-fetch data that we have, so or in pendingFlags.
|
|
|
|
|
wanted = (GameInfoFlags)((int)wantFlags & ~(int)hasFlags); // & is reserved for testing. ugh.
|
|
|
|
|
info->pendingFlags |= wanted;
|
|
|
|
|
}
|
|
|
|
|
if (wanted != (GameInfoFlags)0) {
|
|
|
|
|
// We're missing info that we want. Go get it!
|
|
|
|
|
GameInfoWorkItem *item = new GameInfoWorkItem(gamePath, info, wanted);
|
|
|
|
|
g_threadManager.EnqueueTask(item);
|
|
|
|
|
}
|
2017-03-26 00:00:57 -07:00
|
|
|
return info;
|
|
|
|
|
}
|
2013-03-31 01:04:46 +01:00
|
|
|
|
2024-01-30 12:26:23 +01:00
|
|
|
std::shared_ptr<GameInfo> info = std::make_shared<GameInfo>(gamePath);
|
2024-01-28 16:23:27 +01:00
|
|
|
info->pendingFlags = wantFlags;
|
|
|
|
|
info->lastAccessedTime = time_now_d();
|
|
|
|
|
info_.insert(std::make_pair(pathStr, info));
|
|
|
|
|
mapLock_.unlock();
|
2016-03-06 14:00:09 -08:00
|
|
|
|
2024-01-28 16:23:27 +01:00
|
|
|
// Just get all the stuff we wanted.
|
|
|
|
|
GameInfoWorkItem *item = new GameInfoWorkItem(gamePath, info, wantFlags);
|
2021-12-05 19:22:13 -08:00
|
|
|
g_threadManager.EnqueueTask(item);
|
2013-04-13 21:24:07 +02:00
|
|
|
return info;
|
2013-03-30 15:44:10 +01:00
|
|
|
}
|