From bb22652a3b6a73e9f6d79470d0fef046b8bfb0a1 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 1 Nov 2024 13:27:38 -0700 Subject: [PATCH] LooseFileLoader: Add options to log to disk --- src/mods/LooseFileLoader.cpp | 39 ++++++++++++++++++++++++++++++++++++ src/mods/LooseFileLoader.hpp | 11 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/mods/LooseFileLoader.cpp b/src/mods/LooseFileLoader.cpp index e8352c1d..55dcda04 100644 --- a/src/mods/LooseFileLoader.cpp +++ b/src/mods/LooseFileLoader.cpp @@ -2,10 +2,27 @@ #include #include +#include + #include "LooseFileLoader.hpp" LooseFileLoader* g_loose_file_loader{nullptr}; +LooseFileLoader::LooseFileLoader() + : m_logger{spdlog::basic_logger_mt("LooseFileLoader", "reframework_accessed_files.txt")}, + m_loose_file_logger{spdlog::basic_logger_mt("LooseFileLoader2", "reframework_loose_files.txt")} +{ + m_logger->set_level(spdlog::level::info); + m_logger->flush_on(spdlog::level::info); + + m_logger->info("LooseFileLoader constructed"); + + m_loose_file_logger->set_level(spdlog::level::info); + m_loose_file_logger->flush_on(spdlog::level::info); + + m_loose_file_logger->info("LooseFileLoader constructed"); +} + std::shared_ptr& LooseFileLoader::get() { static auto instance = std::shared_ptr(new LooseFileLoader()); return instance; @@ -87,6 +104,20 @@ void LooseFileLoader::on_draw_ui() { ImGui::TreePop(); } + m_log_accessed_files->draw("Log accessed files"); + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("Logs all accessed files to /reframework_accessed_files.txt"); + ImGui::EndTooltip(); + } + + m_log_loose_files->draw("Log loose files"); + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("Logs loaded loose files to /reframework_loose_files.txt"); + ImGui::EndTooltip(); + } + ImGui::Checkbox("Show recent files", &m_show_recent_files); if (m_show_recent_files) { @@ -297,6 +328,14 @@ bool LooseFileLoader::handle_path(const wchar_t* path, size_t hash) { exists_on_disk = true; } + if (m_log_accessed_files->value()) { + m_logger->info("{}", utility::narrow(path)); + } + + if (exists_on_disk && m_log_loose_files->value()) { + m_loose_file_logger->info("{}", utility::narrow(path)); + } + m_seen_files.insert(hash); // Global seen_files_local.insert(hash); // Thread local ++m_uncached_hits; diff --git a/src/mods/LooseFileLoader.hpp b/src/mods/LooseFileLoader.hpp index 711d45bc..ad8fe18d 100644 --- a/src/mods/LooseFileLoader.hpp +++ b/src/mods/LooseFileLoader.hpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -12,6 +13,7 @@ class LooseFileLoader : public Mod { static std::shared_ptr& get(); public: + LooseFileLoader(); std::string_view get_name() const override { return "LooseFileLoader"; } std::optional on_initialize() override; @@ -51,10 +53,17 @@ class LooseFileLoader : public Mod { std::unique_ptr m_path_to_hash_hook{nullptr}; ModToggle::Ptr m_enabled{ ModToggle::create(generate_name("Enabled")) }; + ModToggle::Ptr m_log_accessed_files{ ModToggle::create(generate_name("LogAccessedFiles")) }; + ModToggle::Ptr m_log_loose_files{ ModToggle::create(generate_name("LogLooseFiles")) }; bool m_show_recent_files{false}; // Not persistent because its for dev purposes bool m_enable_file_cache{true}; + std::shared_ptr m_logger{nullptr}; + std::shared_ptr m_loose_file_logger{nullptr}; + ValueList m_options{ - *m_enabled + *m_enabled, + *m_log_accessed_files, + *m_log_loose_files, }; }; \ No newline at end of file