WIP: Initial commit for savefile migration #133
2 changed files with 55 additions and 3 deletions
52
backend/src/persist/migration.rs
Normal file
52
backend/src/persist/migration.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue