diff --git a/source/ini_file.cpp b/source/ini_file.cpp index 87d605206..0259ba3f2 100644 --- a/source/ini_file.cpp +++ b/source/ini_file.cpp @@ -14,23 +14,21 @@ ini_file::ini_file(const std::filesystem::path &path) : _path(path) { load(); } -ini_file::~ini_file() -{ - save(); -} void ini_file::load() { std::error_code ec; const std::filesystem::file_time_type modified_at = std::filesystem::last_write_time(_path, ec); - if (ec || _modified_at >= modified_at) - return; // Skip loading if there was an error (e.g. file does not exist) or there was no modification to the file since it was last loaded + if (!ec && _modified_at >= modified_at) + return; // Skip loading if there was no modification to the file since it was last loaded + + // Clear when file does not exist too + _sections.clear(); std::ifstream file; if (file.open(_path); !file) return; - _sections.clear(); _modified = false; _modified_at = modified_at; @@ -106,7 +104,7 @@ bool ini_file::save() std::error_code ec; const std::filesystem::file_time_type modified_at = std::filesystem::last_write_time(_path, ec); if (!ec && modified_at >= _modified_at) - return true; // File exists and was modified on disk and therefore may have different data, so cannot save + return false; // File exists and was modified on disk and therefore may have different data, so cannot save std::stringstream data; std::vector section_names, key_names; @@ -210,10 +208,13 @@ bool ini_file::flush_cache(const std::filesystem::path &path) ini_file &ini_file::load_cache(const std::filesystem::path &path) { const auto it = g_ini_cache.try_emplace(path, path); - if (it.second || (std::filesystem::file_time_type::clock::now() - it.first->second._modified_at) < std::chrono::seconds(1)) - return it.first->second; // Don't need to reload file when it was just loaded or there are still modifications pending - else - return it.first->second.load(), it.first->second; + std::pair &file = *it.first; + + // Don't reload file when it was just loaded or there are still modifications pending + if (!it.second && !file.second._modified) + file.second.load(); + + return file.second; } ini_file & reshade::global_config() diff --git a/source/ini_file.hpp b/source/ini_file.hpp index ad5d8a509..e0faae848 100644 --- a/source/ini_file.hpp +++ b/source/ini_file.hpp @@ -34,7 +34,6 @@ class ini_file /// /// The path to the INI file to access. explicit ini_file(const std::filesystem::path &path); - ~ini_file(); /// /// Gets the path to this INI file. diff --git a/source/runtime_gui.cpp b/source/runtime_gui.cpp index 946421d39..4d5b6391e 100644 --- a/source/runtime_gui.cpp +++ b/source/runtime_gui.cpp @@ -976,7 +976,7 @@ void reshade::runtime::draw_gui_home() const float button_size = ImGui::GetFrameHeight(); const float button_spacing = _imgui_context->Style.ItemInnerSpacing.x; - const float browse_button_width = ImGui::GetWindowContentRegionWidth() - (button_spacing + button_size) * 3; + const float browse_button_width = ImGui::GetWindowContentRegionWidth() - (button_spacing + button_size) * 4; bool reload_preset = false; @@ -1006,6 +1006,16 @@ void reshade::runtime::draw_gui_home() } ImGui::PopStyleVar(); + ImGui::SameLine(0, button_spacing); + if (ImGui::ButtonEx(ICON_FK_FLOPPY, ImVec2(button_size, 0), button_flags)) + { + DeleteFileW(_current_preset_path.c_str()); + save_current_preset(); + } + + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Clean up and save the current preset (removes all settings for disabled techniques)"); + ImGui::SameLine(0, button_spacing); if (ImGui::ButtonEx(ICON_FK_PLUS, ImVec2(button_size, 0), button_flags | ImGuiButtonFlags_PressedOnClick)) { @@ -1013,6 +1023,9 @@ void reshade::runtime::draw_gui_home() ImGui::OpenPopup("##create"); } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Add a new preset"); + if (is_loading()) ImGui::PopStyleColor(); @@ -1020,7 +1033,7 @@ void reshade::runtime::draw_gui_home() if (widgets::file_dialog("##browse", _file_selection_path, browse_button_width, { L".ini", L".txt" })) { // Check that this is actually a valid preset file - if (ini_file::load_cache(_file_selection_path).has("", "Techniques")) + if (ini_file::load_cache(_file_selection_path).has({}, "Techniques")) { reload_preset = true; _current_preset_path = _file_selection_path; @@ -1044,7 +1057,7 @@ void reshade::runtime::draw_gui_home() { reload_preset = file_type == std::filesystem::file_type::not_found || - ini_file::load_cache(new_preset_path).has("", "Techniques"); + ini_file::load_cache(new_preset_path).has({}, "Techniques"); if (_duplicate_current_preset && file_type == std::filesystem::file_type::not_found) CopyFileW(_current_preset_path.c_str(), new_preset_path.c_str(), TRUE); @@ -1287,6 +1300,8 @@ void reshade::runtime::draw_gui_home() if (ImGui::Button(ICON_FK_REFRESH " Reload", ImVec2(-11.5f * _font_size, 0))) { + load_config(); // Reload configuration too + if (!_no_effect_cache && (ImGui::GetIO().KeyCtrl || ImGui::GetIO().KeyShift)) clear_effect_cache();