From 7832cebacd3d0d5b3275ccd9671ef20fc3efaaa5 Mon Sep 17 00:00:00 2001 From: shenweip Date: Sun, 24 Nov 2013 16:08:05 +0800 Subject: [PATCH] CleanUp. --- Core/FileSystems/MetaFileSystem.cpp | 13 +++++++++++++ Core/FileSystems/MetaFileSystem.h | 3 +++ Core/HLE/sceUmd.cpp | 26 +++++++++++++++----------- Core/HLE/sceUmd.h | 1 + Core/PSPLoaders.cpp | 3 --- UI/MainScreen.cpp | 6 ++---- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index 898af97f41..6a7ba635b9 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -255,6 +255,19 @@ void MetaFileSystem::Unmount(std::string prefix, IFileSystem *system) fileSystems.erase(std::remove(fileSystems.begin(), fileSystems.end(), x), fileSystems.end()); } +void MetaFileSystem::Remount(std::string prefix, IFileSystem *oldSystem, IFileSystem *newSystem) { + Unmount(prefix, oldSystem); + Mount(prefix, newSystem); +} + +IFileSystem *MetaFileSystem::GetSystem(const std::string &prefix) { + for (auto it = fileSystems.begin(); it != fileSystems.end(); ++it) { + if (it->prefix == prefix) + return it->system; + } + return NULL; +} + void MetaFileSystem::Shutdown() { lock_guard guard(lock); diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index b7d99ebc51..1191f0a1e4 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -51,6 +51,9 @@ public: void Mount(std::string prefix, IFileSystem *system); void Unmount(std::string prefix, IFileSystem *system); + void Remount(std::string prefix, IFileSystem *oldSystem, IFileSystem *newSystem); + + IFileSystem *GetSystem(const std::string &prefix); void ThreadEnded(int threadID); diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index bb3bf6040d..e4f8624035 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -42,7 +42,6 @@ static int umdStatChangeEvent = -1; static std::vector umdWaitingThreads; static std::map umdPausedWaits; -extern IFileSystem* currentUMD; bool UMDReplacePermit = false; struct PspUmdInfo { @@ -444,11 +443,10 @@ u32 sceUmdGetErrorStat() } void __UmdReplace(std::string filepath) { - // Unmount old umd first. - pspFileSystem.Unmount("umd0:", currentUMD); - pspFileSystem.Unmount("umd1:", currentUMD); - pspFileSystem.Unmount("disc0:", currentUMD); - pspFileSystem.Unmount("umd:", currentUMD); + // Only get system from disc0 seems have been enough. + IFileSystem* currentUMD = pspFileSystem.GetSystem("disc0:"); + if (!currentUMD) + return; IFileSystem* umd2; FileInfo info; @@ -462,17 +460,23 @@ void __UmdReplace(std::string filepath) { return; umd2 = new ISOFileSystem(&pspFileSystem, bd); - pspFileSystem.Mount("umd0:", umd2); - pspFileSystem.Mount("umd1:", umd2); - pspFileSystem.Mount("disc0:", umd2); - pspFileSystem.Mount("umd:", umd2); + pspFileSystem.Remount("umd0:", currentUMD, umd2); + pspFileSystem.Remount("umd1:", currentUMD, umd2); + pspFileSystem.Remount("disc0:", currentUMD, umd2); + pspFileSystem.Remount("umd:", currentUMD, umd2); } - currentUMD = umd2; // Change current umd. + delete currentUMD; + + // TODO Is this always correct if UMD was not activated? u32 notifyArg = PSP_UMD_PRESENT | PSP_UMD_READABLE | PSP_UMD_CHANGED; if (driveCBId != -1) __KernelNotifyCallback(driveCBId, notifyArg); } +bool getUMDReplacePermit() { + return UMDReplacePermit; +} + u32 sceUmdReplaceProhibit() { UMDReplacePermit = false; diff --git a/Core/HLE/sceUmd.h b/Core/HLE/sceUmd.h index 235bf7a916..246d6384b2 100644 --- a/Core/HLE/sceUmd.h +++ b/Core/HLE/sceUmd.h @@ -42,5 +42,6 @@ void __UmdInit(); void __UmdDoState(PointerWrap &p); void __UmdReplace(std::string filepath); +bool getUMDReplacePermit(); void Register_sceUmdUser(); diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index f69db2b2d3..0f0e825bca 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -42,7 +42,6 @@ #include "HLE/sceKernelMemory.h" #include "ELF/ParamSFO.h" -IFileSystem* currentUMD; // 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. @@ -73,7 +72,6 @@ void InitMemoryForGameISO(std::string fileToStart) { pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); - currentUMD = umd2; std::string gameID; @@ -208,7 +206,6 @@ bool Load_PSP_ELF_PBP(const char *filename, std::string *error_string) pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); - currentUMD = umd2; } } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 0aa63d250b..b42261eeaa 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -513,7 +513,7 @@ void MainScreen::CreateViews() { root_ = new LinearLayout(ORIENT_HORIZONTAL); leftColumn->ReplaceLayoutParams(new LinearLayoutParams(1.0)); rightColumn->ReplaceLayoutParams(new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins)); - root_->Add(leftColumn); + root_->Add(leftColumn); root_->Add(rightColumn); } @@ -705,8 +705,6 @@ GamePauseScreen::~GamePauseScreen() { } } -extern bool UMDReplacePermit; - void GamePauseScreen::CreateViews() { static const int NUM_SAVESLOTS = 5; @@ -757,7 +755,7 @@ void GamePauseScreen::CreateViews() { rightColumn->Add(rightColumnItems); rightColumnItems->SetSpacing(0.0f); - if (UMDReplacePermit) { + if (getUMDReplacePermit()) { rightColumnItems->Add(new Choice(i->T("Switch UMD")))->OnClick.Handle(this, &GamePauseScreen::OnSwitchUMD); } rightColumnItems->Add(new Choice(i->T("Continue")))->OnClick.Handle(this, &UIScreen::OnBack);