WIP: Initial commit for savefile migration #133

Draft
not_a_segfault wants to merge 12 commits from not_a_segfault/PowerTools:dev into dev
2 changed files with 55 additions and 1 deletions
Showing only changes of commit ae7810702a - Show all commits

View file

@ -0,0 +1,52 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct OldOnEventJson {
pub on_save: Option<String>,
pub on_load: Option<String>,
pub on_set: Option<String>,
pub on_resume: Option<String>,
}
#[derive(Serialize, Deserialize)]
pub struct OldSettingsJson {
pub version: u64,
pub name: String,
pub persistent: bool,
pub cpus: Vec<super::CpuJson>,
pub gpu: super::GpuJson,
pub battery: super::BatteryJson,
pub provider: Option<super::DriverJson>,
pub events: Option<OldOnEventJson>,
}
impl From<&OldSettingsJson> for super::SettingsJson {
fn from(old_settings: &OldSettingsJson) -> Self {
Self {
version: old_settings.version,
name: old_settings.name.clone(),
variant: 0,
persistent: old_settings.persistent,
cpus: old_settings.cpus.clone(),
gpu: old_settings.gpu.clone(),
battery: old_settings.battery.clone(),
provider: old_settings.provider.clone(),
}
}
}
impl From<&OldSettingsJson> for super::FileJson {
fn from(old_settings: &OldSettingsJson) -> Self {
let mut variants = HashMap::new();
let variant = super::SettingsJson::from(old_settings);
variants.insert(0, variant);
Self {
version: 0,
name: old_settings.name.clone(),
variants,
}
}
}

View file

@ -5,6 +5,7 @@ mod error;
mod file;
mod general;
mod gpu;
mod migration;
pub use battery::{BatteryEventJson, BatteryJson};
pub use cpu::CpuJson;
@ -12,5 +13,6 @@ pub use driver::DriverJson;
pub use file::FileJson;
pub use general::{MinMaxJson, SettingsJson};
pub use gpu::GpuJson;
pub use migration::OldSettingsJson;
pub use error::{SerdeError, RonError};
pub use error::{RonError, SerdeError};