2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- 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
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// 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/.
|
|
|
|
|
2014-11-25 19:47:58 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2021-05-09 13:02:46 +00:00
|
|
|
#include "Common/File/Path.h"
|
2020-09-29 10:19:22 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2015-06-27 17:58:44 +00:00
|
|
|
#include "Core/FileLoaders/CachingFileLoader.h"
|
2015-06-28 01:32:21 +00:00
|
|
|
#include "Core/FileLoaders/DiskCachingFileLoader.h"
|
2015-06-27 17:58:44 +00:00
|
|
|
#include "Core/FileLoaders/HTTPFileLoader.h"
|
|
|
|
#include "Core/FileLoaders/LocalFileLoader.h"
|
|
|
|
#include "Core/FileLoaders/RetryingFileLoader.h"
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Core/FileSystems/MetaFileSystem.h"
|
|
|
|
#include "Core/PSPLoaders.h"
|
|
|
|
#include "Core/MemMap.h"
|
|
|
|
#include "Core/Loaders.h"
|
|
|
|
#include "Core/System.h"
|
2014-03-03 16:46:26 +00:00
|
|
|
#include "Core/ELF/PBPReader.h"
|
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-03-02 16:07:12 +00:00
|
|
|
static std::map<std::string, std::unique_ptr<FileLoaderFactory>> factories;
|
2017-02-27 10:32:40 +00:00
|
|
|
|
2017-03-02 16:07:12 +00:00
|
|
|
void RegisterFileLoaderFactory(std::string prefix, std::unique_ptr<FileLoaderFactory> factory) {
|
|
|
|
factories[prefix] = std::move(factory);
|
2017-02-27 10:32:40 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
FileLoader *ConstructFileLoader(const Path &filename) {
|
|
|
|
if (filename.Type() == PathType::HTTP) {
|
2021-01-18 02:33:35 +00:00
|
|
|
FileLoader *baseLoader = new RetryingFileLoader(new HTTPFileLoader(filename));
|
|
|
|
// For headless, avoid disk caching since it's usually used for tests that might mutate.
|
|
|
|
if (!PSP_CoreParameter().headLess) {
|
|
|
|
baseLoader = new DiskCachingFileLoader(baseLoader);
|
|
|
|
}
|
|
|
|
return new CachingFileLoader(baseLoader);
|
|
|
|
}
|
2017-03-02 16:07:12 +00:00
|
|
|
|
|
|
|
for (auto &iter : factories) {
|
2021-05-09 16:38:48 +00:00
|
|
|
if (startsWith(filename.ToString(), iter.first)) {
|
2017-03-02 16:07:12 +00:00
|
|
|
return iter.second->ConstructFileLoader(filename);
|
|
|
|
}
|
2017-02-27 10:32:40 +00:00
|
|
|
}
|
2014-11-23 22:02:35 +00:00
|
|
|
return new LocalFileLoader(filename);
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// TODO : improve, look in the file more
|
2021-08-07 09:54:45 +00:00
|
|
|
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString) {
|
2022-10-03 07:47:55 +00:00
|
|
|
errorString->clear();
|
2014-11-23 21:25:32 +00:00
|
|
|
if (fileLoader == nullptr) {
|
2021-08-07 09:54:45 +00:00
|
|
|
*errorString = "Invalid fileLoader";
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ERROR_IDENTIFYING;
|
2014-11-23 21:25:32 +00:00
|
|
|
}
|
2021-05-10 00:10:14 +00:00
|
|
|
if (fileLoader->GetPath().size() == 0) {
|
2021-08-07 09:54:45 +00:00
|
|
|
*errorString = "Invalid filename " + fileLoader->GetPath().ToString();
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ERROR_IDENTIFYING;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 21:25:32 +00:00
|
|
|
if (!fileLoader->Exists()) {
|
2021-09-08 21:24:28 +00:00
|
|
|
*errorString = "IdentifyFile: File doesn't exist: " + fileLoader->GetPath().ToString();
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ERROR_IDENTIFYING;
|
2013-09-01 23:49:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
std::string extension = fileLoader->GetPath().GetFileExtension();
|
2021-05-10 00:17:13 +00:00
|
|
|
if (extension == ".iso") {
|
2013-09-01 23:49:15 +00:00
|
|
|
// may be a psx iso, they have 2352 byte sectors. You never know what some people try to open
|
2017-06-03 19:47:38 +00:00
|
|
|
if ((fileLoader->FileSize() % 2352) == 0) {
|
2013-09-01 23:49:15 +00:00
|
|
|
unsigned char sync[12];
|
2014-11-23 21:25:32 +00:00
|
|
|
fileLoader->ReadAt(0, 12, sync);
|
2013-09-01 23:49:15 +00:00
|
|
|
|
|
|
|
// each sector in a mode2 image starts with these 12 bytes
|
2017-06-03 19:47:38 +00:00
|
|
|
if (memcmp(sync,"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", 12) == 0) {
|
2021-08-07 09:54:45 +00:00
|
|
|
*errorString = "ISO in Mode 2: Not a PSP game";
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ISO_MODE2;
|
2013-09-01 23:49:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-07 09:54:45 +00:00
|
|
|
// maybe it also just happened to have that size, let's assume it's a PSP ISO and error out later if it's not.
|
2013-09-01 23:49:15 +00:00
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_ISO;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".cso") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_ISO;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".ppst") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PPSSPP_SAVESTATE;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".ppdmp") {
|
2017-06-03 19:47:38 +00:00
|
|
|
char data[8]{};
|
|
|
|
fileLoader->ReadAt(0, 8, data);
|
|
|
|
if (memcmp(data, "PPSSPPGE", 8) == 0) {
|
|
|
|
return IdentifiedFileType::PPSSPP_GE_DUMP;
|
|
|
|
}
|
2015-06-11 21:59:02 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2013-09-01 23:50:43 +00:00
|
|
|
// First, check if it's a directory with an EBOOT.PBP in it.
|
2014-11-23 21:25:32 +00:00
|
|
|
if (fileLoader->IsDirectory()) {
|
2021-05-09 17:06:02 +00:00
|
|
|
Path filename = fileLoader->GetPath();
|
2013-08-20 14:52:36 +00:00
|
|
|
if (filename.size() > 4) {
|
|
|
|
// Check for existence of EBOOT.PBP, as required for "Directory games".
|
2021-05-09 13:02:46 +00:00
|
|
|
if (File::Exists(filename / "EBOOT.PBP")) {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PBP_DIRECTORY;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2013-07-23 15:24:33 +00:00
|
|
|
|
2013-08-20 14:52:36 +00:00
|
|
|
// check if it's a disc directory
|
2021-05-09 13:02:46 +00:00
|
|
|
if (File::Exists(filename / "PSP_GAME")) {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_DISC_DIRECTORY;
|
2013-07-23 15:24:33 +00:00
|
|
|
}
|
2015-06-11 18:22:16 +00:00
|
|
|
|
|
|
|
// Not that, okay, let's guess it's a savedata directory if it has a param.sfo...
|
2021-05-09 13:02:46 +00:00
|
|
|
if (File::Exists(filename / "PARAM.SFO")) {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_SAVEDATA_DIRECTORY;
|
2015-06-11 18:22:16 +00:00
|
|
|
}
|
2013-07-23 15:24:33 +00:00
|
|
|
}
|
2013-08-20 14:52:36 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::NORMAL_DIRECTORY;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 15:47:17 +00:00
|
|
|
// OK, quick methods of identification for common types failed. Moving on to more expensive methods,
|
|
|
|
// starting by reading the first few bytes.
|
|
|
|
|
2013-07-27 23:05:21 +00:00
|
|
|
u32_le id;
|
2013-01-07 14:57:19 +00:00
|
|
|
|
2014-11-23 21:25:32 +00:00
|
|
|
size_t readSize = fileLoader->ReadAt(0, 4, 1, &id);
|
2013-06-08 15:48:41 +00:00
|
|
|
if (readSize != 1) {
|
2021-08-07 09:54:45 +00:00
|
|
|
*errorString = "Failed to read identification bytes";
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ERROR_IDENTIFYING;
|
2013-05-30 15:40:35 +00:00
|
|
|
}
|
2013-01-07 14:57:19 +00:00
|
|
|
|
2021-02-19 06:25:24 +00:00
|
|
|
u32_le psar_offset = 0, psar_id = 0;
|
2013-08-17 13:12:42 +00:00
|
|
|
u32 _id = id;
|
2020-07-27 09:33:23 +00:00
|
|
|
if (!memcmp(&_id, "PK\x03\x04", 4) || !memcmp(&_id, "PK\x05\x06", 4) || !memcmp(&_id, "PK\x07\x08", 4)) {
|
|
|
|
return IdentifiedFileType::ARCHIVE_ZIP;
|
|
|
|
} else if (!memcmp(&_id, "\x00PBP", 4)) {
|
2014-11-23 21:25:32 +00:00
|
|
|
fileLoader->ReadAt(0x24, 4, 1, &psar_offset);
|
|
|
|
fileLoader->ReadAt(psar_offset, 4, 1, &psar_id);
|
2022-04-30 15:47:17 +00:00
|
|
|
// Fall through to the below if chain.
|
2020-07-27 09:33:23 +00:00
|
|
|
} else if (!memcmp(&_id, "Rar!", 4)) {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_RAR;
|
2022-04-30 15:47:17 +00:00
|
|
|
} else if (!memcmp(&_id, "\x37\x7A\xBC\xAF", 4)) {
|
|
|
|
return IdentifiedFileType::ARCHIVE_7Z;
|
|
|
|
} else if (!memcmp(&_id, "\0\0\0\0", 4)) {
|
|
|
|
// All zeroes. ISO files start like this but their 16th 2048-byte sector contains metadata.
|
|
|
|
if (fileLoader->FileSize() > 0x8100) {
|
|
|
|
char buffer[16];
|
|
|
|
fileLoader->ReadAt(0x8000, sizeof(buffer), buffer);
|
|
|
|
if (!memcmp(buffer + 1, "CD001", 5)) {
|
|
|
|
// It's an ISO file.
|
|
|
|
if (!memcmp(buffer + 8, "PSP GAME", 8)) {
|
|
|
|
return IdentifiedFileType::PSP_ISO;
|
|
|
|
}
|
|
|
|
return IdentifiedFileType::UNKNOWN_ISO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!memcmp(&_id, "CISO", 4)) {
|
|
|
|
// CISO are not used for many other kinds of ISO so let's just guess it's a PSP one and let it
|
|
|
|
// fail later...
|
|
|
|
return IdentifiedFileType::PSP_ISO;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2013-05-08 15:36:57 +00:00
|
|
|
|
2013-08-10 17:56:47 +00:00
|
|
|
if (id == 'FLE\x7F') {
|
2021-05-09 16:38:48 +00:00
|
|
|
Path filename = fileLoader->GetPath();
|
2013-06-22 16:50:40 +00:00
|
|
|
// There are a few elfs misnamed as pbp (like Trig Wars), accept that.
|
2021-05-09 16:38:48 +00:00
|
|
|
if (extension == ".plf" || strstr(filename.GetFilename().c_str(), "BOOT.BIN") ||
|
2021-05-10 00:17:13 +00:00
|
|
|
extension == ".elf" || extension == ".prx" || extension == ".pbp") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_ELF;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::UNKNOWN_ELF;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (id == 'PBP\x00') {
|
2014-03-03 16:46:26 +00:00
|
|
|
// Do this PS1 eboot check FIRST before checking other eboot types.
|
|
|
|
// It seems like some are malformed and slip through the PSAR check below.
|
2015-12-24 18:40:25 +00:00
|
|
|
PBPReader pbp(fileLoader);
|
2015-12-24 18:20:27 +00:00
|
|
|
if (pbp.IsValid() && !pbp.IsELF()) {
|
|
|
|
std::vector<u8> sfoData;
|
|
|
|
if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
|
|
|
|
ParamSFOData paramSFO;
|
|
|
|
paramSFO.ReadSFO(sfoData);
|
|
|
|
// PS1 Eboots are supposed to use "ME" as their PARAM SFO category.
|
|
|
|
// If they don't, and they're still malformed (e.g. PSISOIMG0000 isn't found), there's nothing we can do.
|
|
|
|
if (paramSFO.GetValueString("CATEGORY") == "ME")
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PS1_PBP;
|
2014-03-03 16:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 15:48:41 +00:00
|
|
|
if (psar_id == 'MUPN') {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_ISO_NP;
|
2013-06-08 15:48:41 +00:00
|
|
|
}
|
2013-08-12 05:23:33 +00:00
|
|
|
// PS1 PSAR begins with "PSISOIMG0000"
|
|
|
|
if (psar_id == 'SISP') {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PS1_PBP;
|
2013-08-12 05:23:33 +00:00
|
|
|
}
|
2013-07-21 12:11:52 +00:00
|
|
|
|
|
|
|
// Let's check if we got pointed to a PBP within such a directory.
|
|
|
|
// If so we just move up and return the directory itself as the game.
|
|
|
|
// If loading from memstick...
|
2021-12-16 19:37:05 +00:00
|
|
|
if (fileLoader->GetPath().FilePathContainsNoCase("PSP/GAME/")) {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PBP_DIRECTORY;
|
2013-07-21 12:11:52 +00:00
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PBP;
|
2021-05-11 21:58:54 +00:00
|
|
|
} else if (extension == ".pbp") {
|
2013-07-21 12:11:52 +00:00
|
|
|
ERROR_LOG(LOADER, "A PBP with the wrong magic number?");
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::PSP_PBP;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".bin") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::UNKNOWN_BIN;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".zip") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_ZIP;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".rar") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_RAR;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".r00") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_RAR;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".r01") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_RAR;
|
2021-05-10 00:17:13 +00:00
|
|
|
} else if (extension == ".7z") {
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::ARCHIVE_7Z;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
return IdentifiedFileType::UNKNOWN;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 03:25:28 +00:00
|
|
|
FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader) {
|
2021-08-07 09:54:45 +00:00
|
|
|
std::string errorString;
|
|
|
|
IdentifiedFileType type = Identify_File(fileLoader, &errorString);
|
2017-03-02 11:29:03 +00:00
|
|
|
if (type == IdentifiedFileType::PSP_PBP_DIRECTORY) {
|
2021-05-09 16:38:48 +00:00
|
|
|
const Path ebootFilename = ResolvePBPFile(fileLoader->GetPath());
|
2021-05-10 00:10:14 +00:00
|
|
|
if (ebootFilename != fileLoader->GetPath()) {
|
2016-06-27 03:33:25 +00:00
|
|
|
// Switch fileLoader to the actual EBOOT.
|
|
|
|
delete fileLoader;
|
|
|
|
fileLoader = ConstructFileLoader(ebootFilename);
|
|
|
|
}
|
2015-12-28 03:25:28 +00:00
|
|
|
}
|
|
|
|
return fileLoader;
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
Path ResolvePBPDirectory(const Path &filename) {
|
|
|
|
if (filename.GetFilename() == "EBOOT.PBP") {
|
|
|
|
return filename.NavigateUp();
|
|
|
|
} else {
|
|
|
|
return filename;
|
2016-06-27 03:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
Path ResolvePBPFile(const Path &filename) {
|
|
|
|
if (filename.GetFilename() != "EBOOT.PBP") {
|
|
|
|
return filename / "EBOOT.PBP";
|
|
|
|
} else {
|
|
|
|
return filename;
|
2016-06-27 03:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-23 22:08:14 +00:00
|
|
|
bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
|
|
|
FileLoader *&fileLoader = *fileLoaderPtr;
|
2013-06-08 15:48:41 +00:00
|
|
|
// Note that this can modify filename!
|
2021-08-07 09:54:45 +00:00
|
|
|
IdentifiedFileType type = Identify_File(fileLoader, error_string);
|
|
|
|
switch (type) {
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
2013-06-08 15:48:41 +00:00
|
|
|
{
|
2015-12-28 03:25:28 +00:00
|
|
|
// TODO: Perhaps we should/can never get here now?
|
|
|
|
fileLoader = ResolveFileLoaderTarget(fileLoader);
|
2014-11-23 21:25:32 +00:00
|
|
|
if (fileLoader->Exists()) {
|
2013-06-08 15:48:41 +00:00
|
|
|
INFO_LOG(LOADER, "File is a PBP in a directory!");
|
2021-08-07 09:54:45 +00:00
|
|
|
IdentifiedFileType ebootType = Identify_File(fileLoader, error_string);
|
2017-03-02 11:29:03 +00:00
|
|
|
if (ebootType == IdentifiedFileType::PSP_ISO_NP) {
|
2014-11-23 21:25:32 +00:00
|
|
|
InitMemoryForGameISO(fileLoader);
|
2013-09-01 17:25:42 +00:00
|
|
|
pspFileSystem.SetStartingDirectory("disc0:/PSP_GAME/USRDIR");
|
2014-11-23 21:59:56 +00:00
|
|
|
return Load_PSP_ISO(fileLoader, error_string);
|
2013-09-01 17:25:42 +00:00
|
|
|
}
|
2017-03-02 11:29:03 +00:00
|
|
|
else if (ebootType == IdentifiedFileType::PSP_PS1_PBP) {
|
2014-02-25 04:15:49 +00:00
|
|
|
*error_string = "PS1 EBOOTs are not supported by PPSSPP.";
|
2020-07-04 18:19:56 +00:00
|
|
|
coreState = CORE_BOOT_ERROR;
|
2014-02-25 04:15:49 +00:00
|
|
|
return false;
|
2021-08-07 09:54:45 +00:00
|
|
|
} else if (ebootType == IdentifiedFileType::ERROR_IDENTIFYING) {
|
|
|
|
// IdentifyFile will have written to errorString.
|
|
|
|
coreState = CORE_BOOT_ERROR;
|
|
|
|
return false;
|
2014-02-25 04:15:49 +00:00
|
|
|
}
|
2021-05-09 16:38:48 +00:00
|
|
|
|
|
|
|
std::string dir = fileLoader->GetPath().GetDirectory();
|
|
|
|
size_t pos = dir.find("PSP/GAME/");
|
2015-12-28 03:25:28 +00:00
|
|
|
if (pos != std::string::npos) {
|
2021-05-09 16:38:48 +00:00
|
|
|
dir = ResolvePBPDirectory(Path(dir)).ToString();
|
|
|
|
pspFileSystem.SetStartingDirectory("ms0:/" + dir.substr(pos));
|
2015-12-28 03:25:28 +00:00
|
|
|
}
|
2014-11-23 21:59:56 +00:00
|
|
|
return Load_PSP_ELF_PBP(fileLoader, error_string);
|
2013-06-08 15:48:41 +00:00
|
|
|
} else {
|
|
|
|
*error_string = "No EBOOT.PBP, misidentified game";
|
2020-07-04 18:19:56 +00:00
|
|
|
coreState = CORE_BOOT_ERROR;
|
2013-06-08 15:48:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP:
|
|
|
|
case IdentifiedFileType::PSP_ELF:
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2021-08-07 09:54:45 +00:00
|
|
|
INFO_LOG(LOADER, "File is an ELF or loose PBP!");
|
2014-11-23 21:59:56 +00:00
|
|
|
return Load_PSP_ELF_PBP(fileLoader, error_string);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY: // behaves the same as the mounting is already done by now
|
2013-01-10 11:27:10 +00:00
|
|
|
pspFileSystem.SetStartingDirectory("disc0:/PSP_GAME/USRDIR");
|
2014-11-23 21:59:56 +00:00
|
|
|
return Load_PSP_ISO(fileLoader, error_string);
|
2013-06-08 15:48:41 +00:00
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PS1_PBP:
|
2013-08-12 05:23:33 +00:00
|
|
|
*error_string = "PS1 EBOOTs are not supported by PPSSPP.";
|
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_RAR:
|
2013-08-23 07:52:28 +00:00
|
|
|
#ifdef WIN32
|
2013-09-03 10:42:12 +00:00
|
|
|
*error_string = "RAR file detected (Require WINRAR)";
|
2013-08-23 07:52:28 +00:00
|
|
|
#else
|
2013-09-03 10:42:12 +00:00
|
|
|
*error_string = "RAR file detected (Require UnRAR)";
|
2013-08-23 07:52:28 +00:00
|
|
|
#endif
|
2013-08-10 17:56:47 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_ZIP:
|
2013-08-23 07:52:28 +00:00
|
|
|
#ifdef WIN32
|
2013-09-03 10:42:12 +00:00
|
|
|
*error_string = "ZIP file detected (Require WINRAR)";
|
2013-08-23 07:52:28 +00:00
|
|
|
#else
|
2013-09-03 10:42:12 +00:00
|
|
|
*error_string = "ZIP file detected (Require UnRAR)";
|
2013-08-23 07:52:28 +00:00
|
|
|
#endif
|
2013-08-10 17:56:47 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ARCHIVE_7Z:
|
2014-10-20 22:09:24 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
*error_string = "7z file detected (Require 7-Zip)";
|
|
|
|
#else
|
|
|
|
*error_string = "7z file detected (Require 7-Zip)";
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::ISO_MODE2:
|
2013-09-04 11:48:22 +00:00
|
|
|
*error_string = "PSX game image detected.";
|
2013-09-01 23:49:15 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::NORMAL_DIRECTORY:
|
2013-08-20 14:52:36 +00:00
|
|
|
ERROR_LOG(LOADER, "Just a directory.");
|
2013-09-01 17:25:42 +00:00
|
|
|
*error_string = "Just a directory.";
|
2013-08-20 14:52:36 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PPSSPP_SAVESTATE:
|
2015-06-12 12:46:34 +00:00
|
|
|
*error_string = "This is a saved state, not a game."; // Actually, we could make it load it...
|
|
|
|
break;
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
2015-06-12 12:46:34 +00:00
|
|
|
*error_string = "This is save data, not a game."; // Actually, we could make it load it...
|
|
|
|
break;
|
|
|
|
|
2017-06-03 19:47:38 +00:00
|
|
|
case IdentifiedFileType::PPSSPP_GE_DUMP:
|
|
|
|
return Load_PSP_GE_Dump(fileLoader, error_string);
|
|
|
|
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::UNKNOWN_BIN:
|
|
|
|
case IdentifiedFileType::UNKNOWN_ELF:
|
2022-04-30 15:47:17 +00:00
|
|
|
case IdentifiedFileType::UNKNOWN_ISO:
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::UNKNOWN:
|
2021-08-07 09:54:45 +00:00
|
|
|
ERROR_LOG(LOADER, "Unknown file type: %s (%s)", fileLoader->GetPath().c_str(), error_string->c_str());
|
|
|
|
*error_string = "Unknown file type: " + fileLoader->GetPath().ToString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IdentifiedFileType::ERROR_IDENTIFYING:
|
|
|
|
*error_string = *error_string + ": " + (fileLoader ? fileLoader->LatestError() : "");
|
|
|
|
ERROR_LOG(LOADER, "Error while identifying file: %s", error_string->c_str());
|
|
|
|
break;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
default:
|
2021-08-07 09:54:45 +00:00
|
|
|
*error_string = StringFromFormat("Unhandled identified file type %d", (int)type);
|
|
|
|
ERROR_LOG(LOADER, "%s", error_string->c_str());
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-11-02 04:27:01 +00:00
|
|
|
|
2020-07-04 18:19:56 +00:00
|
|
|
coreState = CORE_BOOT_ERROR;
|
2012-11-01 15:19:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-01-02 06:56:24 +00:00
|
|
|
|
2021-05-09 16:38:48 +00:00
|
|
|
bool UmdReplace(const Path &filepath, std::string &error) {
|
2021-08-07 09:54:45 +00:00
|
|
|
IFileSystem *currentUMD = pspFileSystem.GetSystem("disc0:");
|
2020-01-02 06:56:24 +00:00
|
|
|
|
|
|
|
if (!currentUMD) {
|
|
|
|
error = "has no disc";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileLoader *loadedFile = ConstructFileLoader(filepath);
|
|
|
|
|
|
|
|
if (!loadedFile->Exists()) {
|
2021-05-09 16:38:48 +00:00
|
|
|
error = loadedFile->GetPath().ToVisualString() + " doesn't exist";
|
2022-12-11 05:12:58 +00:00
|
|
|
delete loadedFile;
|
2020-01-02 06:56:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UpdateLoadedFile(loadedFile);
|
|
|
|
|
|
|
|
loadedFile = ResolveFileLoaderTarget(loadedFile);
|
2021-08-07 09:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::string errorString;
|
|
|
|
IdentifiedFileType type = Identify_File(loadedFile, &errorString);
|
2020-01-02 06:56:24 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
2020-01-03 06:33:32 +00:00
|
|
|
if (!ReInitMemoryForGameISO(loadedFile)) {
|
|
|
|
error = "reinit memory failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-02 06:56:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-07 09:54:45 +00:00
|
|
|
error = "Unsupported file type: " + std::to_string((int)type) + " " + errorString;
|
2020-01-02 06:56:24 +00:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|