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.
This commit is contained in:
lioncash 2014-03-04 08:39:25 -05:00
parent 6fa39c28fe
commit f39c757edf
2 changed files with 41 additions and 37 deletions

View File

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

View File

@ -11,10 +11,10 @@
namespace FileMon namespace FileMon
{ {
void ShowSound(std::string File); bool IsSoundFile(const std::string& filename);
void ReadGC(std::string File); void ReadGC(const std::string& file);
void CheckFile(std::string File, u64 Size); void CheckFile(const std::string& file, u64 size);
void FindFilename(u64 Offset); void FindFilename(u64 offset);
void Close(); void Close();
} }