| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | // Copyright (C) 2003-2008 Dolphin Project.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, version 2.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU General Public License 2.0 for more details.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A copy of the GPL 2.0 should have been included with the program.
 | 
					
						
							|  |  |  | // If not, see http://www.gnu.org/licenses/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Official SVN repository and contact information can be found at
 | 
					
						
							|  |  |  | // http://code.google.com/p/dolphin-emu/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-22 06:00:36 +00:00
										 |  |  | #include "Common.h"
 | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | #include "IniFile.h"
 | 
					
						
							|  |  |  | #include "LogManager.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../../Core/Src/Core.h"
 | 
					
						
							|  |  |  | #include "../../Core/Src/ConfigManager.h"
 | 
					
						
							|  |  |  | #include "FileSystemGCWii.h"
 | 
					
						
							|  |  |  | #include "VolumeCreator.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FileMon | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DiscIO::IVolume *OpenISO = NULL; | 
					
						
							|  |  |  | DiscIO::IFileSystem *pFileSystem = NULL; | 
					
						
							|  |  |  | std::vector<const DiscIO::SFileInfo *> GCFiles; | 
					
						
							|  |  |  | std::string ISOFile = "", CurrentFile = ""; | 
					
						
							|  |  |  | bool FileAccess = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Filtered files
 | 
					
						
							|  |  |  | bool ShowSound(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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Read the GC file system
 | 
					
						
							|  |  |  | void ReadGC(std::string FileName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Should have an actual Shutdown procedure or something
 | 
					
						
							|  |  |  | 	if(OpenISO != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete OpenISO; | 
					
						
							|  |  |  | 		OpenISO = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(pFileSystem != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete pFileSystem; | 
					
						
							|  |  |  | 		pFileSystem = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// GCFiles' pointers are no longer valid after pFileSystem is cleared
 | 
					
						
							|  |  |  | 	GCFiles.clear(); | 
					
						
							|  |  |  | 	OpenISO = DiscIO::CreateVolumeFromFilename(FileName); | 
					
						
							|  |  |  | 	if (!OpenISO) return; | 
					
						
							|  |  |  | 	if (!DiscIO::IsVolumeWiiDisc(OpenISO) && !DiscIO::IsVolumeWadFile(OpenISO)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		pFileSystem = DiscIO::CreateFileSystem(OpenISO); | 
					
						
							|  |  |  | 		if(!pFileSystem) return; | 
					
						
							|  |  |  | 		pFileSystem->GetFileList(GCFiles); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	FileAccess = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Check if we should play this file
 | 
					
						
							|  |  |  | void CheckFile(std::string File, u64 Size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Don't do anything if the log is unselected
 | 
					
						
							| 
									
										
										
										
											2011-04-01 07:43:02 +00:00
										 |  |  | 	if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON)) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 	// Do nothing if we found the same file again
 | 
					
						
							| 
									
										
										
										
											2011-04-01 07:43:02 +00:00
										 |  |  | 	if (CurrentFile == File) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (Size > 0) Size = (Size / 1000); | 
					
						
							| 
									
										
										
										
											2010-11-10 04:12:31 +00:00
										 |  |  | 	std::string Str = StringFromFormat("%s kB %s", ThousandSeparate(Size, 7).c_str(), File.c_str()); | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 	if (ShowSound(File)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-02-02 21:52:43 +00:00
										 |  |  | 		INFO_LOG(FILEMON, "%s", Str.c_str()); | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-12-05 09:04:34 +00:00
										 |  |  | 		WARN_LOG(FILEMON, "%s", Str.c_str()); | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Update the current file
 | 
					
						
							|  |  |  | 	CurrentFile = File; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Find the GC filename
 | 
					
						
							|  |  |  | void FindFilename(u64 offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Don't do anything if a game is not running
 | 
					
						
							|  |  |  | 	if (Core::GetState() != Core::CORE_RUN) return; | 
					
						
							|  |  |  | 	// Or if the log is unselected
 | 
					
						
							| 
									
										
										
										
											2011-04-01 07:43:02 +00:00
										 |  |  | 	if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON)) return; | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 	if (!FileAccess) return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		FileAccess = false; | 
					
						
							|  |  |  | 		ReadGC(SConfig::GetInstance().m_LastFilename); | 
					
						
							|  |  |  | 		ISOFile = SConfig::GetInstance().m_LastFilename; | 
					
						
							| 
									
										
										
										
											2011-02-02 18:21:20 +00:00
										 |  |  | 		INFO_LOG(FILEMON, "Opening '%s'", ISOFile.c_str()); | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const char *fname = pFileSystem->GetFileName(offset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// There's something wrong with the paths
 | 
					
						
							|  |  |  | 	if (!fname || (strlen(fname) == 512)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	CheckFile(fname, pFileSystem->GetFileSize(fname)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Close() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(OpenISO != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete OpenISO; | 
					
						
							|  |  |  | 		OpenISO = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(pFileSystem != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete pFileSystem; | 
					
						
							|  |  |  | 		pFileSystem = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// GCFiles' pointers are no longer valid after pFileSystem is cleared
 | 
					
						
							|  |  |  | 	GCFiles.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ISOFile = ""; | 
					
						
							|  |  |  | 	CurrentFile = ""; | 
					
						
							|  |  |  | 	FileAccess = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // FileMon
 |