loadstore
This commit is contained in:
parent
c0daf3f64c
commit
a2b629beab
2 changed files with 7 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt::format, ops::ControlFlow, result, sync::{atomic::Ordering, Arc}, thread::{self, sleep}, time::Duration};
|
||||
use std::{fmt::format, ops::ControlFlow, path::Path, result, sync::{atomic::Ordering, Arc}, thread::{self, sleep}, time::Duration};
|
||||
|
||||
use anyhow::{Context, Ok, Result};
|
||||
use atomic_float::AtomicF32;
|
||||
|
@ -17,7 +17,7 @@ fn main() -> Result<()> {
|
|||
let directories = ProjectDirs::from("dev", "ank", "Cruise Control").context("no home")?;
|
||||
let auto = Auto::new("../auto/target/release/libauto.so")?;
|
||||
|
||||
let storage = StorageManager::new(directories.config_dir().with_file_name("conf.dat"))?;
|
||||
let storage = StorageManager::new(dbg!(directories.config_dir().to_path_buf().join(Path::new("conf.dat"))))?;
|
||||
|
||||
println!("name: {}", auto.name());
|
||||
|
||||
|
@ -116,10 +116,12 @@ fn main() -> Result<()> {
|
|||
|
||||
println!("launching gui");
|
||||
let (_conf_sender, conf) = watch::channel(CONFIGS);
|
||||
gui(gui_data, toasts, executor, conf, storage).unwrap();
|
||||
gui(gui_data, toasts, executor, conf, storage.clone()).unwrap();
|
||||
|
||||
drop(stream);
|
||||
|
||||
storage.save();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ impl StorageManager {
|
|||
let map = if let Ok(mut file) = File::open(path.clone()) {
|
||||
let mut vec = Vec::new();
|
||||
file.read_to_end(&mut vec)?;
|
||||
postcard::from_bytes(&vec)?
|
||||
postcard::from_bytes_cobs(&mut vec)?
|
||||
} else {
|
||||
DashMap::new()
|
||||
};
|
||||
|
@ -29,6 +29,7 @@ impl StorageManager {
|
|||
pub fn save(&self) {
|
||||
let map = postcard::to_stdvec_cobs(&self.map).unwrap();
|
||||
|
||||
// TODO: mkdir
|
||||
let mut backing_file = File::options().write(true).truncate(true).create(true)
|
||||
.open(self.storage.as_path()).unwrap();
|
||||
backing_file.write_all(&map).unwrap();
|
||||
|
|
Loading…
Reference in a new issue