mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 02:59:49 +01:00
Merge pull request #14695 from hrydgard/scoped-load-fix
Scoped load fix
This commit is contained in:
9 files changed
+104
-53
No files matched your search
+37
-21
@@ -59,17 +59,19 @@ FileLoader *ConstructFileLoader(const Path &filename) {
|
||||
}
|
||||
|
||||
// TODO : improve, look in the file more
|
||||
IdentifiedFileType Identify_File(FileLoader *fileLoader) {
|
||||
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString) {
|
||||
*errorString = "";
|
||||
if (fileLoader == nullptr) {
|
||||
ERROR_LOG(LOADER, "Invalid fileLoader");
|
||||
*errorString = "Invalid fileLoader";
|
||||
return IdentifiedFileType::ERROR_IDENTIFYING;
|
||||
}
|
||||
if (fileLoader->GetPath().size() == 0) {
|
||||
ERROR_LOG(LOADER, "Invalid filename %s", fileLoader->GetPath().c_str());
|
||||
*errorString = "Invalid filename " + fileLoader->GetPath().ToString();
|
||||
return IdentifiedFileType::ERROR_IDENTIFYING;
|
||||
}
|
||||
|
||||
if (!fileLoader->Exists()) {
|
||||
*errorString = "IdentifyFile: File doesn't exist" + fileLoader->GetPath().ToString();
|
||||
return IdentifiedFileType::ERROR_IDENTIFYING;
|
||||
}
|
||||
|
||||
@@ -82,10 +84,11 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) {
|
||||
|
||||
// each sector in a mode2 image starts with these 12 bytes
|
||||
if (memcmp(sync,"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", 12) == 0) {
|
||||
*errorString = "ISO in Mode 2: Not a PSP game";
|
||||
return IdentifiedFileType::ISO_MODE2;
|
||||
}
|
||||
|
||||
// maybe it also just happened to have that size,
|
||||
// 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.
|
||||
}
|
||||
return IdentifiedFileType::PSP_ISO;
|
||||
} else if (extension == ".cso") {
|
||||
@@ -127,7 +130,7 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) {
|
||||
|
||||
size_t readSize = fileLoader->ReadAt(0, 4, 1, &id);
|
||||
if (readSize != 1) {
|
||||
ERROR_LOG(LOADER, "Failed to read identification bytes");
|
||||
*errorString = "Failed to read identification bytes";
|
||||
return IdentifiedFileType::ERROR_IDENTIFYING;
|
||||
}
|
||||
|
||||
@@ -201,7 +204,8 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) {
|
||||
}
|
||||
|
||||
FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader) {
|
||||
IdentifiedFileType type = Identify_File(fileLoader);
|
||||
std::string errorString;
|
||||
IdentifiedFileType type = Identify_File(fileLoader, &errorString);
|
||||
if (type == IdentifiedFileType::PSP_PBP_DIRECTORY) {
|
||||
const Path ebootFilename = ResolvePBPFile(fileLoader->GetPath());
|
||||
if (ebootFilename != fileLoader->GetPath()) {
|
||||
@@ -232,14 +236,15 @@ Path ResolvePBPFile(const Path &filename) {
|
||||
bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
FileLoader *&fileLoader = *fileLoaderPtr;
|
||||
// Note that this can modify filename!
|
||||
switch (Identify_File(fileLoader)) {
|
||||
IdentifiedFileType type = Identify_File(fileLoader, error_string);
|
||||
switch (type) {
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
{
|
||||
// TODO: Perhaps we should/can never get here now?
|
||||
fileLoader = ResolveFileLoaderTarget(fileLoader);
|
||||
if (fileLoader->Exists()) {
|
||||
INFO_LOG(LOADER, "File is a PBP in a directory!");
|
||||
IdentifiedFileType ebootType = Identify_File(fileLoader);
|
||||
IdentifiedFileType ebootType = Identify_File(fileLoader, error_string);
|
||||
if (ebootType == IdentifiedFileType::PSP_ISO_NP) {
|
||||
InitMemoryForGameISO(fileLoader);
|
||||
pspFileSystem.SetStartingDirectory("disc0:/PSP_GAME/USRDIR");
|
||||
@@ -249,6 +254,10 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
*error_string = "PS1 EBOOTs are not supported by PPSSPP.";
|
||||
coreState = CORE_BOOT_ERROR;
|
||||
return false;
|
||||
} else if (ebootType == IdentifiedFileType::ERROR_IDENTIFYING) {
|
||||
// IdentifyFile will have written to errorString.
|
||||
coreState = CORE_BOOT_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string dir = fileLoader->GetPath().GetDirectory();
|
||||
@@ -268,7 +277,7 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
case IdentifiedFileType::PSP_PBP:
|
||||
case IdentifiedFileType::PSP_ELF:
|
||||
{
|
||||
INFO_LOG(LOADER,"File is an ELF or loose PBP!");
|
||||
INFO_LOG(LOADER, "File is an ELF or loose PBP!");
|
||||
return Load_PSP_ELF_PBP(fileLoader, error_string);
|
||||
}
|
||||
|
||||
@@ -282,13 +291,6 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
*error_string = "PS1 EBOOTs are not supported by PPSSPP.";
|
||||
break;
|
||||
|
||||
case IdentifiedFileType::ERROR_IDENTIFYING:
|
||||
ERROR_LOG(LOADER, "Could not read file enough to identify it");
|
||||
*error_string = fileLoader ? fileLoader->LatestError() : "";
|
||||
if (error_string->empty())
|
||||
*error_string = "Error reading file";
|
||||
break;
|
||||
|
||||
case IdentifiedFileType::ARCHIVE_RAR:
|
||||
#ifdef WIN32
|
||||
*error_string = "RAR file detected (Require WINRAR)";
|
||||
@@ -336,9 +338,20 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
case IdentifiedFileType::UNKNOWN_BIN:
|
||||
case IdentifiedFileType::UNKNOWN_ELF:
|
||||
case IdentifiedFileType::UNKNOWN:
|
||||
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() : "");
|
||||
if (error_string->empty())
|
||||
*error_string = "Error reading file";
|
||||
ERROR_LOG(LOADER, "Error while identifying file: %s", error_string->c_str());
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_LOG(LOADER, "Failed to identify file: %s", fileLoader->GetPath().c_str());
|
||||
*error_string = "Failed to identify file";
|
||||
*error_string = StringFromFormat("Unhandled identified file type %d", (int)type);
|
||||
ERROR_LOG(LOADER, "%s", error_string->c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -347,7 +360,7 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
||||
}
|
||||
|
||||
bool UmdReplace(const Path &filepath, std::string &error) {
|
||||
IFileSystem* currentUMD = pspFileSystem.GetSystem("disc0:");
|
||||
IFileSystem *currentUMD = pspFileSystem.GetSystem("disc0:");
|
||||
|
||||
if (!currentUMD) {
|
||||
error = "has no disc";
|
||||
@@ -364,7 +377,10 @@ bool UmdReplace(const Path &filepath, std::string &error) {
|
||||
UpdateLoadedFile(loadedFile);
|
||||
|
||||
loadedFile = ResolveFileLoaderTarget(loadedFile);
|
||||
IdentifiedFileType type = Identify_File(loadedFile);
|
||||
|
||||
|
||||
std::string errorString;
|
||||
IdentifiedFileType type = Identify_File(loadedFile, &errorString);
|
||||
|
||||
switch (type) {
|
||||
case IdentifiedFileType::PSP_ISO:
|
||||
@@ -377,7 +393,7 @@ bool UmdReplace(const Path &filepath, std::string &error) {
|
||||
|
||||
break;
|
||||
default:
|
||||
error = "Unsupported file type:" + std::to_string((int)type);
|
||||
error = "Unsupported file type: " + std::to_string((int)type) + " " + errorString;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader);
|
||||
Path ResolvePBPDirectory(const Path &filename);
|
||||
Path ResolvePBPFile(const Path &filename);
|
||||
|
||||
IdentifiedFileType Identify_File(FileLoader *fileLoader);
|
||||
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString);
|
||||
|
||||
class FileLoaderFactory {
|
||||
public:
|
||||
|
||||
+6
-3
@@ -216,7 +216,7 @@ bool DiscIDFromGEDumpPath(const Path &path, FileLoader *fileLoader, std::string
|
||||
}
|
||||
}
|
||||
|
||||
bool CPU_Init() {
|
||||
bool CPU_Init(std::string *errorString) {
|
||||
coreState = CORE_POWERUP;
|
||||
currentMIPS = &mipsr4k;
|
||||
|
||||
@@ -237,7 +237,8 @@ bool CPU_Init() {
|
||||
loadedFile = new RamCachingFileLoader(loadedFile);
|
||||
}
|
||||
#endif
|
||||
IdentifiedFileType type = Identify_File(loadedFile);
|
||||
|
||||
IdentifiedFileType type = Identify_File(loadedFile, errorString);
|
||||
|
||||
// TODO: Put this somewhere better?
|
||||
if (!coreParameter.mountIso.empty()) {
|
||||
@@ -277,6 +278,8 @@ bool CPU_Init() {
|
||||
allowPlugins = false;
|
||||
break;
|
||||
default:
|
||||
// Can we even get here?
|
||||
WARN_LOG(LOADER, "CPU_Init didn't recognize file. %s", errorString->c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -413,7 +416,7 @@ bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) {
|
||||
pspIsIniting = true;
|
||||
PSP_SetLoading("Loading game...");
|
||||
|
||||
if (!CPU_Init()) {
|
||||
if (!CPU_Init(&coreParameter.errorString)) {
|
||||
*error_string = coreParameter.errorString;
|
||||
if (error_string->empty()) {
|
||||
*error_string = "Failed initializing CPU/Memory";
|
||||
|
||||
@@ -399,7 +399,8 @@ std::string GameManager::GetGameID(const Path &path) const {
|
||||
auto loader = ConstructFileLoader(path);
|
||||
std::string id;
|
||||
|
||||
switch (Identify_File(loader)) {
|
||||
std::string errorString;
|
||||
switch (Identify_File(loader, &errorString)) {
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
delete loader;
|
||||
loader = ConstructFileLoader(ResolvePBPFile(path));
|
||||
|
||||
@@ -356,8 +356,10 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
std::string errorString;
|
||||
|
||||
info_->working = true;
|
||||
info_->fileType = Identify_File(info_->GetFileLoader().get());
|
||||
info_->fileType = Identify_File(info_->GetFileLoader().get(), &errorString);
|
||||
switch (info_->fileType) {
|
||||
case IdentifiedFileType::PSP_PBP:
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
|
||||
+2
-1
@@ -74,7 +74,8 @@ bool LaunchFile(ScreenManager *screenManager, const Path &path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IdentifiedFileType type = Identify_File(loader);
|
||||
std::string errorString;
|
||||
IdentifiedFileType type = Identify_File(loader, &errorString);
|
||||
delete loader;
|
||||
|
||||
switch (type) {
|
||||
|
||||
@@ -426,7 +426,8 @@ bool SavedataBrowser::ByFilename(const UI::View *v1, const UI::View *v2) {
|
||||
|
||||
static time_t GetTotalSize(const SavedataButton *b) {
|
||||
auto fileLoader = std::unique_ptr<FileLoader>(ConstructFileLoader(b->GamePath()));
|
||||
switch (Identify_File(fileLoader.get())) {
|
||||
std::string errorString;
|
||||
switch (Identify_File(fileLoader.get(), &errorString)) {
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
||||
return File::GetDirectoryRecursiveSize(ResolvePBPDirectory(b->GamePath()), nullptr, File::GETFILES_GETHIDDEN);
|
||||
@@ -449,7 +450,8 @@ static time_t GetDateSeconds(const SavedataButton *b) {
|
||||
auto fileLoader = std::unique_ptr<FileLoader>(ConstructFileLoader(b->GamePath()));
|
||||
tm datetm;
|
||||
bool success;
|
||||
if (Identify_File(fileLoader.get()) == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY) {
|
||||
std::string errorString;
|
||||
if (Identify_File(fileLoader.get(), &errorString) == IdentifiedFileType::PSP_SAVEDATA_DIRECTORY) {
|
||||
success = File::GetModifTime(b->GamePath() / "PARAM.SFO", datetm);
|
||||
} else {
|
||||
success = File::GetModifTime(b->GamePath(), datetm);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Net/URL.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
// Utility to deal with Android storage URIs of the forms:
|
||||
// content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO
|
||||
@@ -37,13 +38,24 @@ public:
|
||||
std::vector<std::string> parts;
|
||||
SplitString(components, '/', parts);
|
||||
if (parts.size() == 3) {
|
||||
// Single file URI.
|
||||
provider = parts[0];
|
||||
if (parts[1] != "tree") {
|
||||
if (parts[1] == "tree") {
|
||||
// Single directory URI.
|
||||
// Not sure when we encounter these?
|
||||
// file empty signals this type.
|
||||
root = UriDecode(parts[2]);
|
||||
return true;
|
||||
} else if (parts[1] == "document") {
|
||||
// root empty signals this type.
|
||||
file = UriDecode(parts[2]);
|
||||
return true;
|
||||
} else {
|
||||
// What's this?
|
||||
return false;
|
||||
}
|
||||
root = UriDecode(parts[2]);
|
||||
return true;
|
||||
} else if (parts.size() == 5) {
|
||||
// Tree URI
|
||||
provider = parts[0];
|
||||
if (parts[1] != "tree") {
|
||||
return false;
|
||||
@@ -62,6 +74,11 @@ public:
|
||||
}
|
||||
|
||||
AndroidContentURI WithRootFilePath(const std::string &filePath) {
|
||||
if (root.empty()) {
|
||||
ERROR_LOG(SYSTEM, "WithRootFilePath cannot be used with single file URIs.");
|
||||
return *this;
|
||||
}
|
||||
|
||||
AndroidContentURI uri = *this;
|
||||
uri.file = uri.root;
|
||||
if (!filePath.empty()) {
|
||||
@@ -103,11 +120,10 @@ public:
|
||||
return uri;
|
||||
}
|
||||
|
||||
bool IsTreeURI() const {
|
||||
return file.empty();
|
||||
}
|
||||
|
||||
bool CanNavigateUp() const {
|
||||
if (root.empty()) {
|
||||
return false;
|
||||
}
|
||||
return file.size() > root.size();
|
||||
}
|
||||
|
||||
@@ -142,7 +158,7 @@ public:
|
||||
}
|
||||
|
||||
std::string GetLastPart() const {
|
||||
if (IsTreeURI()) {
|
||||
if (file.empty()) {
|
||||
// Can't do anything anyway.
|
||||
return std::string();
|
||||
}
|
||||
@@ -179,7 +195,7 @@ public:
|
||||
}
|
||||
|
||||
bool TreeContains(const AndroidContentURI &fileURI) {
|
||||
if (!IsTreeURI()) {
|
||||
if (root.empty()) {
|
||||
return false;
|
||||
}
|
||||
return startsWith(fileURI.file, root);
|
||||
@@ -189,8 +205,11 @@ public:
|
||||
if (file.empty()) {
|
||||
// Tree URI
|
||||
return StringFromFormat("content://%s/tree/%s", provider.c_str(), UriEncode(root).c_str());
|
||||
} else if (root.empty()) {
|
||||
// Single file URI
|
||||
return StringFromFormat("content://%s/document/%s", provider.c_str(), UriEncode(file).c_str());
|
||||
} else {
|
||||
// File URI
|
||||
// File URI from Tree
|
||||
return StringFromFormat("content://%s/tree/%s/document/%s", provider.c_str(), UriEncode(root).c_str(), UriEncode(file).c_str());
|
||||
}
|
||||
}
|
||||
@@ -205,6 +224,6 @@ public:
|
||||
}
|
||||
|
||||
const std::string &RootPath() const {
|
||||
return root;
|
||||
return root.empty() ? file : root;
|
||||
}
|
||||
};
|
||||
+19
-12
@@ -622,33 +622,40 @@ static bool TestPath() {
|
||||
static bool TestAndroidContentURI() {
|
||||
static const char *treeURIString = "content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO";
|
||||
static const char *directoryURIString = "content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO/document/primary%3APSP%20ISO";
|
||||
static const char *fileURIString = "content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO/document/primary%3APSP%20ISO%2FTekken%206.iso";
|
||||
static const char *fileTreeURIString = "content://com.android.externalstorage.documents/tree/primary%3APSP%20ISO/document/primary%3APSP%20ISO%2FTekken%206.iso";
|
||||
static const char *fileNonTreeString = "content://com.android.externalstorage.documents/document/primary%3APSP%2Fcrash_bad_execaddr.prx";
|
||||
|
||||
|
||||
AndroidContentURI treeURI;
|
||||
EXPECT_TRUE(treeURI.Parse(std::string(treeURIString)));
|
||||
AndroidContentURI dirURI;
|
||||
EXPECT_TRUE(dirURI.Parse(std::string(directoryURIString)));
|
||||
AndroidContentURI fileTreeURI;
|
||||
EXPECT_TRUE(fileTreeURI.Parse(std::string(fileTreeURIString)));
|
||||
AndroidContentURI fileTreeURICopy;
|
||||
EXPECT_TRUE(fileTreeURICopy.Parse(std::string(fileTreeURIString)));
|
||||
AndroidContentURI fileURI;
|
||||
EXPECT_TRUE(fileURI.Parse(std::string(fileURIString)));
|
||||
EXPECT_TRUE(fileURI.Parse(std::string(fileNonTreeString)));
|
||||
|
||||
std::string lastPart = dirURI.GetLastPart();
|
||||
EXPECT_EQ_STR(fileTreeURI.GetLastPart(), std::string("Tekken 6.iso"));
|
||||
|
||||
EXPECT_EQ_STR(fileURI.GetLastPart(), std::string("Tekken 6.iso"));
|
||||
EXPECT_TRUE(treeURI.TreeContains(fileTreeURI));
|
||||
|
||||
EXPECT_TRUE(treeURI.TreeContains(fileURI));
|
||||
|
||||
EXPECT_TRUE(fileURI.CanNavigateUp());
|
||||
fileURI.NavigateUp();
|
||||
EXPECT_FALSE(fileURI.CanNavigateUp());
|
||||
EXPECT_TRUE(fileTreeURI.CanNavigateUp());
|
||||
fileTreeURI.NavigateUp();
|
||||
EXPECT_FALSE(fileTreeURI.CanNavigateUp());
|
||||
|
||||
EXPECT_EQ_STR(fileURI.FilePath(), fileURI.RootPath());
|
||||
EXPECT_EQ_STR(fileTreeURI.FilePath(), fileTreeURI.RootPath());
|
||||
|
||||
EXPECT_EQ_STR(fileURI.ToString(), std::string(directoryURIString));
|
||||
EXPECT_EQ_STR(fileTreeURI.ToString(), std::string(directoryURIString));
|
||||
|
||||
std::string diff;
|
||||
EXPECT_TRUE(dirURI.ComputePathTo(fileURI, diff));
|
||||
EXPECT_TRUE(dirURI.ComputePathTo(fileTreeURICopy, diff));
|
||||
EXPECT_EQ_STR(diff, std::string("Tekken 6.iso"));
|
||||
|
||||
EXPECT_EQ_STR(fileURI.GetFileExtension(), std::string(".prx"));
|
||||
EXPECT_FALSE(fileURI.CanNavigateUp());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user