summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/FileMonitor.cpp
diff options
context:
space:
mode:
authorlioncash <mathew1800@gmail.com>2014-03-04 08:39:25 -0500
committerlioncash <mathew1800@gmail.com>2014-03-04 08:39:25 -0500
commitf39c757edf93673f8e1792d16481a61d901a0af6 (patch)
tree7dc6fc7221688e18ca699eaf4301e1da1624123c /Source/Core/DiscIO/FileMonitor.cpp
parent6fa39c28fe9f8d9b907bfd3c90b8882db4e223bc (diff)
Simplify ShowSound() in FileMonitor.cpp.
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.
Diffstat (limited to 'Source/Core/DiscIO/FileMonitor.cpp')
-rw-r--r--Source/Core/DiscIO/FileMonitor.cpp74
1 files changed, 39 insertions, 35 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 <cctype>
#include <cstring>
#include <string>
+#include <unordered_set>
#include <vector>
#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);
-
- 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
-
- || (Ending == ".brstm") // Wii Sports, Wario Land, etc
- || (Ending == ".sad") // Disaster
- )
- return true;
-
- return false;
+ std::string extension;
+ SplitPath(filename, NULL, NULL, &extension);
+ std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
+
+ std::unordered_set<std::string> 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
+ };
+
+ 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;