1use crate::AppConfig; 2use serde::{Deserialize, Serialize}; 3use std::path::PathBuf; 4 5pub fn migrate_config_0_10_2(config: &mut AppConfig, config_str: &str) { 6 // smsgg.bios_path -> smsgg.sms_bios_path 7 // smsgg.boot_from_bios -> smsgg.sms_boot_from_bios 8 9 #[derive(Debug, Clone, Default, Serialize, Deserialize)] 10 struct OldSmsGgConfig { 11 bios_path: Option<PathBuf>, 12 boot_from_bios: bool, 13 } 14 15 #[derive(Debug, Clone, Default, Serialize, Deserialize)] 16 struct OldAppConfig { 17 smsgg: OldSmsGgConfig, 18 } 19 20 let Ok(old_config) = toml::from_str::<OldAppConfig>(config_str) else { return }; 21 22 config.smsgg.sms_bios_path = old_config.smsgg.bios_path; 23 config.smsgg.sms_boot_from_bios = old_config.smsgg.boot_from_bios; 24} 25 26#[cfg(test)] 27mod tests { 28 use super::*; 29 30 #[test] 31 fn v0_10_2() { 32 const OLD_STR: &str = " 33[smsgg] 34boot_from_bios = true 35bios_path = \"/path/to/bios.sms\" 36"; 37 38 let mut config = AppConfig::default(); 39 migrate_config_0_10_2(&mut config, OLD_STR); 40 assert!(config.smsgg.sms_boot_from_bios); 41 assert_eq!(config.smsgg.sms_bios_path, Some("/path/to/bios.sms".into())); 42 } 43}