diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index b1b3f5f7a5..970949ad3a 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -651,42 +651,6 @@ void __IoInit() { asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify); syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify); - // TODO(scoped): This won't work if memStickDirectory points at the contents of /PSP... -#if defined(USING_WIN_UI) || defined(APPLE) - auto flash0System = std::make_shared(&pspFileSystem, g_Config.flash0Directory, FileSystemFlags::FLASH); -#else - auto flash0System = std::make_shared(&pspFileSystem, "flash0"); -#endif - FileSystemFlags memstickFlags = FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD; - - Path pspDir = GetSysDirectory(DIRECTORY_PSP); - if (pspDir == g_Config.memStickDirectory) { - // Initially tried to do this with dual mounts, but failed due to save state compatibility issues. - INFO_LOG(Log::sceIo, "Enabling /PSP compatibility mode"); - memstickFlags |= FileSystemFlags::STRIP_PSP; - } - - auto memstickSystem = std::make_shared(&pspFileSystem, g_Config.memStickDirectory, memstickFlags); - - pspFileSystem.Mount("ms0:", memstickSystem); - pspFileSystem.Mount("fatms0:", memstickSystem); - pspFileSystem.Mount("fatms:", memstickSystem); - pspFileSystem.Mount("pfat0:", memstickSystem); - - pspFileSystem.Mount("flash0:", flash0System); - - if (g_RemasterMode) { - const std::string gameId = g_paramSFO.GetDiscID(); - const Path exdataPath = GetSysDirectory(DIRECTORY_EXDATA) / gameId; - if (File::Exists(exdataPath)) { - auto exdataSystem = std::make_shared(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD); - pspFileSystem.Mount("exdata0:", exdataSystem); - INFO_LOG(Log::sceIo, "Mounted exdata/%s/ under memstick for exdata0:/", gameId.c_str()); - } else { - INFO_LOG(Log::sceIo, "Did not find exdata/%s/ under memstick for exdata0:/", gameId.c_str()); - } - } - __KernelListenThreadEnd(&TellFsThreadEnded); memset(fds, 0, sizeof(fds)); @@ -703,6 +667,30 @@ void __IoInit() { lastMemStickFatState = MemoryStick_FatState(); } +void __IoShutdown() { + ioManagerThreadEnabled = false; + ioManager.SyncThread(); + ioManager.FinishEventLoop(); + if (ioManagerThread.joinable()) { + ioManagerThread.join(); + ioManager.Shutdown(); + } + + for (int i = 0; i < PSP_COUNT_FDS; ++i) { + asyncParams[i].op = IoAsyncOp::NONE; + asyncParams[i].priority = -1; + if (asyncThreads[i]) + asyncThreads[i]->Forget(); + delete asyncThreads[i]; + asyncThreads[i] = nullptr; + } + asyncDefaultPriority = -1; + + MemoryStick_Shutdown(); + memStickCallbacks.clear(); + memStickFatCallbacks.clear(); +} + void __IoDoState(PointerWrap &p) { auto s = p.Section("sceIo", 1, 5); if (!s) @@ -771,37 +759,6 @@ void __IoDoState(PointerWrap &p) { } } -void __IoShutdown() { - ioManagerThreadEnabled = false; - ioManager.SyncThread(); - ioManager.FinishEventLoop(); - if (ioManagerThread.joinable()) { - ioManagerThread.join(); - ioManager.Shutdown(); - } - - for (int i = 0; i < PSP_COUNT_FDS; ++i) { - asyncParams[i].op = IoAsyncOp::NONE; - asyncParams[i].priority = -1; - if (asyncThreads[i]) - asyncThreads[i]->Forget(); - delete asyncThreads[i]; - asyncThreads[i] = nullptr; - } - asyncDefaultPriority = -1; - - pspFileSystem.Unmount("ms0:"); - pspFileSystem.Unmount("fatms0:"); - pspFileSystem.Unmount("fatms:"); - pspFileSystem.Unmount("pfat0:"); - pspFileSystem.Unmount("flash0:"); - pspFileSystem.Unmount("exdata0:"); - - MemoryStick_Shutdown(); - memStickCallbacks.clear(); - memStickFatCallbacks.clear(); -} - static std::string IODetermineFilename(const FileNode *f) { uint64_t offset = pspFileSystem.GetSeekPos(f->handle); if ((pspFileSystem.DevType(f->handle) & PSPDevType::BLOCK) != 0) { diff --git a/Core/System.cpp b/Core/System.cpp index e33ef65b1e..fe22a31080 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -63,15 +63,15 @@ #include "Core/CoreTiming.h" #include "Core/CoreParameter.h" #include "Core/FileLoaders/RamCachingFileLoader.h" -#include "Core/LuaContext.h" #include "Core/FileSystems/MetaFileSystem.h" +#include "Core/FileSystems/ISOFileSystem.h" +#include "Core/FileSystems/DirectoryFileSystem.h" +#include "Core/LuaContext.h" #include "Core/Loaders.h" #include "Core/PSPLoaders.h" -#include "Core/FileSystems/ISOFileSystem.h" #include "Core/ELF/ParamSFO.h" #include "Core/SaveState.h" #include "Core/Util/RecentFiles.h" -#include "Common/StringUtils.h" #include "Common/ExceptionHandlerSetup.h" #include "GPU/GPUCommon.h" #include "GPU/Debugger/Playback.h" @@ -276,6 +276,44 @@ static void ShowCompatWarnings(const Compatibility &compat) { extern const std::string INDEX_FILENAME; +static void MountFileSystems() { + // TODO(scoped): This won't work if memStickDirectory points at the contents of /PSP... +#if defined(USING_WIN_UI) || defined(APPLE) + auto flash0System = std::make_shared(&pspFileSystem, g_Config.flash0Directory, FileSystemFlags::FLASH); +#else + auto flash0System = std::make_shared(&pspFileSystem, "flash0"); +#endif + FileSystemFlags memstickFlags = FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD; + + Path pspDir = GetSysDirectory(DIRECTORY_PSP); + if (pspDir == g_Config.memStickDirectory) { + // Initially tried to do this with dual mounts, but failed due to save state compatibility issues. + INFO_LOG(Log::sceIo, "Enabling /PSP compatibility mode"); + memstickFlags |= FileSystemFlags::STRIP_PSP; + } + + auto memstickSystem = std::make_shared(&pspFileSystem, g_Config.memStickDirectory, memstickFlags); + + pspFileSystem.Mount("ms0:", memstickSystem); + pspFileSystem.Mount("fatms0:", memstickSystem); + pspFileSystem.Mount("fatms:", memstickSystem); + pspFileSystem.Mount("pfat0:", memstickSystem); + + pspFileSystem.Mount("flash0:", flash0System); + + if (g_RemasterMode) { + const std::string gameId = g_paramSFO.GetDiscID(); + const Path exdataPath = GetSysDirectory(DIRECTORY_EXDATA) / gameId; + if (File::Exists(exdataPath)) { + auto exdataSystem = std::make_shared(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD); + pspFileSystem.Mount("exdata0:", exdataSystem); + INFO_LOG(Log::sceIo, "Mounted exdata/%s/ under memstick for exdata0:/", gameId.c_str()); + } else { + INFO_LOG(Log::sceIo, "Did not find exdata/%s/ under memstick for exdata0:/", gameId.c_str()); + } + } +} + // NOTE: The loader has already been fully resolved (ResolveFileLoaderTarget) and identified here. static bool CPU_Init(FileLoader *fileLoader, IdentifiedFileType type, std::string *errorString) { // Default memory settings @@ -449,6 +487,8 @@ static bool CPU_Init(FileLoader *fileLoader, IdentifiedFileType type, std::strin g_CoreParameter.mountIsoLoader = ConstructFileLoader(g_CoreParameter.mountIso); } + MountFileSystems(); + // Game-specific settings are load from for example Load_PSP_ISO (which calls g_Config.LoadGameConfig). // We can't do things that depend on these before the below switch. So for example, the adjustment of the GPU core // to software has now been moved below it. @@ -541,7 +581,8 @@ void CPU_Shutdown(bool success) { DisplayHWShutdown(); - pspFileSystem.Shutdown(); + pspFileSystem.Shutdown(); // This unmounts all filesystems. + mipsr4k.Shutdown(); Memory::Shutdown(); HLEPlugins::Shutdown();