Skip to content

Commit

Permalink
Merge pull request #4901 from JosJuice/filemonitor-redesign
Browse files Browse the repository at this point in the history
FileMonitor redesign
  • Loading branch information
Helios747 committed Mar 20, 2017
2 parents 50faffc + 98b4ff1 commit 26bb26f
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 191 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/CMakeLists.txt
Expand Up @@ -8,6 +8,7 @@ set(SRCS
CoreTiming.cpp
DSPEmulator.cpp
ec_wii.cpp
FileMonitor.cpp
GeckoCodeConfig.cpp
GeckoCode.cpp
HotkeyManager.cpp
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/Core/Core.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Core.vcxproj
Expand Up @@ -89,6 +89,7 @@
<ClCompile Include="FifoPlayer\FifoPlayer.cpp" />
<ClCompile Include="FifoPlayer\FifoRecordAnalyzer.cpp" />
<ClCompile Include="FifoPlayer\FifoRecorder.cpp" />
<ClCompile Include="FileMonitor.cpp" />
<ClCompile Include="GeckoCode.cpp" />
<ClCompile Include="GeckoCodeConfig.cpp" />
<ClCompile Include="HLE\HLE.cpp" />
Expand Down Expand Up @@ -338,6 +339,7 @@
<ClInclude Include="FifoPlayer\FifoPlayer.h" />
<ClInclude Include="FifoPlayer\FifoRecordAnalyzer.h" />
<ClInclude Include="FifoPlayer\FifoRecorder.h" />
<ClInclude Include="FileMonitor.h" />
<ClInclude Include="GeckoCode.h" />
<ClInclude Include="GeckoCodeConfig.h" />
<ClInclude Include="HLE\HLE.h" />
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/Core.vcxproj.filters
Expand Up @@ -281,6 +281,9 @@
<ClCompile Include="FifoPlayer\FifoRecorder.cpp">
<Filter>FifoPlayer</Filter>
</ClCompile>
<ClCompile Include="FileMonitor.cpp">
<Filter>FileMonitor</Filter>
</ClCompile>
<ClCompile Include="GeckoCode.cpp">
<Filter>GeckoCode</Filter>
</ClCompile>
Expand Down Expand Up @@ -957,6 +960,9 @@
<ClInclude Include="FifoPlayer\FifoRecorder.h">
<Filter>FifoPlayer</Filter>
</ClInclude>
<ClInclude Include="FileMonitor.h">
<Filter>FileMonitor</Filter>
</ClInclud
<ClInclude Include="GeckoCode.h">
<Filter>GeckoCode</Filter>
</ClInclude>
Expand Down
116 changes: 116 additions & 0 deletions 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 <algorithm>
#include <cctype>
#include <memory>
#include <string>
#include <unordered_set>

#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<DiscIO::IFileSystem> 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<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
".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
24 changes: 24 additions & 0 deletions 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 <memory>

#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);
}
14 changes: 13 additions & 1 deletion Source/Core/Core/HW/DVDInterface.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -474,6 +480,7 @@ void Shutdown()
{
DVDThread::Stop();
s_inserted_volume.reset();
FileMonitor::SetFileSystem(nullptr);
}

const DiscIO::IVolume& GetVolume()
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -513,6 +522,7 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate)
{
DVDThread::WaitUntilIdle();
s_inserted_volume.reset();
FileMonitor::SetFileSystem(s_inserted_volume.get());
SetLidOpen();
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/HW/DVDThread.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -277,6 +278,8 @@ static void DVDThread()
ReadRequest request;
while (s_request_queue.Pop(request))
{
FileMonitor::Log(request.dvd_offset, request.decrypt);

std::vector<u8> buffer(request.length);
const DiscIO::IVolume& volume = DVDInterface::GetVolume();
if (!volume.Read(request.dvd_offset, request.length, buffer.data(), request.decrypt))
Expand Down
1 change: 0 additions & 1 deletion Source/Core/DiscIO/CMakeLists.txt
Expand Up @@ -7,7 +7,6 @@ set(SRCS
DriveBlob.cpp
Enums.cpp
FileBlob.cpp
FileMonitor.cpp
FileSystemGCWii.cpp
Filesystem.cpp
NANDContentLoader.cpp
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DiscIO/DiscIO.vcxproj
Expand Up @@ -42,7 +42,6 @@
<ClCompile Include="DriveBlob.cpp" />
<ClCompile Include="Enums.cpp" />
<ClCompile Include="FileBlob.cpp" />
<ClCompile Include="FileMonitor.cpp" />
<ClCompile Include="Filesystem.cpp" />
<ClCompile Include="FileSystemGCWii.cpp" />
<ClCompile Include="NANDContentLoader.cpp" />
Expand All @@ -64,7 +63,6 @@
<ClInclude Include="DriveBlob.h" />
<ClInclude Include="Enums.h" />
<ClInclude Include="FileBlob.h" />
<ClInclude Include="FileMonitor.h" />
<ClInclude Include="Filesystem.h" />
<ClInclude Include="FileSystemGCWii.h" />
<ClInclude Include="NANDContentLoader.h" />
Expand Down
6 changes: 0 additions & 6 deletions Source/Core/DiscIO/DiscIO.vcxproj.filters
Expand Up @@ -51,9 +51,6 @@
<ClCompile Include="WbfsBlob.cpp">
<Filter>Volume\Blob</Filter>
</ClCompile>
<ClCompile Include="FileMonitor.cpp">
<Filter>Volume</Filter>
</ClCompile>
<ClCompile Include="VolumeCreator.cpp">
<Filter>Volume</Filter>
</ClCompile>
Expand Down Expand Up @@ -113,9 +110,6 @@
<ClInclude Include="WbfsBlob.h">
<Filter>Volume\Blob</Filter>
</ClInclude>
<ClInclude Include="FileMonitor.h">
<Filter>Volume</Filter>
</ClInclude>
<ClInclude Include="Volume.h">
<Filter>Volume</Filter>
</ClInclude>
Expand Down

0 comments on commit 26bb26f

Please sign in to comment.