WIP: Initial commit for savefile migration #133

Draft
not_a_segfault wants to merge 12 commits from not_a_segfault/PowerTools:dev into dev
4 changed files with 87 additions and 69 deletions
Showing only changes of commit da5d2a9673 - Show all commits

View file

@ -1,68 +1,2 @@
// - Commit that changed setting format: 3aa9680baedf850d7d576d0df28ce50cf2124ebe.
// - Commit that made settings variant use u64 instead of String:
// d481f1314409c99a0ed48b006a8e9b53f6caa8a5.
// - Add all back-end functionality for interacting with variants on the front-end:
// 4eaf6fae2bba0219a316d37499ee6e1549645862.
// - Improve memory clock selection for #140, fix dpm_performance enforcement check for GPU:
// a1c44cdea7ae27f7a09fd194c580c79b291d25d1.
// - Remove legacy charge mode and level functionality: 88d359e286bec2fdabde0f4f72b52fb8f4d5200e.
// - Add tags for persistent settings variants: ccf0c04020bfc5ae9f667801f99d1a31f939006a.
// TODO: Check full git diff between data structures from version 1.4.0 and current, to see exactly
// what changed and how to migrate them to the current data structures.
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>,
pub tags: Vec<String>,
}
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(),
tags: todo!(),
}
}
}
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: super::LATEST_VERSION,
name: old_settings.name.clone(),
variants,
app_id: todo!(),
}
}
}
pub mod gpu;
pub mod settings;

View file

@ -0,0 +1,26 @@
use serde::{Deserialize, Serialize};
use crate::persist::{GpuJson, MinMaxJson};
#[derive(Serialize, Deserialize, Clone)]
pub struct OldGpuJson {
pub fast_ppt: Option<u64>,
pub slow_ppt: Option<u64>,
pub clock_limits: Option<MinMaxJson<u64>>,
pub slow_memory: bool,
pub root: Option<String>,
}
impl From<OldGpuJson> for GpuJson {
fn from(old_gpu: OldGpuJson) -> Self {
Self {
fast_ppt: old_gpu.fast_ppt,
slow_ppt: old_gpu.slow_ppt,
tdp: None,
tdp_boost: None,
clock_limits: old_gpu.clock_limits.clone(),
memory_clock: None,
root: old_gpu.root.clone(),
}
}
}

View file

@ -0,0 +1,58 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::persist::{BatteryJson, CpuJson, DriverJson, FileJson, SettingsJson, LATEST_VERSION};
use super::gpu::OldGpuJson;
#[derive(Serialize, Deserialize, Clone)]
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, Clone)]
pub struct OldSettingsJson {
pub version: u64,
pub name: String,
pub persistent: bool,
pub cpus: Vec<CpuJson>,
pub gpu: OldGpuJson,
pub battery: BatteryJson,
pub provider: Option<DriverJson>,
pub events: Option<OldOnEventJson>,
}
impl From<OldSettingsJson> for 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().into(),
battery: old_settings.battery.clone(),
provider: old_settings.provider.clone(),
tags: Vec::new(),
}
}
}
impl From<OldSettingsJson> for FileJson {
fn from(old_settings: OldSettingsJson) -> Self {
let mut variants = HashMap::new();
let variant = SettingsJson::from(old_settings.clone());
variants.insert(0, variant);
Self {
version: LATEST_VERSION,
name: old_settings.name.clone(),
app_id: todo!(),
variants,
}
}
}

View file

@ -13,7 +13,7 @@ pub use driver::DriverJson;
pub use file::FileJson;
pub use general::{MinMaxJson, SettingsJson};
pub use gpu::GpuJson;
pub use migration::OldSettingsJson;
pub use migration::{gpu::*, settings::*};
pub use error::{RonError, SerdeError};