Merge pull request #131 from lioncash/file-monitor-simplifications
Simplify ShowSound() in FileMonitor.cpp.
This commit is contained in:
commit
d1ccd964cd
|
@ -6,6 +6,7 @@
|
|||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Common.h"
|
||||
|
@ -30,38 +31,38 @@ 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<std::string> extensions = {
|
||||
".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
|
||||
".ogg", // Tony Hawk's Underground 2
|
||||
".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 +70,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 +149,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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue