diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index c9704450ab..fe8a78072a 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -8,6 +8,7 @@ set(SRCS CoreTiming.cpp DSPEmulator.cpp ec_wii.cpp + FileMonitor.cpp GeckoCodeConfig.cpp GeckoCode.cpp HotkeyManager.cpp diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index dc4399fb63..c266d31189 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -64,9 +64,9 @@ #include "Core/PowerPC/GDBStub.h" #endif -#include "DiscIO/FileMonitor.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/GCAdapter.h" + #include "VideoCommon/Fifo.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/RenderBase.h" @@ -619,8 +619,6 @@ void EmuThread() if (core_parameter.bCPUThread) g_video_backend->Video_Cleanup(); - FileMon::Close(); - // We must set up this flag before executing HW::Shutdown() s_hardware_initialized = false; INFO_LOG(CONSOLE, "%s", StopMessage(false, "Shutting down HW").c_str()); diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 86edd95d87..80042e4313 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -89,6 +89,7 @@ + @@ -338,6 +339,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 18bce72497..0a3e302cca 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -281,6 +281,9 @@ FifoPlayer + + FileMonitor + GeckoCode @@ -957,6 +960,9 @@ FifoPlayer + + FileMonitor + GeckoCode diff --git a/Source/Core/Core/FileMonitor.cpp b/Source/Core/Core/FileMonitor.cpp new file mode 100644 index 0000000000..bb223cc578 --- /dev/null +++ b/Source/Core/Core/FileMonitor.cpp @@ -0,0 +1,116 @@ +// Copyright 2009 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/FileMonitor.h" + +#include +#include +#include +#include +#include + +#include "Common/CommonTypes.h" +#include "Common/Logging/Log.h" +#include "Common/Logging/LogManager.h" +#include "Common/StringUtil.h" + +#include "DiscIO/Enums.h" +#include "DiscIO/Filesystem.h" +#include "DiscIO/Volume.h" + +namespace FileMonitor +{ +static const DiscIO::IVolume* s_volume = nullptr; +static bool s_wii_disc; +static std::unique_ptr s_filesystem; +static std::string s_previous_file; + +// Filtered files +static bool IsSoundFile(const std::string& filename) +{ + std::string extension; + SplitPath(filename, nullptr, nullptr, &extension); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); + + static const std::unordered_set 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 + ".snd", // Tales of Symphonia + ".song", // Tales of Symphonia + ".ssm", // Custom Robo, Kirby Air Ride, etc. + ".str", // Harry Potter & the Sorcerer's Stone + }; + + return extensions.find(extension) != extensions.end(); +} + +void SetFileSystem(const DiscIO::IVolume* volume) +{ + // Instead of creating the file system object right away, we will let Log + // create it later once we know that it actually will get used + s_volume = volume; + + // If the volume that was passed in was nullptr, Log won't try to create a + // file system object later, so we have to set s_filesystem to nullptr right away + s_filesystem = nullptr; +} + +// Logs access to files in the file system set by SetFileSystem +void Log(u64 offset, bool decrypt) +{ + // Do nothing if the log isn't selected + if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON, LogTypes::LWARNING)) + return; + + // If a new volume has been set, use the file system of that volume + if (s_volume) + { + s_wii_disc = s_volume->GetVolumeType() == DiscIO::Platform::WII_DISC; + if (decrypt != s_wii_disc) + return; + s_filesystem = DiscIO::CreateFileSystem(s_volume); + s_volume = nullptr; + s_previous_file.clear(); + } + + // For Wii discs, FileSystemGCWii will only load file systems from encrypted partitions + if (decrypt != s_wii_disc) + return; + + // Do nothing if there is no valid file system + if (!s_filesystem) + return; + + const std::string filename = s_filesystem->GetFileName(offset); + + // Do nothing if no file was found at that offset + if (filename.empty()) + return; + + // Do nothing if we found the same file again + if (s_previous_file == filename) + return; + + const u64 size = s_filesystem->GetFileSize(filename); + const std::string size_string = ThousandSeparate(size / 1000, 7); + + const std::string log_string = + StringFromFormat("%s kB %s", size_string.c_str(), filename.c_str()); + if (IsSoundFile(filename)) + INFO_LOG(FILEMON, "%s", log_string.c_str()); + else + WARN_LOG(FILEMON, "%s", log_string.c_str()); + + // Update the last accessed file + s_previous_file = filename; +} + +} // namespace FileMonitor diff --git a/Source/Core/Core/FileMonitor.h b/Source/Core/Core/FileMonitor.h new file mode 100644 index 0000000000..abfc01d3c5 --- /dev/null +++ b/Source/Core/Core/FileMonitor.h @@ -0,0 +1,24 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "Common/CommonTypes.h" + +namespace DiscIO +{ +class IFileSystem; +class IVolume; +} + +namespace FileMonitor +{ +// Can be called with nullptr to set the file system to nothing. When not called +// with nullptr, the volume must remain valid until the next SetFileSystem call. +void SetFileSystem(const DiscIO::IVolume* volume); +// Logs access to files in the file system set by SetFileSystem +void Log(u64 offset, bool decrypt); +} diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp index fd3092309f..b2c45564ca 100644 --- a/Source/Core/Core/HW/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVDInterface.cpp @@ -17,6 +17,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" +#include "Core/FileMonitor.h" #include "Core/HW/AudioInterface.h" #include "Core/HW/DVDInterface.h" #include "Core/HW/DVDThread.h" @@ -321,9 +322,14 @@ void DoState(PointerWrap& p) if (disc_inside != IsDiscInside()) { if (disc_inside) + { PanicAlertT("An inserted disc was expected but not found."); + } else + { s_inserted_volume.reset(); + FileMonitor::SetFileSystem(nullptr); + } } } @@ -474,6 +480,7 @@ void Shutdown() { DVDThread::Stop(); s_inserted_volume.reset(); + FileMonitor::SetFileSystem(nullptr); } const DiscIO::IVolume& GetVolume() @@ -486,6 +493,7 @@ bool SetVolumeName(const std::string& disc_path) { DVDThread::WaitUntilIdle(); s_inserted_volume = DiscIO::CreateVolumeFromFilename(disc_path); + FileMonitor::SetFileSystem(s_inserted_volume.get()); SetLidOpen(); return IsDiscInside(); } @@ -496,6 +504,7 @@ bool SetVolumeDirectory(const std::string& full_path, bool is_wii, DVDThread::WaitUntilIdle(); s_inserted_volume = DiscIO::CreateVolumeFromDirectory(full_path, is_wii, apploader_path, DOL_path); + FileMonitor::SetFileSystem(s_inserted_volume.get()); SetLidOpen(); return IsDiscInside(); } @@ -513,6 +522,7 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate) { DVDThread::WaitUntilIdle(); s_inserted_volume.reset(); + FileMonitor::SetFileSystem(s_inserted_volume.get()); SetLidOpen(); } @@ -568,7 +578,9 @@ void SetLidOpen() bool ChangePartition(u64 offset) { DVDThread::WaitUntilIdle(); - return s_inserted_volume->ChangePartition(offset); + const bool success = s_inserted_volume->ChangePartition(offset); + FileMonitor::SetFileSystem(s_inserted_volume.get()); + return success; } void RegisterMMIO(MMIO::Mapping* mmio, u32 base) diff --git a/Source/Core/Core/HW/DVDThread.cpp b/Source/Core/Core/HW/DVDThread.cpp index beec9708fb..bbb930f043 100644 --- a/Source/Core/Core/HW/DVDThread.cpp +++ b/Source/Core/Core/HW/DVDThread.cpp @@ -21,6 +21,7 @@ #include "Core/Core.h" #include "Core/CoreTiming.h" +#include "Core/FileMonitor.h" #include "Core/HW/DVDInterface.h" #include "Core/HW/DVDThread.h" #include "Core/HW/Memmap.h" @@ -277,6 +278,8 @@ static void DVDThread() ReadRequest request; while (s_request_queue.Pop(request)) { + FileMonitor::Log(request.dvd_offset, request.decrypt); + std::vector buffer(request.length); const DiscIO::IVolume& volume = DVDInterface::GetVolume(); if (!volume.Read(request.dvd_offset, request.length, buffer.data(), request.decrypt)) diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index ae15f3bd6a..b8f337b5da 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -7,7 +7,6 @@ set(SRCS DriveBlob.cpp Enums.cpp FileBlob.cpp - FileMonitor.cpp FileSystemGCWii.cpp Filesystem.cpp NANDContentLoader.cpp diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj index db5ef8d44e..9ab6365e13 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj +++ b/Source/Core/DiscIO/DiscIO.vcxproj @@ -42,7 +42,6 @@ - @@ -64,7 +63,6 @@ - diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters index 382915d4b8..118169a0c9 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj.filters +++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters @@ -51,9 +51,6 @@ Volume\Blob - - Volume - Volume @@ -113,9 +110,6 @@ Volume\Blob - - Volume - Volume diff --git a/Source/Core/DiscIO/FileMonitor.cpp b/Source/Core/DiscIO/FileMonitor.cpp deleted file mode 100644 index adc29de250..0000000000 --- a/Source/Core/DiscIO/FileMonitor.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2009 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include -#include -#include -#include -#include -#include -#include - -#include "Common/CommonTypes.h" -#include "Common/Logging/LogManager.h" -#include "Common/StringUtil.h" - -#include "Core/Boot/Boot.h" -#include "Core/ConfigManager.h" -#include "Core/Core.h" - -#include "DiscIO/Enums.h" -#include "DiscIO/FileMonitor.h" -#include "DiscIO/Filesystem.h" -#include "DiscIO/Volume.h" -#include "DiscIO/VolumeCreator.h" - -namespace FileMon -{ -static std::unique_ptr s_open_iso; -static std::unique_ptr s_filesystem; -static std::string ISOFile = "", CurrentFile = ""; -static bool FileAccess = true; - -// Filtered files -bool IsSoundFile(const std::string& filename) -{ - std::string extension; - SplitPath(filename, nullptr, nullptr, &extension); - std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - - static std::unordered_set 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 - ".snd", // Tales of Symphonia - ".song", // Tales of Symphonia - ".ssm", // Custom Robo, Kirby Air Ride, etc. - ".str", // Harry Potter & the Sorcerer's Stone - }; - - return extensions.find(extension) != extensions.end(); -} - -// Read the file system -void ReadFileSystem(const std::string& filename) -{ - // Should have an actual Shutdown procedure or something - s_open_iso.reset(); - s_filesystem.reset(); - - s_open_iso = DiscIO::CreateVolumeFromFilename(filename); - if (!s_open_iso) - return; - - if (s_open_iso->GetVolumeType() != DiscIO::Platform::WII_WAD) - { - s_filesystem = DiscIO::CreateFileSystem(s_open_iso.get()); - - if (!s_filesystem) - return; - } - - FileAccess = true; -} - -// Logs a file if it passes a few checks -void CheckFile(const std::string& file, u64 size) -{ - // Don't do anything if the log is unselected - if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON, LogTypes::LWARNING)) - return; - // Do nothing if we found the same file again - if (CurrentFile == file) - return; - - if (size > 0) - size = (size / 1000); - - 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()); - } - else - { - WARN_LOG(FILEMON, "%s", str.c_str()); - } - - // Update the current file - CurrentFile = file; -} - -// Find the filename -void FindFilename(u64 offset) -{ - // Don't do anything if a game is not running - if (Core::GetState() != Core::State::Running) - return; - - // Or if the log is unselected - if (!LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON, LogTypes::LWARNING)) - return; - - // Or if we don't have file access - if (!FileAccess) - return; - - if (!s_filesystem || ISOFile != SConfig::GetInstance().m_LastFilename) - { - FileAccess = false; - ReadFileSystem(SConfig::GetInstance().m_LastFilename); - ISOFile = SConfig::GetInstance().m_LastFilename; - INFO_LOG(FILEMON, "Opening '%s'", ISOFile.c_str()); - return; - } - - const std::string filename = s_filesystem->GetFileName(offset); - - if (filename.empty()) - return; - - CheckFile(filename, s_filesystem->GetFileSize(filename)); -} - -void Close() -{ - s_open_iso.reset(); - s_filesystem.reset(); - - ISOFile = ""; - CurrentFile = ""; - FileAccess = true; -} - -} // FileMon diff --git a/Source/Core/DiscIO/FileMonitor.h b/Source/Core/DiscIO/FileMonitor.h deleted file mode 100644 index 0e73152947..0000000000 --- a/Source/Core/DiscIO/FileMonitor.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include - -#include "Common/CommonTypes.h" - -namespace FileMon -{ -bool IsSoundFile(const std::string& filename); -void ReadFileSystem(const std::string& file); -void CheckFile(const std::string& file, u64 size); -void FindFilename(u64 offset); -void Close(); -} diff --git a/Source/Core/DiscIO/Filesystem.cpp b/Source/Core/DiscIO/Filesystem.cpp index 48da2b6e23..48c9a33b6f 100644 --- a/Source/Core/DiscIO/Filesystem.cpp +++ b/Source/Core/DiscIO/Filesystem.cpp @@ -18,6 +18,9 @@ IFileSystem::~IFileSystem() std::unique_ptr CreateFileSystem(const IVolume* volume) { + if (!volume) + return nullptr; + std::unique_ptr filesystem = std::make_unique(volume); if (!filesystem) diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 9f93aa0331..8668b2b936 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -19,7 +19,6 @@ #include "Common/Logging/Log.h" #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" -#include "DiscIO/FileMonitor.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeDirectory.h" @@ -130,8 +129,6 @@ bool CVolumeDirectory::Read(u64 offset, u64 length, u8* buffer, bool decrypt) co u64 fileSize = file.GetSize(); - FileMon::CheckFile(fileName, fileSize); - if (fileOffset < fileSize) { u64 fileBytes = std::min(fileSize - fileOffset, length); diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 60b9846504..0f302b5ce0 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -17,7 +17,6 @@ #include "Common/StringUtil.h" #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" -#include "DiscIO/FileMonitor.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeGC.h" @@ -38,8 +37,6 @@ bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const if (decrypt) PanicAlertT("Tried to decrypt data from a non-Wii volume"); - FileMon::FindFilename(_Offset); - return m_pReader->Read(_Offset, _Length, _pBuffer); } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 31d13ba68b..4b382839d2 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -22,7 +22,6 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" -#include "DiscIO/FileMonitor.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeCreator.h" @@ -59,8 +58,6 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de if (!decrypt) return m_pReader->Read(_ReadOffset, _Length, _pBuffer); - FileMon::FindFilename(_ReadOffset); - std::vector read_buffer(BLOCK_TOTAL_SIZE); while (_Length > 0) {