From f39c757edf93673f8e1792d16481a61d901a0af6 Mon Sep 17 00:00:00 2001 From: lioncash Date: Tue, 4 Mar 2014 08:39:25 -0500 Subject: [PATCH 1/2] Simplify ShowSound() in FileMonitor.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now if more sound types are found, they just need to simply be added to the unordered set. - Also changed ShowSound() to IsSoundFile() - Fixed IsSoundFile’s definition in FileMonitor.h. This whole time it has been defined as a void method, when in reality it was a bool function. - Changed the FileMonitor’s string parameters to be constant references. --- Source/Core/DiscIO/FileMonitor.cpp | 70 ++++++++++++++++-------------- Source/Core/DiscIO/FileMonitor.h | 8 ++-- 2 files changed, 41 insertions(+), 37 deletions(-) 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(); } From 2c8b9735ae52471a36a33c5bf37c4487eb96367a Mon Sep 17 00:00:00 2001 From: lioncash Date: Tue, 4 Mar 2014 08:57:07 -0500 Subject: [PATCH 2/2] Add two other formats to the list of extensions in IsSoundFile .adx is used in various games, so this should definitely be here. --- Source/Core/DiscIO/FileMonitor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Core/DiscIO/FileMonitor.cpp b/Source/Core/DiscIO/FileMonitor.cpp index 63f4dddf56..cc0a345838 100644 --- a/Source/Core/DiscIO/FileMonitor.cpp +++ b/Source/Core/DiscIO/FileMonitor.cpp @@ -38,12 +38,14 @@ bool IsSoundFile(const std::string& filename) std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); std::unordered_set extensions = { - ".adp", // 1080 Avalanche, Crash Bandicoot, etc + ".adp", // 1080 Avalanche, Crash Bandicoot, etc. + ".adx", // Sonic Adventure 2 Battle, etc. ".afc", // Zelda WW ".ast", // Zelda TP, Mario Kart + ".brstm", // Wii Sports, Wario Land, etc. ".dsp", // Metroid Prime ".hps", // SSB Melee - ".brstm", // Wii Sports, Wario Land, etc. + ".ogg", // Tony Hawk's Underground 2 ".sad" // Disaster };