mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-06 08:09:01 +00:00
feat: load and dump profile as profile methods
This commit is contained in:
parent
f2f2c23fd6
commit
46951f02c9
2 changed files with 21 additions and 16 deletions
|
@ -1,4 +1,7 @@
|
||||||
use crate::{file_utils::get_writer, paths::{SYSTEM_PREFIX, BWRAP_SYSTEM_PREFIX}};
|
use crate::{
|
||||||
|
file_utils::get_writer,
|
||||||
|
paths::{BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
|
||||||
|
};
|
||||||
use expect_dialog::ExpectDialog;
|
use expect_dialog::ExpectDialog;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader};
|
use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader};
|
||||||
|
@ -42,28 +45,28 @@ impl Profile {
|
||||||
opts.push("%command%".into());
|
opts.push("%command%".into());
|
||||||
opts.join(" ")
|
opts.join(" ")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_profile(path: &String) -> Profile {
|
pub fn load_profile(path: &String) -> Self {
|
||||||
let file = File::open(path).expect_dialog("Unable to open profile");
|
let file = File::open(path).expect_dialog("Unable to open profile");
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
serde_json::from_reader(reader).expect_dialog("Faiuled to deserialize profile")
|
serde_json::from_reader(reader).expect_dialog("Faiuled to deserialize profile")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_profile(profile: Profile, path_s: &String) -> () {
|
pub fn dump_profile(&self, path_s: &String) -> () {
|
||||||
let writer = get_writer(path_s);
|
let writer = get_writer(path_s);
|
||||||
serde_json::to_writer_pretty(writer, &profile).expect_dialog("Could not write profile")
|
serde_json::to_writer_pretty(writer, self).expect_dialog("Could not write profile")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::{dump_profile, load_profile, Profile};
|
use super::Profile;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn profile_can_be_loaded() {
|
fn profile_can_be_loaded() {
|
||||||
let profile = load_profile(&"./test/files/profile.json".to_string());
|
let profile = Profile::load_profile(&"./test/files/profile.json".to_string());
|
||||||
assert_eq!(profile.name, "Demo profile");
|
assert_eq!(profile.name, "Demo profile");
|
||||||
assert_eq!(profile.monado_path, "/home/user/monado");
|
assert_eq!(profile.monado_path, "/home/user/monado");
|
||||||
assert_eq!(profile.opencomposite_path, "/home/user/opencomposite");
|
assert_eq!(profile.opencomposite_path, "/home/user/opencomposite");
|
||||||
|
@ -106,8 +109,8 @@ mod tests {
|
||||||
can_be_built: true,
|
can_be_built: true,
|
||||||
};
|
};
|
||||||
let fpath = String::from("./target/testout/testprofile.json");
|
let fpath = String::from("./target/testout/testprofile.json");
|
||||||
dump_profile(p, &fpath);
|
p.dump_profile(&fpath);
|
||||||
let loaded = load_profile(&fpath);
|
let loaded = Profile::load_profile(&fpath);
|
||||||
assert_eq!(loaded.name, "Demo profile");
|
assert_eq!(loaded.name, "Demo profile");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
loaded.libsurvive_path,
|
loaded.libsurvive_path,
|
||||||
|
|
|
@ -199,7 +199,7 @@ impl Runner {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::profile::load_profile;
|
use crate::profile::Profile;
|
||||||
|
|
||||||
use super::{Runner, RunnerStatus};
|
use super::{Runner, RunnerStatus};
|
||||||
use core::time;
|
use core::time;
|
||||||
|
@ -241,6 +241,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_create_from_profile() {
|
fn can_create_from_profile() {
|
||||||
Runner::monado_runner_from_profile(load_profile(&"./test/files/profile.json".to_string()));
|
Runner::monado_runner_from_profile(Profile::load_profile(
|
||||||
|
&"./test/files/profile.json".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue