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/.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
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"
|
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"
|
2013-06-09 10:41:12 +00:00
|
|
|
#include "Core/System.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"
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-03-30 18:23:20 +00:00
|
|
|
GameInfoCache g_gameInfoCache;
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
bool GameInfo::DeleteGame() {
|
|
|
|
switch (fileType) {
|
|
|
|
case FILETYPE_PSP_ISO:
|
|
|
|
case FILETYPE_PSP_ISO_NP:
|
2013-09-30 19:11:42 +00:00
|
|
|
{
|
|
|
|
// Just delete the one file (TODO: handle two-disk games as well somehow).
|
|
|
|
const char *fileToRemove = fileInfo.fullName.c_str();
|
|
|
|
deleteFile(fileToRemove);
|
|
|
|
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;
|
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
case FILETYPE_PSP_PBP_DIRECTORY:
|
2013-11-29 11:34:10 +00:00
|
|
|
{
|
|
|
|
// TODO: This could be handled by Core/Util/GameManager too somehow.
|
|
|
|
|
|
|
|
const char *directoryToRemove = fileInfo.fullName.c_str();
|
|
|
|
INFO_LOG(HLE, "Deleting %s", directoryToRemove);
|
|
|
|
if (!File::DeleteDirRecursively(directoryToRemove)) {
|
|
|
|
ERROR_LOG(HLE, "Failed to delete file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
g_Config.CleanRecent();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-11 14:11:27 +00:00
|
|
|
case FILETYPE_PSP_ELF:
|
|
|
|
{
|
|
|
|
const char *fileToRemove = fileInfo.fullName.c_str();
|
|
|
|
deleteFile(fileToRemove);
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 GameInfo::GetGameSizeInBytes() {
|
|
|
|
switch (fileType) {
|
|
|
|
case FILETYPE_PSP_PBP_DIRECTORY:
|
|
|
|
// TODO: Need to recurse here.
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return fileInfo.size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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() {
|
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) {
|
|
|
|
//Generally the savedata size in a dir shouldn't be more than 10MB.
|
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
}
|
|
|
|
filesSizeInDir = 0;
|
|
|
|
}
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 GameInfo::GetInstallDataSizeInBytes() {
|
|
|
|
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) {
|
|
|
|
// Generally the savedata size in a dir shouldn't be more than 10MB.
|
|
|
|
// This is probably GameInstall data.
|
|
|
|
totalSize += filesSizeInDir;
|
|
|
|
}
|
|
|
|
filesSizeInDir = 0;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
deleteFile(fileInfo[i].fullName.c_str());
|
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-06-09 10:41:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-13 20:29:42 +00:00
|
|
|
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, recursive_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) {
|
|
|
|
lock_guard lock(*mtx);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
|
|
|
|
class GameInfoWorkItem : public PrioritizedWorkQueueItem {
|
|
|
|
public:
|
|
|
|
GameInfoWorkItem(const std::string &gamePath, GameInfo *info)
|
|
|
|
: gamePath_(gamePath), info_(info) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void run() {
|
2013-06-08 15:48:41 +00:00
|
|
|
getFileInfo(gamePath_.c_str(), &info_->fileInfo);
|
|
|
|
if (!info_->fileInfo.exists)
|
2013-04-13 19:24:07 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
std::string filename = gamePath_;
|
2013-12-11 13:22:25 +00:00
|
|
|
info_->path = gamePath_;
|
2013-06-08 15:48:41 +00:00
|
|
|
info_->fileType = Identify_File(filename);
|
2013-12-11 13:22:25 +00:00
|
|
|
// Fallback title
|
|
|
|
info_->title = getFilename(info_->path);
|
2013-06-08 15:48:41 +00:00
|
|
|
|
|
|
|
switch (info_->fileType) {
|
|
|
|
case FILETYPE_PSP_PBP:
|
|
|
|
case FILETYPE_PSP_PBP_DIRECTORY:
|
2013-04-13 19:24:07 +00:00
|
|
|
{
|
2013-06-08 15:48:41 +00:00
|
|
|
std::string pbpFile = filename;
|
|
|
|
if (info_->fileType == FILETYPE_PSP_PBP_DIRECTORY)
|
|
|
|
pbpFile += "/EBOOT.PBP";
|
|
|
|
|
|
|
|
PBPReader pbp(pbpFile.c_str());
|
2013-12-11 13:22:25 +00:00
|
|
|
if (!pbp.IsValid()) {
|
|
|
|
if (pbp.IsELF()) {
|
|
|
|
goto handleELF;
|
|
|
|
}
|
|
|
|
ERROR_LOG(LOADER, "invalid pbp %s\n", pbpFile.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.
|
|
|
|
size_t sfoSize;
|
|
|
|
u8 *sfoData = pbp.GetSubFile(PBP_PARAM_SFO, &sfoSize);
|
|
|
|
{
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->paramSFO.ReadSFO(sfoData, sfoSize);
|
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
|
|
|
delete [] sfoData;
|
2013-04-13 19:24:07 +00:00
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
// Then, ICON0.PNG.
|
2013-04-13 19:24:07 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(info_->lock);
|
2013-06-08 15:48:41 +00:00
|
|
|
if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
|
|
|
|
pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData);
|
|
|
|
} else {
|
2013-06-22 21:25:22 +00:00
|
|
|
// Read standard icon
|
|
|
|
size_t sz;
|
2013-11-23 00:51:35 +00:00
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because a PBP was missing an icon");
|
2013-06-23 14:24:45 +00:00
|
|
|
uint8_t *contents = VFSReadFile("unknown.png", &sz);
|
|
|
|
if (contents) {
|
2013-06-22 21:25:22 +00:00
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->iconTextureData = std::string((const char *)contents, sz);
|
|
|
|
}
|
|
|
|
delete [] contents;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info_->wantBG) {
|
2013-06-22 21:25:22 +00:00
|
|
|
if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
|
2013-06-08 15:48:41 +00:00
|
|
|
lock_guard lock(info_->lock);
|
2013-06-22 21:25:22 +00:00
|
|
|
pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData);
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-15 16:57:42 +00:00
|
|
|
break;
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
case FILETYPE_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.
|
2013-06-09 11:41:15 +00:00
|
|
|
info_->title = getFilename(filename);
|
|
|
|
info_->id = "ELF000000";
|
|
|
|
info_->id_version = "ELF000000_1.00";
|
|
|
|
info_->paramSFOLoaded = true;
|
2013-06-22 21:25:22 +00:00
|
|
|
{
|
|
|
|
// Read standard icon
|
|
|
|
size_t sz;
|
2013-06-23 15:57:24 +00:00
|
|
|
uint8_t *contents = VFSReadFile("unknown.png", &sz);
|
2013-11-23 00:51:35 +00:00
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because there was an ELF");
|
2013-06-23 15:57:24 +00:00
|
|
|
if (contents) {
|
2013-06-22 21:25:22 +00:00
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->iconTextureData = std::string((const char *)contents, sz);
|
|
|
|
}
|
|
|
|
delete [] contents;
|
|
|
|
}
|
2013-07-15 16:57:42 +00:00
|
|
|
break;
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-07-23 15:35:43 +00:00
|
|
|
case FILETYPE_PSP_DISC_DIRECTORY:
|
|
|
|
{
|
|
|
|
info_->fileType = FILETYPE_PSP_ISO;
|
|
|
|
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)) {
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock);
|
|
|
|
if (info_->wantBG) {
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock);
|
|
|
|
}
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
case FILETYPE_PSP_ISO:
|
|
|
|
case FILETYPE_PSP_ISO_NP:
|
2013-06-23 14:24:45 +00:00
|
|
|
{
|
|
|
|
info_->fileType = FILETYPE_PSP_ISO;
|
|
|
|
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.
|
|
|
|
BlockDevice *bd = constructBlockDevice(gamePath_.c_str());
|
|
|
|
if (!bd)
|
|
|
|
return; // nothing to do here..
|
|
|
|
ISOFileSystem umd(&handles, bd, "/PSP_GAME");
|
|
|
|
|
|
|
|
// Alright, let's fetch the PARAM.SFO.
|
|
|
|
std::string paramSFOcontents;
|
|
|
|
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) {
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
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
|
|
|
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock);
|
|
|
|
if (info_->wantBG) {
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock);
|
|
|
|
}
|
|
|
|
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
|
2013-08-16 10:52:16 +00:00
|
|
|
} else {
|
|
|
|
// Fall back to the filename for title if ISO is broken
|
|
|
|
info_->title = gamePath_;
|
2013-12-11 14:29:41 +00:00
|
|
|
// Fall back to unknown icon if ISO is broken, override is allowed though
|
|
|
|
size_t sz;
|
|
|
|
uint8_t *contents = VFSReadFile("unknown.png", &sz);
|
|
|
|
DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
|
|
|
|
if (contents) {
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->iconTextureData = std::string((const char *)contents, sz);
|
|
|
|
}
|
|
|
|
delete [] contents;
|
2013-06-23 14:24:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-12-06 10:44:46 +00:00
|
|
|
|
2013-12-11 14:11:27 +00:00
|
|
|
case FILETYPE_ARCHIVE_ZIP:
|
|
|
|
info_->title = getFilename(filename);
|
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
info_->wantBG = false;
|
|
|
|
{
|
|
|
|
// Read standard icon
|
|
|
|
size_t sz;
|
|
|
|
uint8_t *contents = VFSReadFile("zip.png", &sz);
|
|
|
|
if (contents) {
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->iconTextureData = std::string((const char *)contents, sz);
|
|
|
|
}
|
|
|
|
delete [] contents;
|
|
|
|
}
|
2013-08-20 14:52:36 +00:00
|
|
|
break;
|
|
|
|
|
2013-12-11 14:11:27 +00:00
|
|
|
case FILETYPE_ARCHIVE_RAR:
|
2013-12-11 14:24:29 +00:00
|
|
|
info_->title = getFilename(filename);
|
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
info_->wantBG = false;
|
|
|
|
{
|
|
|
|
// Read standard icon
|
|
|
|
size_t sz;
|
|
|
|
uint8_t *contents = VFSReadFile("rargray.png", &sz);
|
|
|
|
if (contents) {
|
|
|
|
lock_guard lock(info_->lock);
|
|
|
|
info_->iconTextureData = std::string((const char *)contents, sz);
|
|
|
|
}
|
|
|
|
delete [] contents;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-12-11 14:11:27 +00:00
|
|
|
case FILETYPE_NORMAL_DIRECTORY:
|
2013-08-20 14:52:36 +00:00
|
|
|
default:
|
2013-12-11 14:11:27 +00:00
|
|
|
info_->title = getFilename(gamePath_);
|
|
|
|
info_->paramSFOLoaded = true;
|
|
|
|
info_->wantBG = false;
|
|
|
|
break;
|
2013-06-09 09:54:03 +00:00
|
|
|
}
|
|
|
|
// probably only want these when we ask for the background image...
|
|
|
|
// should maybe flip the flag to "onlyIcon"
|
|
|
|
if (info_->wantBG) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual float priority() {
|
|
|
|
return info_->lastAccessedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string gamePath_;
|
|
|
|
GameInfo *info_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(GameInfoWorkItem);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GameInfoCache::~GameInfoCache() {
|
2013-04-14 09:58:28 +00:00
|
|
|
Clear();
|
2013-04-13 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfoCache::Init() {
|
|
|
|
gameInfoWQ_ = new PrioritizedWorkQueue();
|
|
|
|
ProcessWorkQueueOnThreadWhile(gameInfoWQ_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameInfoCache::Shutdown() {
|
|
|
|
StopProcessingWorkQueue(gameInfoWQ_);
|
|
|
|
}
|
|
|
|
|
2013-03-30 14:44:10 +00:00
|
|
|
void GameInfoCache::Save()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:02 +00:00
|
|
|
void GameInfoCache::Load() {
|
2013-03-30 14:44:10 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2013-04-01 10:35:02 +00:00
|
|
|
void GameInfoCache::Decimate() {
|
2013-03-30 14:44:10 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2013-04-14 09:58:28 +00:00
|
|
|
void GameInfoCache::Clear() {
|
2013-07-11 05:27:24 +00:00
|
|
|
if (gameInfoWQ_)
|
|
|
|
gameInfoWQ_->Flush();
|
2013-04-14 09:58:28 +00:00
|
|
|
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
|
|
|
|
lock_guard lock(iter->second->lock);
|
|
|
|
if (!iter->second->pic0TextureData.empty()) {
|
|
|
|
iter->second->pic0TextureData.clear();
|
|
|
|
}
|
|
|
|
if (iter->second->pic0Texture) {
|
|
|
|
delete iter->second->pic0Texture;
|
|
|
|
iter->second->pic0Texture = 0;
|
|
|
|
}
|
|
|
|
if (!iter->second->pic1TextureData.empty()) {
|
|
|
|
iter->second->pic1TextureData.clear();
|
|
|
|
}
|
|
|
|
if (iter->second->pic1Texture) {
|
|
|
|
delete iter->second->pic1Texture;
|
|
|
|
iter->second->pic1Texture = 0;
|
|
|
|
}
|
2013-12-09 14:28:47 +00:00
|
|
|
if (!iter->second->iconTextureData.empty()) {
|
|
|
|
iter->second->iconTextureData.clear();
|
|
|
|
}
|
|
|
|
if (iter->second->iconTexture) {
|
|
|
|
delete iter->second->iconTexture;
|
|
|
|
iter->second->iconTexture = 0;
|
|
|
|
}
|
2013-04-14 09:58:28 +00:00
|
|
|
}
|
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++) {
|
|
|
|
lock_guard lock(iter->second->lock);
|
|
|
|
if (!iter->second->pic0TextureData.empty()) {
|
|
|
|
iter->second->pic0TextureData.clear();
|
|
|
|
}
|
|
|
|
if (iter->second->pic0Texture) {
|
|
|
|
delete iter->second->pic0Texture;
|
|
|
|
iter->second->pic0Texture = 0;
|
|
|
|
}
|
|
|
|
if (!iter->second->pic1TextureData.empty()) {
|
|
|
|
iter->second->pic1TextureData.clear();
|
|
|
|
}
|
|
|
|
if (iter->second->pic1Texture) {
|
|
|
|
delete iter->second->pic1Texture;
|
|
|
|
iter->second->pic1Texture = 0;
|
|
|
|
}
|
2013-06-04 16:37:39 +00:00
|
|
|
iter->second->wantBG = false;
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This may run off-main-thread and we thus can't use the global
|
|
|
|
// pspFileSystem (well, we could with synchronization but there might not
|
|
|
|
// even be a game running).
|
2013-11-20 13:42:48 +00:00
|
|
|
GameInfo *GameInfoCache::GetInfo(const std::string &gamePath, bool wantBG, bool synchronous) {
|
2013-03-30 14:44:10 +00:00
|
|
|
auto iter = info_.find(gamePath);
|
|
|
|
if (iter != info_.end()) {
|
2013-03-30 18:23:20 +00:00
|
|
|
GameInfo *info = iter->second;
|
2013-03-31 00:04:46 +00:00
|
|
|
if (!info->wantBG && wantBG) {
|
2013-04-13 20:29:42 +00:00
|
|
|
// Need to start over. We'll just add a new work item.
|
|
|
|
delete info; // Hm, how dangerous is this? There might be a race condition here.
|
2013-03-31 00:04:46 +00:00
|
|
|
goto again;
|
|
|
|
}
|
2013-04-13 20:29:42 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(info->lock);
|
|
|
|
if (info->iconTextureData.size()) {
|
|
|
|
// We'd have to split up Texture->LoadPNG though, creating some intermediate Image class maybe.
|
2013-12-11 14:11:27 +00:00
|
|
|
info->iconTexture = new Texture();
|
2013-04-13 20:29:42 +00:00
|
|
|
if (info->iconTexture->LoadPNG((const u8 *)info->iconTextureData.data(), info->iconTextureData.size(), false)) {
|
|
|
|
info->timeIconWasLoaded = time_now_d();
|
2013-04-20 18:57:01 +00:00
|
|
|
} else {
|
|
|
|
delete info->iconTexture;
|
|
|
|
info->iconTexture = 0;
|
2013-04-13 20:29:42 +00:00
|
|
|
}
|
|
|
|
info->iconTextureData.clear();
|
2013-03-30 18:23:20 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-13 20:29:42 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(info->lock);
|
|
|
|
if (info->pic0TextureData.size()) {
|
|
|
|
info->pic0Texture = new Texture();
|
|
|
|
if (info->pic0Texture->LoadPNG((const u8 *)info->pic0TextureData.data(), info->pic0TextureData.size(), false)) {
|
|
|
|
info->timePic0WasLoaded = time_now_d();
|
2013-04-20 18:57:01 +00:00
|
|
|
} else {
|
2013-04-20 19:00:35 +00:00
|
|
|
delete info->pic0Texture;
|
|
|
|
info->pic0Texture = 0;
|
2013-04-13 20:29:42 +00:00
|
|
|
}
|
|
|
|
info->pic0TextureData.clear();
|
2013-03-30 18:23:20 +00:00
|
|
|
}
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-04-13 20:29:42 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(info->lock);
|
|
|
|
if (info->pic1TextureData.size()) {
|
|
|
|
info->pic1Texture = new Texture();
|
|
|
|
if (info->pic1Texture->LoadPNG((const u8 *)info->pic1TextureData.data(), info->pic1TextureData.size(), false)) {
|
|
|
|
info->timePic1WasLoaded = time_now_d();
|
2013-04-20 18:57:01 +00:00
|
|
|
} else {
|
2013-04-20 19:00:35 +00:00
|
|
|
delete info->pic1Texture;
|
|
|
|
info->pic1Texture = 0;
|
2013-04-13 20:29:42 +00:00
|
|
|
}
|
|
|
|
info->pic1TextureData.clear();
|
2013-04-01 10:35:02 +00:00
|
|
|
}
|
2013-03-30 18:23:20 +00:00
|
|
|
}
|
2013-03-30 14:44:10 +00:00
|
|
|
iter->second->lastAccessedTime = time_now_d();
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2013-03-31 00:04:46 +00:00
|
|
|
again:
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
GameInfo *info = new GameInfo();
|
|
|
|
info->wantBG = wantBG;
|
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
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
if (synchronous) {
|
|
|
|
gameInfoWQ_->Wait(item);
|
|
|
|
}
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
info_[gamePath] = info;
|
|
|
|
return info;
|
2013-03-30 14:44:10 +00:00
|
|
|
}
|