StringUtil cleanup. Nothing seems broken.
[dolphin.git] / Source / Core / DiscIO / Src / FileMonitor.cpp
blobc05bd3f22cfe4f28dae2ae2a83483dafedcf8128
1 // Copyright (C) 2003-2008 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
19 // -----------
20 // Include
22 #include "stdafx.h"
23 #include <iostream>
24 #include <vector>
25 #include <string>
26 #include <algorithm>
29 #include "Common.h" // Common
30 #include "IniFile.h"
31 #include "LogManager.h"
33 #include "../../Core/Src/Core.h"
34 #include "../../Core/Src/ConfigManager.h"
35 #include "FileSystemGCWii.h"
36 #include "VolumeCreator.h"
38 namespace FileMon
41 DiscIO::IVolume *OpenISO = NULL;
42 DiscIO::IFileSystem *pFileSystem = NULL;
43 std::vector<const DiscIO::SFileInfo *> GCFiles;
44 std::string ISOFile = "", CurrentFile = "";
45 bool FileAccess = true;
47 // Filtered files
48 bool ShowSound(std::string FileName)
50 std::string Ending;
51 SplitPath(FileName, NULL, NULL, &Ending);
52 std::transform(Ending.begin(),Ending.end(),Ending.begin(),::tolower);
54 if (
55 (Ending == ".adp") // 1080 Avalanche, Crash Bandicoot, etc
56 || (Ending == ".afc") // Zelda WW
57 || (Ending == ".ast") // Zelda TP, Mario Kart
58 || (Ending == ".dsp") // Metroid Prime
59 || (Ending == ".hps") // SSB Melee
61 || (Ending == ".brstm") // Wii Sports, Wario Land, etc
62 || (Ending == ".sad") // Disaster
64 return true;
66 return false;
70 // Read the GC file system
71 void ReadGC(std::string FileName)
73 // Should have an actual Shutdown procedure or something
74 if(OpenISO != NULL)
76 delete OpenISO;
77 OpenISO = NULL;
79 if(pFileSystem != NULL)
81 delete pFileSystem;
82 pFileSystem = NULL;
84 // GCFiles' pointers are no longer valid after pFileSystem is cleared
85 GCFiles.clear();
86 OpenISO = DiscIO::CreateVolumeFromFilename(FileName);
87 if (!OpenISO) return;
88 if (!DiscIO::IsVolumeWiiDisc(OpenISO) && !DiscIO::IsVolumeWadFile(OpenISO))
90 pFileSystem = DiscIO::CreateFileSystem(OpenISO);
91 if(!pFileSystem) return;
92 pFileSystem->GetFileList(GCFiles);
94 FileAccess = true;
97 // Check if we should play this file
98 void CheckFile(std::string File, u64 Size)
100 // Don't do anything if the log is unselected
101 if (!LogManager::GetInstance()->isEnable(LogTypes::FILEMON)) return;
102 // Do nothing if we found the same file again
103 if (CurrentFile == File) return;
105 if (Size > 0) Size = (Size / 1000);
106 std::string Str = StringFromFormat("%s kB %s", ThousandSeparate(Size, 7).c_str(), File.c_str());
107 if (ShowSound(File))
109 NOTICE_LOG(FILEMON, Str.c_str());
111 else
113 WARN_LOG(FILEMON, Str.c_str());
116 // Update the current file
117 CurrentFile = File;
121 // Find the GC filename
122 void FindFilename(u64 offset)
124 // Don't do anything if a game is not running
125 if (Core::GetState() != Core::CORE_RUN) return;
126 // Or if the log is unselected
127 if (!LogManager::GetInstance()->isEnable(LogTypes::FILEMON)) return;
128 if (!FileAccess) return;
130 if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename)
132 FileAccess = false;
133 ReadGC(SConfig::GetInstance().m_LastFilename);
134 ISOFile = SConfig::GetInstance().m_LastFilename;
135 NOTICE_LOG(FILEMON, "Opening '%s'", ISOFile.c_str());
136 return;
139 const char *fname = pFileSystem->GetFileName(offset);
141 // There's something wrong with the paths
142 if (!fname || (strlen(fname) == 512))
143 return;
145 CheckFile(fname, pFileSystem->GetFileSize(fname));
148 void Close()
150 if(OpenISO != NULL)
152 delete OpenISO;
153 OpenISO = NULL;
156 if(pFileSystem != NULL)
158 delete pFileSystem;
159 pFileSystem = NULL;
162 // GCFiles' pointers are no longer valid after pFileSystem is cleared
163 GCFiles.clear();
165 ISOFile = "";
166 CurrentFile = "";
167 FileAccess = true;
171 } // FileMon