Jump to content

SongRec/Internal formats/preferences.toml: Difference between revisions

From Fossplant
Line 9: Line 9:
(WIP 2026-05-05)
(WIP 2026-05-05)


The location for the <code>preferences.toml</code> file is calculated through the <code>[https://github.com/marin-m/SongRec/blob/0.6.9/src/utils/filesystem_operations.rs#L31 obtain_preferences_file_path]</code> function of <code>[https://github.com/marin-m/SongRec/blob/0.6.9/src/utils/filesystem_operations.rs src/utils/filesystem_operations.rs]</code>.
The location for the <code>preferences.toml</code> file is calculated through the <code>[https://github.com/marin-m/SongRec/blob/7ab23d0/src/utils/filesystem_operations.rs#L31 obtain_preferences_file_path]</code> function of <code>[https://github.com/marin-m/SongRec/blob/7ab23d0/src/utils/filesystem_operations.rs src/utils/filesystem_operations.rs]</code>.


<syntaxhighlight lang="rust">
<syntaxhighlight lang="rust">
pub fn obtain_preferences_file_path() -> Result<String, Box<dyn Error>> {
const QUALIFIER: &str = "";
     let project_dir =
const ORGANIZATION: &str = "SongRec";
        ProjectDirs::from(QUALIFIER, ORGANIZATION, APPLICATION).ok_or("No valid path")?;
const APPLICATION: &str = "SongRec";
     let mut preferences_file_path: PathBuf = obtain_preferences_directory(project_dir)?;
 
static PROJECT_DIRS: LazyLock<ProjectDirs> =
     LazyLock::new(|| ProjectDirs::from(QUALIFIER, ORGANIZATION, APPLICATION).unwrap());
 
pub fn obtain_preferences_file_path() -> Result<PathBuf, Box<dyn Error>> {
     let mut preferences_file_path = obtain_preferences_directory()?;
     preferences_file_path.push("preferences.toml");
     preferences_file_path.push("preferences.toml");
     Ok(preferences_file_path.to_str().unwrap().to_string())
     Ok(preferences_file_path)
}
 
fn obtain_preferences_directory() -> Result<PathBuf, Box<dyn Error>> {
    let preferences_dir = PROJECT_DIRS.preference_dir();
    if !preferences_dir.exists() {
        create_dir_all(preferences_dir)?;
    }
    Ok(preferences_dir.to_path_buf())
}
}
</syntaxhighlight>
</syntaxhighlight>
See:
* https://docs.rs/directories/latest/directories/struct.ProjectDirs.html
* https://docs.rs/directories/latest/directories/struct.ProjectDirs.html#method.from
* https://docs.rs/directories/latest/directories/struct.ProjectDirs.html#method.preference_dir


== Variables ==
== Variables ==


(WIP 2026-05-05)
(WIP 2026-05-05)

Revision as of 04:16, 6 May 2026

The preferences.toml file of SongRec is saved, under Linux, at the ~/.config/songrec/preferences.toml path by default, when using an unsandboxed environment.

It uses the TOML format.

It is written through by the src/core/preferences.rs utility file, which open the path of the preferences file through src/utils/filesystem_operations.rs.

Save location

(WIP 2026-05-05)

The location for the preferences.toml file is calculated through the obtain_preferences_file_path function of src/utils/filesystem_operations.rs.

const QUALIFIER: &str = "";
const ORGANIZATION: &str = "SongRec";
const APPLICATION: &str = "SongRec";

static PROJECT_DIRS: LazyLock<ProjectDirs> =
    LazyLock::new(|| ProjectDirs::from(QUALIFIER, ORGANIZATION, APPLICATION).unwrap());

pub fn obtain_preferences_file_path() -> Result<PathBuf, Box<dyn Error>> {
    let mut preferences_file_path = obtain_preferences_directory()?;
    preferences_file_path.push("preferences.toml");
    Ok(preferences_file_path)
}

fn obtain_preferences_directory() -> Result<PathBuf, Box<dyn Error>> {
    let preferences_dir = PROJECT_DIRS.preference_dir();
    if !preferences_dir.exists() {
        create_dir_all(preferences_dir)?;
    }
    Ok(preferences_dir.to_path_buf())
}

See:

Variables

(WIP 2026-05-05)