1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Management of TOML configuration files for AtlantisOS applications.
//!
//! This module uses the `confy` and `serde` crates to
//! persistently store and read simple key-value pairs
//! in the user's default configuration directory (e.g., `~/.config/`).
/**
* toml_config.rs
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use ;
use HashMap;
/// Data structure for AtlantisOS configurations.
///
/// Uses a [HashMap] to flexibly store various configuration keys
/// and their values as strings.
/// Reads a value from an application's configuration file.
///
/// Loads the configuration file based on the application name. If the file
/// does not exist, a default empty structure is used.
///
/// # Arguments
/// * `app_name` - The name of the application (determines the file name/directory).
/// * `key` - The name of the configuration key being searched for.
///
/// # Return Value
/// Returns `Some(String)` if the key exists, otherwise `None`.
///
/// # Usage:
///
/// ```rust
/// fn main() {
/// match get_config("atl_test", "theme") {
/// Some(val) => println!("Found: {}", val),
/// None => println!("Key not found!"),
/// }
/// }
/// ```
/// Saves or updates a value in the configuration file.
///
/// First loads the current state of the file, adds the new key-value pair
/// or overwrites an existing one, and then writes the entire structure
/// back to the hard drive.
///
/// # Arguments
/// * `app_name` - The name of the application (determines the storage location at `~/.config/app_name`).
/// * `key` - The identifier for the setting.
/// * `value` - The value to be saved.
///
/// # Error Handling
/// Returns a [confy::ConfyError] if file permissions are missing or
/// serialization fails.
///
/// # Usage:
///
/// ```rust
/// fn main() {
/// if let Err(e) = set_config("atl_test", "theme", "dark") {
/// eprintln!("Error at saving: {}", e);
/// }
/// set_config_val("atl_test", "port", "8080").unwrap();
/// let port: u16 = get_config_val("port")
/// .and_then(|v| v.parse().ok())
/// .unwrap_or(3000); // default value
/// println!("Port: {}", port);
/// }
/// ```