diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 15:33:52 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 15:42:08 +0100 |
| commit | 439cd0d998571506dd7971fe1e357d09cb2ff36e (patch) | |
| tree | f9f2667865c3816736b3f009c0841510b97fcb76 /src/preferences/storage.rs | |
| parent | 5a902f8b350f8b2b33c4e19c70f3425802faaa1b (diff) | |
Add license, and expand variables
Diffstat (limited to 'src/preferences/storage.rs')
| -rw-r--r-- | src/preferences/storage.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/preferences/storage.rs b/src/preferences/storage.rs index 83db786..b61266b 100644 --- a/src/preferences/storage.rs +++ b/src/preferences/storage.rs @@ -1,17 +1,18 @@ -// Copyright (C) 2024 Rubén Beltrán del Río +// Map, wardley map editor for linux +// Copyright (C) 2026 Rubén Beltrán del Río // This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by +// it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// GNU Affero General Public License for more details. -// You should have received a copy of the GNU General Public License -// along with this program. If not, see https://map.tranquil.systems. +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. use std::fs; use std::path::PathBuf; @@ -47,30 +48,30 @@ pub fn load() -> UserPreferences { } /// Saves preferences to disk -pub fn save(prefs: &UserPreferences) -> Result<(), std::io::Error> { +pub fn save(preferences: &UserPreferences) -> Result<(), std::io::Error> { let path = preferences_path(); if let Some(parent) = path.parent() { fs::create_dir_all(parent)?; } - let content = serde_json::to_string_pretty(prefs).map_err(std::io::Error::other)?; + let content = serde_json::to_string_pretty(preferences).map_err(std::io::Error::other)?; fs::write(path, content) } /// Exports preferences to JSON string (for file export) -pub fn export_json(prefs: &UserPreferences) -> Option<String> { - let json_prefs = prefs.to_json(); - serde_json::to_string_pretty(&json_prefs).ok() +pub fn export_json(preferences: &UserPreferences) -> Option<String> { + let json_preferences = preferences.to_json(); + serde_json::to_string_pretty(&json_preferences).ok() } /// Imports preferences from JSON string (partial updates supported) /// Returns true on success, false on parse error -pub fn import_json(prefs: &mut UserPreferences, json: &str) -> bool { +pub fn import_json(preferences: &mut UserPreferences, json: &str) -> bool { match serde_json::from_str::<UserPreferencesJson>(json) { Ok(imported) => { - prefs.update_from_json(&imported); + preferences.update_from_json(&imported); true } Err(_) => false, @@ -78,16 +79,19 @@ pub fn import_json(prefs: &mut UserPreferences, json: &str) -> bool { } /// Saves preferences to a specific file path (for export dialog) -pub fn export_to_file(prefs: &UserPreferences, path: &PathBuf) -> Result<(), std::io::Error> { +pub fn export_to_file(preferences: &UserPreferences, path: &PathBuf) -> Result<(), std::io::Error> { let content = - export_json(prefs).ok_or_else(|| std::io::Error::other("Serialization failed"))?; + export_json(preferences).ok_or_else(|| std::io::Error::other("Serialization failed"))?; fs::write(path, content) } /// Loads preferences from a specific file path (for import dialog) -pub fn import_from_file(prefs: &mut UserPreferences, path: &PathBuf) -> Result<(), std::io::Error> { +pub fn import_from_file( + preferences: &mut UserPreferences, + path: &PathBuf, +) -> Result<(), std::io::Error> { let content = fs::read_to_string(path)?; - if import_json(prefs, &content) { + if import_json(preferences, &content) { Ok(()) } else { Err(std::io::Error::new( |