mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Startup cleanup, part 1
This commit is contained in:
parent
3880f83e81
commit
05b1cf3b80
6 changed files with 29 additions and 69 deletions
|
@ -273,19 +273,19 @@ std::string MetaFileSystem::NormalizePrefix(std::string prefix) const {
|
|||
|
||||
void MetaFileSystem::Mount(const std::string &prefix, std::shared_ptr<IFileSystem> system) {
|
||||
std::lock_guard<std::recursive_mutex> guard(lock);
|
||||
|
||||
MountPoint x;
|
||||
x.prefix = prefix;
|
||||
x.system = system;
|
||||
for (auto &it : fileSystems) {
|
||||
if (it.prefix == prefix) {
|
||||
// Overwrite the old mount. Don't create a new one.
|
||||
it = x;
|
||||
// Overwrite the old mount.
|
||||
// shared_ptr makes sure there's no leak.
|
||||
it.system = system;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Prefix not yet mounted, do so.
|
||||
MountPoint x;
|
||||
x.prefix = prefix;
|
||||
x.system = system;
|
||||
fileSystems.push_back(x);
|
||||
}
|
||||
|
||||
|
@ -305,17 +305,6 @@ void MetaFileSystem::Unmount(const std::string &prefix) {
|
|||
}
|
||||
}
|
||||
|
||||
bool MetaFileSystem::Remount(const std::string &prefix, std::shared_ptr<IFileSystem> system) {
|
||||
std::lock_guard<std::recursive_mutex> guard(lock);
|
||||
for (auto &it : fileSystems) {
|
||||
if (it.prefix == prefix) {
|
||||
it.system = system;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
IFileSystem *MetaFileSystem::GetSystemFromFilename(const std::string &filename) {
|
||||
size_t prefixPos = filename.find(':');
|
||||
if (prefixPos == filename.npos)
|
||||
|
|
|
@ -58,9 +58,8 @@ public:
|
|||
Reset();
|
||||
}
|
||||
|
||||
// Will replace the existing mount if already exists.
|
||||
void Mount(const std::string &prefix, std::shared_ptr<IFileSystem> system);
|
||||
// Fails if there's not already a file system at prefix.
|
||||
bool Remount(const std::string &prefix, std::shared_ptr<IFileSystem> system);
|
||||
|
||||
void UnmountAll();
|
||||
void Unmount(const std::string &prefix);
|
||||
|
|
|
@ -260,6 +260,7 @@ bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) {
|
|||
INFO_LOG(Log::Loader, "File is a PBP in a directory: %s", fileLoader->GetPath().c_str());
|
||||
IdentifiedFileType ebootType = Identify_File(fileLoader, error_string);
|
||||
if (ebootType == IdentifiedFileType::PSP_ISO_NP) {
|
||||
MountGameISO(fileLoader);
|
||||
InitMemoryForGameISO(fileLoader);
|
||||
pspFileSystem.SetStartingDirectory("disc0:/PSP_GAME/USRDIR");
|
||||
return Load_PSP_ISO(fileLoader, error_string);
|
||||
|
@ -386,8 +387,8 @@ bool UmdReplace(const Path &filepath, FileLoader **fileLoader, std::string &erro
|
|||
|
||||
FileLoader *loadedFile = ConstructFileLoader(filepath);
|
||||
|
||||
if (!loadedFile->Exists()) {
|
||||
error = loadedFile->GetPath().ToVisualString() + " doesn't exist";
|
||||
if (!loadedFile || !loadedFile->Exists()) {
|
||||
error = loadedFile ? (loadedFile->GetPath().ToVisualString() + " doesn't exist") : "no loaded file";
|
||||
delete loadedFile;
|
||||
return false;
|
||||
}
|
||||
|
@ -404,8 +405,8 @@ bool UmdReplace(const Path &filepath, FileLoader **fileLoader, std::string &erro
|
|||
case IdentifiedFileType::PSP_ISO:
|
||||
case IdentifiedFileType::PSP_ISO_NP:
|
||||
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
||||
if (!ReInitMemoryForGameISO(loadedFile)) {
|
||||
error = "reinit memory failed";
|
||||
if (!MountGameISO(loadedFile)) {
|
||||
error = "mounting the new ISO failed";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -65,14 +65,7 @@ static void UseLargeMem(int memsize) {
|
|||
}
|
||||
}
|
||||
|
||||
// We gather the game info before actually loading/booting the ISO
|
||||
// to determine if the emulator should enable extra memory and
|
||||
// double-sized texture coordinates.
|
||||
void InitMemoryForGameISO(FileLoader *fileLoader) {
|
||||
if (!fileLoader->Exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool MountGameISO(FileLoader *fileLoader) {
|
||||
std::shared_ptr<IFileSystem> fileSystem;
|
||||
std::shared_ptr<IFileSystem> blockSystem;
|
||||
|
||||
|
@ -81,21 +74,27 @@ void InitMemoryForGameISO(FileLoader *fileLoader) {
|
|||
blockSystem = fileSystem;
|
||||
} else {
|
||||
auto bd = constructBlockDevice(fileLoader);
|
||||
// Can't init anything without a block device...
|
||||
if (!bd)
|
||||
return;
|
||||
if (!bd) {
|
||||
// Can only fail if the ISO is bad.
|
||||
return false;
|
||||
}
|
||||
|
||||
fileSystem = std::make_shared<ISOFileSystem>(&pspFileSystem, bd);
|
||||
blockSystem = std::make_shared<ISOBlockSystem>(fileSystem);
|
||||
auto iso = std::make_shared<ISOFileSystem>(&pspFileSystem, bd);
|
||||
fileSystem = iso;
|
||||
blockSystem = std::make_shared<ISOBlockSystem>(iso);
|
||||
}
|
||||
|
||||
pspFileSystem.Mount("umd0:", blockSystem);
|
||||
pspFileSystem.Mount("umd1:", blockSystem);
|
||||
pspFileSystem.Mount("disc0:", fileSystem);
|
||||
pspFileSystem.Mount("umd:", blockSystem);
|
||||
// TODO: Should we do this?
|
||||
//pspFileSystem.Mount("host0:", fileSystem);
|
||||
pspFileSystem.Mount("disc0:", fileSystem);
|
||||
return true;
|
||||
}
|
||||
|
||||
// We gather the game info before actually loading/booting the ISO
|
||||
// to determine if the emulator should enable extra memory and
|
||||
// double-sized texture coordinates.
|
||||
void InitMemoryForGameISO(FileLoader *fileLoader) {
|
||||
std::string gameID;
|
||||
std::string umdData;
|
||||
|
||||
|
@ -135,35 +134,6 @@ void InitMemoryForGameISO(FileLoader *fileLoader) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ReInitMemoryForGameISO(FileLoader *fileLoader) {
|
||||
if (!fileLoader->Exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<IFileSystem> fileSystem;
|
||||
std::shared_ptr<IFileSystem> blockSystem;
|
||||
|
||||
if (fileLoader->IsDirectory()) {
|
||||
fileSystem = std::make_shared<VirtualDiscFileSystem>(&pspFileSystem, fileLoader->GetPath());
|
||||
blockSystem = fileSystem;
|
||||
} else {
|
||||
auto bd = constructBlockDevice(fileLoader);
|
||||
if (!bd)
|
||||
return false;
|
||||
|
||||
auto iso = std::make_shared<ISOFileSystem>(&pspFileSystem, bd);
|
||||
fileSystem = iso;
|
||||
blockSystem = std::make_shared<ISOBlockSystem>(iso);
|
||||
}
|
||||
|
||||
pspFileSystem.Remount("umd0:", blockSystem);
|
||||
pspFileSystem.Remount("umd1:", blockSystem);
|
||||
pspFileSystem.Remount("umd:", blockSystem);
|
||||
pspFileSystem.Remount("disc0:", fileSystem);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitMemoryForGamePBP(FileLoader *fileLoader) {
|
||||
if (!fileLoader->Exists()) {
|
||||
return;
|
||||
|
|
|
@ -25,6 +25,6 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string);
|
|||
bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string);
|
||||
bool Load_PSP_GE_Dump(FileLoader *fileLoader, std::string *error_string);
|
||||
void InitMemoryForGameISO(FileLoader *fileLoader);
|
||||
bool ReInitMemoryForGameISO(FileLoader *fileLoader);
|
||||
bool MountGameISO(FileLoader *fileLoader);
|
||||
void InitMemoryForGamePBP(FileLoader *fileLoader);
|
||||
void PSPLoaders_Shutdown();
|
||||
|
|
|
@ -243,6 +243,7 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy
|
|||
case IdentifiedFileType::PSP_ISO:
|
||||
case IdentifiedFileType::PSP_ISO_NP:
|
||||
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
||||
MountGameISO(loadedFile);
|
||||
InitMemoryForGameISO(loadedFile);
|
||||
break;
|
||||
case IdentifiedFileType::PSP_PBP:
|
||||
|
|
Loading…
Add table
Reference in a new issue