diff --git a/Source/Core/DiscIO/FileMonitor.cpp b/Source/Core/DiscIO/FileMonitor.cpp index 94d0189668..63f4dddf56 100644 --- a/Source/Core/DiscIO/FileMonitor.cpp +++ b/Source/Core/DiscIO/FileMonitor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "Common/Common.h" @@ -30,38 +31,36 @@ std::string ISOFile = "", CurrentFile = ""; bool FileAccess = true; // Filtered files -bool ShowSound(std::string FileName) +bool IsSoundFile(const std::string& filename) { - std::string Ending; - SplitPath(FileName, NULL, NULL, &Ending); - std::transform(Ending.begin(),Ending.end(),Ending.begin(),::tolower); + std::string extension; + SplitPath(filename, NULL, NULL, &extension); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - if ( - (Ending == ".adp") // 1080 Avalanche, Crash Bandicoot, etc - || (Ending == ".afc") // Zelda WW - || (Ending == ".ast") // Zelda TP, Mario Kart - || (Ending == ".dsp") // Metroid Prime - || (Ending == ".hps") // SSB Melee + std::unordered_set extensions = { + ".adp", // 1080 Avalanche, Crash Bandicoot, etc + ".afc", // Zelda WW + ".ast", // Zelda TP, Mario Kart + ".dsp", // Metroid Prime + ".hps", // SSB Melee + ".brstm", // Wii Sports, Wario Land, etc. + ".sad" // Disaster + }; - || (Ending == ".brstm") // Wii Sports, Wario Land, etc - || (Ending == ".sad") // Disaster - ) - return true; - - return false; + return extensions.find(extension) != extensions.end(); } // Read the GC file system -void ReadGC(std::string FileName) +void ReadGC(const std::string& filename) { // Should have an actual Shutdown procedure or something - if(OpenISO != NULL) + if (OpenISO != NULL) { delete OpenISO; OpenISO = NULL; } - if(pFileSystem != NULL) + if (pFileSystem != NULL) { delete pFileSystem; pFileSystem = NULL; @@ -69,42 +68,47 @@ void ReadGC(std::string FileName) // GCFiles' pointers are no longer valid after pFileSystem is cleared GCFiles.clear(); - OpenISO = DiscIO::CreateVolumeFromFilename(FileName); - if (!OpenISO) return; + OpenISO = DiscIO::CreateVolumeFromFilename(filename); + if (!OpenISO) + return; + if (!DiscIO::IsVolumeWiiDisc(OpenISO) && !DiscIO::IsVolumeWadFile(OpenISO)) { pFileSystem = DiscIO::CreateFileSystem(OpenISO); - if(!pFileSystem) return; + + if (!pFileSystem) + return; + pFileSystem->GetFileList(GCFiles); } FileAccess = true; } // Check if we should play this file -void CheckFile(std::string File, u64 Size) +void CheckFile(const std::string& file, u64 size) { // Don't do anything if the log is unselected if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON)) return; // Do nothing if we found the same file again - if (CurrentFile == File) + if (CurrentFile == file) return; - if (Size > 0) - Size = (Size / 1000); + if (size > 0) + size = (size / 1000); - std::string Str = StringFromFormat("%s kB %s", ThousandSeparate(Size, 7).c_str(), File.c_str()); - if (ShowSound(File)) + std::string str = StringFromFormat("%s kB %s", ThousandSeparate(size, 7).c_str(), file.c_str()); + if (IsSoundFile(file)) { - INFO_LOG(FILEMON, "%s", Str.c_str()); + INFO_LOG(FILEMON, "%s", str.c_str()); } else { - WARN_LOG(FILEMON, "%s", Str.c_str()); + WARN_LOG(FILEMON, "%s", str.c_str()); } // Update the current file - CurrentFile = File; + CurrentFile = file; } @@ -143,13 +147,13 @@ void FindFilename(u64 offset) void Close() { - if(OpenISO != NULL) + if (OpenISO != NULL) { delete OpenISO; OpenISO = NULL; } - if(pFileSystem != NULL) + if (pFileSystem != NULL) { delete pFileSystem; pFileSystem = NULL; diff --git a/Source/Core/DiscIO/FileMonitor.h b/Source/Core/DiscIO/FileMonitor.h index f5e92f021b..6ca49b1673 100644 --- a/Source/Core/DiscIO/FileMonitor.h +++ b/Source/Core/DiscIO/FileMonitor.h @@ -11,10 +11,10 @@ namespace FileMon { -void ShowSound(std::string File); -void ReadGC(std::string File); -void CheckFile(std::string File, u64 Size); -void FindFilename(u64 Offset); +bool IsSoundFile(const std::string& filename); +void ReadGC(const std::string& file); +void CheckFile(const std::string& file, u64 size); +void FindFilename(u64 offset); void Close(); }