From 4b5aba86d10c5cfac3f13971c348c6e8d7c1044f Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 30 Apr 2024 22:55:12 +0200 Subject: [PATCH] Revert "switch from toml to ini as config file for simplicity" This reverts commit 8da20abff8681853fc46ce2113d2dd0d5d625dfa. --- Cargo.lock | 65 +++++++++++++++++++++++---------------- Cargo.toml | 2 +- outfly.ini => outfly.toml | 6 ++-- src/var.rs | 28 +++++++++++------ 4 files changed, 61 insertions(+), 40 deletions(-) rename outfly.ini => outfly.toml (94%) diff --git a/Cargo.lock b/Cargo.lock index cb1883d..f3b3884 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,7 +691,7 @@ dependencies = [ "quote", "rustc-hash", "syn 2.0.52", - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -2812,8 +2812,8 @@ dependencies = [ "fastrand", "regex", "serde", - "serde_ini", "serde_yaml", + "toml_edit 0.22.12", ] [[package]] @@ -2997,7 +2997,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -3151,12 +3151,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" -[[package]] -name = "result" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" - [[package]] name = "robust" version = "1.1.0" @@ -3299,17 +3293,6 @@ dependencies = [ "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]] name = "serde_json" version = "1.0.115" @@ -3321,6 +3304,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" @@ -3609,6 +3601,9 @@ name = "toml_datetime" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -3618,7 +3613,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[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]] @@ -3778,12 +3786,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "vswhom" version = "0.1.0" @@ -4504,6 +4506,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index eec6d0d..acf92de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9" # For reading/writing the player's configuration file. -serde_ini = "0.2" +toml_edit = { version = "0.22", default-features = false, features = ["parse", "serde"] } [build-dependencies] embed-resource = "1.6.3" # embedding of .exe metadata diff --git a/outfly.ini b/outfly.toml similarity index 94% rename from outfly.ini rename to outfly.toml index 24a8d6c..ba34066 100644 --- a/outfly.ini +++ b/outfly.toml @@ -12,10 +12,10 @@ # See https://codeberg.org/hut/outfly # fullscreen_mode may be "borderless", "true", or "sized" -fullscreen_mode = borderless +fullscreen_mode = "borderless" # window_mode may be "windowed", or "fullscreen" -window_mode = fullscreen +window_mode = "fullscreen" # render_mode may be "vulkan" or "gl" -render_mode = vulkan +render_mode = "vulkan" diff --git a/src/var.rs b/src/var.rs index 908d37b..a1e1978 100644 --- a/src/var.rs +++ b/src/var.rs @@ -14,7 +14,8 @@ use bevy::prelude::*; use std::collections::HashMap; use serde::Deserialize; -use serde_ini; +use toml_edit::DocumentMut; +use toml_edit::de::from_document; use std::env; use std::fs; @@ -79,21 +80,30 @@ pub fn load_prefs() -> Preferences { return Preferences::default(); } }; - let content = match fs::read_to_string(&prefs_path) { - Ok(content) => content, + let toml = fs::read_to_string(&prefs_path); + let toml = match toml { + Ok(toml) => toml, Err(error) => { error!("Failed to open preferences file '{prefs_path}': {error}"); return Preferences::default(); } }; - match serde_ini::from_str::(content.as_str()) { - Ok(pref) => { - info!("Loaded preference file from {prefs_path}"); - dbg!(&pref); - return pref; + match toml.parse::() { + Ok(doc) => { + match from_document::(doc) { + Ok(pref) => { + info!("Loaded preference file from {prefs_path}"); + dbg!(&pref); + return pref; + } + Err(error) => { + error!("Failed to read preference line: {error}"); + return Preferences::default(); + } + } } Err(error) => { - error!("Failed to read preference line: {error}"); + error!("Failed to open preferences: {error}"); return Preferences::default(); } }