yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
user_settings.cc
Go to the documentation of this file.
2
3#include <fstream>
4#include <sstream>
5
6#include "absl/strings/str_format.h"
7#include "app/gui/style.h"
8#include "imgui/imgui.h"
9#include "util/file_util.h"
10#include "util/log.h"
11#include "util/platform_paths.h"
12
13namespace yaze {
14namespace editor {
15
17 auto config_dir_status = util::PlatformPaths::GetConfigDirectory();
18 if (config_dir_status.ok()) {
19 settings_file_path_ = (*config_dir_status / "yaze_settings.ini").string();
20 } else {
21 LOG_WARN("UserSettings", "Could not determine config directory. Using local.");
22 settings_file_path_ = "yaze_settings.ini";
23 }
24}
25
26absl::Status UserSettings::Load() {
27 try {
29 if (data.empty()) {
30 return absl::OkStatus(); // No settings file yet, use defaults.
31 }
32
33 std::istringstream ss(data);
34 std::string line;
35 while (std::getline(ss, line)) {
36 size_t eq_pos = line.find('=');
37 if (eq_pos == std::string::npos) continue;
38
39 std::string key = line.substr(0, eq_pos);
40 std::string val = line.substr(eq_pos + 1);
41
42 // General
43 if (key == "font_global_scale") {
44 prefs_.font_global_scale = std::stof(val);
45 } else if (key == "backup_rom") {
46 prefs_.backup_rom = (val == "1");
47 } else if (key == "save_new_auto") {
48 prefs_.save_new_auto = (val == "1");
49 } else if (key == "autosave_enabled") {
50 prefs_.autosave_enabled = (val == "1");
51 } else if (key == "autosave_interval") {
52 prefs_.autosave_interval = std::stof(val);
53 } else if (key == "recent_files_limit") {
54 prefs_.recent_files_limit = std::stoi(val);
55 } else if (key == "last_rom_path") {
57 } else if (key == "last_project_path") {
59 } else if (key == "show_welcome_on_startup") {
60 prefs_.show_welcome_on_startup = (val == "1");
61 } else if (key == "restore_last_session") {
62 prefs_.restore_last_session = (val == "1");
63 }
64 // Editor Behavior
65 else if (key == "backup_before_save") {
66 prefs_.backup_before_save = (val == "1");
67 } else if (key == "default_editor") {
68 prefs_.default_editor = std::stoi(val);
69 }
70 // Performance
71 else if (key == "vsync") {
72 prefs_.vsync = (val == "1");
73 } else if (key == "target_fps") {
74 prefs_.target_fps = std::stoi(val);
75 } else if (key == "cache_size_mb") {
76 prefs_.cache_size_mb = std::stoi(val);
77 } else if (key == "undo_history_size") {
78 prefs_.undo_history_size = std::stoi(val);
79 }
80 // AI Agent
81 else if (key == "ai_provider") {
82 prefs_.ai_provider = std::stoi(val);
83 } else if (key == "ollama_url") {
84 prefs_.ollama_url = val;
85 } else if (key == "gemini_api_key") {
87 } else if (key == "ai_temperature") {
88 prefs_.ai_temperature = std::stof(val);
89 } else if (key == "ai_max_tokens") {
90 prefs_.ai_max_tokens = std::stoi(val);
91 } else if (key == "ai_proactive") {
92 prefs_.ai_proactive = (val == "1");
93 } else if (key == "ai_auto_learn") {
94 prefs_.ai_auto_learn = (val == "1");
95 } else if (key == "ai_multimodal") {
96 prefs_.ai_multimodal = (val == "1");
97 }
98 // CLI Logging
99 else if (key == "log_level") {
100 prefs_.log_level = std::stoi(val);
101 } else if (key == "log_to_file") {
102 prefs_.log_to_file = (val == "1");
103 } else if (key == "log_file_path") {
104 prefs_.log_file_path = val;
105 } else if (key == "log_ai_requests") {
106 prefs_.log_ai_requests = (val == "1");
107 } else if (key == "log_rom_operations") {
108 prefs_.log_rom_operations = (val == "1");
109 } else if (key == "log_gui_automation") {
110 prefs_.log_gui_automation = (val == "1");
111 } else if (key == "log_proposals") {
112 prefs_.log_proposals = (val == "1");
113 }
114 }
115 ImGui::GetIO().FontGlobalScale = prefs_.font_global_scale;
116 } catch (const std::exception& e) {
117 return absl::InternalError(
118 absl::StrFormat("Failed to load user settings: %s", e.what()));
119 }
120 return absl::OkStatus();
121}
122
123absl::Status UserSettings::Save() {
124 try {
125 std::ostringstream ss;
126 // General
127 ss << "font_global_scale=" << prefs_.font_global_scale << "\n";
128 ss << "backup_rom=" << (prefs_.backup_rom ? 1 : 0) << "\n";
129 ss << "save_new_auto=" << (prefs_.save_new_auto ? 1 : 0) << "\n";
130 ss << "autosave_enabled=" << (prefs_.autosave_enabled ? 1 : 0) << "\n";
131 ss << "autosave_interval=" << prefs_.autosave_interval << "\n";
132 ss << "recent_files_limit=" << prefs_.recent_files_limit << "\n";
133 ss << "last_rom_path=" << prefs_.last_rom_path << "\n";
134 ss << "last_project_path=" << prefs_.last_project_path << "\n";
135 ss << "show_welcome_on_startup=" << (prefs_.show_welcome_on_startup ? 1 : 0) << "\n";
136 ss << "restore_last_session=" << (prefs_.restore_last_session ? 1 : 0) << "\n";
137
138 // Editor Behavior
139 ss << "backup_before_save=" << (prefs_.backup_before_save ? 1 : 0) << "\n";
140 ss << "default_editor=" << prefs_.default_editor << "\n";
141
142 // Performance
143 ss << "vsync=" << (prefs_.vsync ? 1 : 0) << "\n";
144 ss << "target_fps=" << prefs_.target_fps << "\n";
145 ss << "cache_size_mb=" << prefs_.cache_size_mb << "\n";
146 ss << "undo_history_size=" << prefs_.undo_history_size << "\n";
147
148 // AI Agent
149 ss << "ai_provider=" << prefs_.ai_provider << "\n";
150 ss << "ollama_url=" << prefs_.ollama_url << "\n";
151 ss << "gemini_api_key=" << prefs_.gemini_api_key << "\n";
152 ss << "ai_temperature=" << prefs_.ai_temperature << "\n";
153 ss << "ai_max_tokens=" << prefs_.ai_max_tokens << "\n";
154 ss << "ai_proactive=" << (prefs_.ai_proactive ? 1 : 0) << "\n";
155 ss << "ai_auto_learn=" << (prefs_.ai_auto_learn ? 1 : 0) << "\n";
156 ss << "ai_multimodal=" << (prefs_.ai_multimodal ? 1 : 0) << "\n";
157
158 // CLI Logging
159 ss << "log_level=" << prefs_.log_level << "\n";
160 ss << "log_to_file=" << (prefs_.log_to_file ? 1 : 0) << "\n";
161 ss << "log_file_path=" << prefs_.log_file_path << "\n";
162 ss << "log_ai_requests=" << (prefs_.log_ai_requests ? 1 : 0) << "\n";
163 ss << "log_rom_operations=" << (prefs_.log_rom_operations ? 1 : 0) << "\n";
164 ss << "log_gui_automation=" << (prefs_.log_gui_automation ? 1 : 0) << "\n";
165 ss << "log_proposals=" << (prefs_.log_proposals ? 1 : 0) << "\n";
166
168 } catch (const std::exception& e) {
169 return absl::InternalError(
170 absl::StrFormat("Failed to save user settings: %s", e.what()));
171 }
172 return absl::OkStatus();
173}
174
175} // namespace editor
176} // namespace yaze
177
static absl::StatusOr< std::filesystem::path > GetConfigDirectory()
Get the user-specific configuration directory for YAZE.
#define LOG_WARN(category, format,...)
Definition log.h:108
void SaveFile(const std::string &filename, const std::string &contents)
Definition file_util.cc:56
std::string LoadFile(const std::string &filename)
Loads the entire contents of a file into a string.
Definition file_util.cc:23
Main namespace for the application.