switch from toml to ini as config file for simplicity

This commit is contained in:
yuni 2024-04-30 22:40:40 +02:00
parent d65d3b2aec
commit 8da20abff8
4 changed files with 40 additions and 61 deletions

65
Cargo.lock generated
View file

@ -691,7 +691,7 @@ dependencies = [
"quote", "quote",
"rustc-hash", "rustc-hash",
"syn 2.0.52", "syn 2.0.52",
"toml_edit 0.21.1", "toml_edit",
] ]
[[package]] [[package]]
@ -2812,8 +2812,8 @@ dependencies = [
"fastrand", "fastrand",
"regex", "regex",
"serde", "serde",
"serde_ini",
"serde_yaml", "serde_yaml",
"toml_edit 0.22.12",
] ]
[[package]] [[package]]
@ -2997,7 +2997,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [ dependencies = [
"toml_edit 0.21.1", "toml_edit",
] ]
[[package]] [[package]]
@ -3151,6 +3151,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "result"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560"
[[package]] [[package]]
name = "robust" name = "robust"
version = "1.1.0" version = "1.1.0"
@ -3293,6 +3299,17 @@ dependencies = [
"syn 2.0.52", "syn 2.0.52",
] ]
[[package]]
name = "serde_ini"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb236687e2bb073a7521c021949be944641e671b8505a94069ca37b656c81139"
dependencies = [
"result",
"serde",
"void",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.115" version = "1.0.115"
@ -3304,15 +3321,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_spanned"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_yaml" name = "serde_yaml"
version = "0.9.34+deprecated" version = "0.9.34+deprecated"
@ -3601,9 +3609,6 @@ name = "toml_datetime"
version = "0.6.5" version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
@ -3613,20 +3618,7 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"toml_datetime", "toml_datetime",
"winnow 0.5.40", "winnow",
]
[[package]]
name = "toml_edit"
version = "0.22.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow 0.6.7",
] ]
[[package]] [[package]]
@ -3786,6 +3778,12 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]] [[package]]
name = "vswhom" name = "vswhom"
version = "0.1.0" version = "0.1.0"
@ -4506,15 +4504,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winnow"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.10.1" version = "0.10.1"

View file

@ -40,7 +40,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9" serde_yaml = "0.9"
# For reading/writing the player's configuration file. # For reading/writing the player's configuration file.
toml_edit = { version = "0.22", default-features = false, features = ["parse", "serde"] } serde_ini = "0.2"
[build-dependencies] [build-dependencies]
embed-resource = "1.6.3" # embedding of .exe metadata embed-resource = "1.6.3" # embedding of .exe metadata

View file

@ -12,10 +12,10 @@
# See https://codeberg.org/hut/outfly # See https://codeberg.org/hut/outfly
# fullscreen_mode may be "borderless", "true", or "sized" # fullscreen_mode may be "borderless", "true", or "sized"
fullscreen_mode = "borderless" fullscreen_mode = borderless
# window_mode may be "windowed", or "fullscreen" # window_mode may be "windowed", or "fullscreen"
window_mode = "fullscreen" window_mode = fullscreen
# render_mode may be "vulkan" or "gl" # render_mode may be "vulkan" or "gl"
render_mode = "vulkan" render_mode = vulkan

View file

@ -14,8 +14,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;
use serde::Deserialize; use serde::Deserialize;
use toml_edit::DocumentMut; use serde_ini;
use toml_edit::de::from_document;
use std::env; use std::env;
use std::fs; use std::fs;
@ -80,17 +79,14 @@ pub fn load_prefs() -> Preferences {
return Preferences::default(); return Preferences::default();
} }
}; };
let toml = fs::read_to_string(&prefs_path); let content = match fs::read_to_string(&prefs_path) {
let toml = match toml { Ok(content) => content,
Ok(toml) => toml,
Err(error) => { Err(error) => {
error!("Failed to open preferences file '{prefs_path}': {error}"); error!("Failed to open preferences file '{prefs_path}': {error}");
return Preferences::default(); return Preferences::default();
} }
}; };
match toml.parse::<DocumentMut>() { match serde_ini::from_str::<Preferences>(content.as_str()) {
Ok(doc) => {
match from_document::<Preferences>(doc) {
Ok(pref) => { Ok(pref) => {
info!("Loaded preference file from {prefs_path}"); info!("Loaded preference file from {prefs_path}");
dbg!(&pref); dbg!(&pref);
@ -101,12 +97,6 @@ pub fn load_prefs() -> Preferences {
return Preferences::default(); return Preferences::default();
} }
} }
}
Err(error) => {
error!("Failed to open preferences: {error}");
return Preferences::default();
}
}
} }
#[derive(Resource)] #[derive(Resource)]