Resubmit - Prevent settings from being saved when close button is pressed instead of save (#1747)

* Do not save settings when close button pressed instead of save

* Update src/common/config.h

Co-authored-by: TheTurtle <geoster3d@gmail.com>

* Revert "Update src/common/config.h"

This reverts commit 125303ea86.

---------

Co-authored-by: rainmakerv2 <30595646+jpau02@users.noreply.github.com>
Co-authored-by: TheTurtle <geoster3d@gmail.com>
This commit is contained in:
rainmakerv2 2024-12-13 04:46:31 +08:00 committed by GitHub
parent 2a19d915e8
commit 3f1061de56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 194 additions and 163 deletions

View file

@ -422,6 +422,10 @@ void setEmulatorLanguage(std::string language) {
emulator_language = language;
}
void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config) {
settings_install_dirs = settings_install_dirs_config;
}
u32 getMainWindowGeometryX() {
return main_window_geometry_x;
}
@ -673,14 +677,6 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["crashDiagnostic"] = vkCrashDiagnostic;
data["Debug"]["DebugDump"] = isDebugDump;
data["Debug"]["CollectShader"] = isShaderDebug;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;
data["GUI"]["iconSizeGrid"] = m_icon_size_grid;
data["GUI"]["sliderPosGrid"] = m_slider_pos_grid;
data["GUI"]["gameTableMode"] = m_table_mode;
data["GUI"]["mw_width"] = m_window_size_W;
data["GUI"]["mw_height"] = m_window_size_H;
std::vector<std::string> install_dirs;
for (const auto& dirString : settings_install_dirs) {
@ -690,6 +686,43 @@ void save(const std::filesystem::path& path) {
data["GUI"]["addonInstallDir"] =
std::string{fmt::UTF(settings_addon_install_dir.u8string()).data};
data["GUI"]["emulatorLanguage"] = emulator_language;
data["Settings"]["consoleLanguage"] = m_language;
std::ofstream file(path, std::ios::binary);
file << data;
file.close();
}
void saveMainWindow(const std::filesystem::path& path) {
toml::value data;
std::error_code error;
if (std::filesystem::exists(path, error)) {
try {
std::ifstream ifs;
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
ifs.open(path, std::ios_base::binary);
data = toml::parse(ifs, std::string{fmt::UTF(path.filename().u8string()).data});
} catch (const std::exception& ex) {
fmt::print("Exception trying to parse config file. Exception: {}\n", ex.what());
return;
}
} else {
if (error) {
fmt::print("Filesystem error: {}\n", error.message());
}
fmt::print("Saving new configuration file {}\n", fmt::UTF(path.u8string()));
}
data["GUI"]["mw_width"] = m_window_size_W;
data["GUI"]["mw_height"] = m_window_size_H;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;
data["GUI"]["iconSizeGrid"] = m_icon_size_grid;
data["GUI"]["sliderPosGrid"] = m_slider_pos_grid;
data["GUI"]["gameTableMode"] = m_table_mode;
data["GUI"]["geometry_x"] = main_window_geometry_x;
data["GUI"]["geometry_y"] = main_window_geometry_y;
data["GUI"]["geometry_w"] = main_window_geometry_w;
@ -697,9 +730,6 @@ void save(const std::filesystem::path& path) {
data["GUI"]["pkgDirs"] = m_pkg_viewer;
data["GUI"]["elfDirs"] = m_elf_viewer;
data["GUI"]["recentFiles"] = m_recent_files;
data["GUI"]["emulatorLanguage"] = emulator_language;
data["Settings"]["consoleLanguage"] = m_language;
std::ofstream file(path, std::ios::binary);
file << data;

View file

@ -13,6 +13,7 @@ enum HideCursorState : s16 { Never, Idle, Always };
void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path);
void saveMainWindow(const std::filesystem::path& path);
bool isNeoMode();
bool isFullscreenMode();
@ -67,6 +68,7 @@ void setNeoMode(bool enable);
void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type);
void setSeparateUpdateEnabled(bool use);
void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_install_dirs_config);
void setCursorState(s16 cursorState);
void setCursorHideTimeout(int newcursorHideTimeout);
@ -128,4 +130,4 @@ void setDefaultValues();
// settings
u32 GetLanguage();
}; // namespace Config
}; // namespace Config