diff --git a/backend/src/persist/migration.rs b/backend/src/persist/migration.rs new file mode 100644 index 0000000..33f21bb --- /dev/null +++ b/backend/src/persist/migration.rs @@ -0,0 +1,52 @@ +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub struct OldOnEventJson { + pub on_save: Option, + pub on_load: Option, + pub on_set: Option, + pub on_resume: Option, +} + +#[derive(Serialize, Deserialize)] +pub struct OldSettingsJson { + pub version: u64, + pub name: String, + pub persistent: bool, + pub cpus: Vec, + pub gpu: super::GpuJson, + pub battery: super::BatteryJson, + pub provider: Option, + pub events: Option, +} + +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, + } + } +} diff --git a/backend/src/persist/mod.rs b/backend/src/persist/mod.rs index bfc0b2a..d991a88 100644 --- a/backend/src/persist/mod.rs +++ b/backend/src/persist/mod.rs @@ -5,6 +5,7 @@ mod error; mod file; mod general; mod gpu; +mod migration; pub use battery::{BatteryEventJson, BatteryJson}; pub use cpu::CpuJson; @@ -12,7 +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; - -pub const LATEST_VERSION: u64 = 0; +pub use error::{RonError, SerdeError};