mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-22 09:18:37 +00:00
fix: remove and replace deprecated writer_legacy
This commit is contained in:
parent
6162a1cf3c
commit
ec191b4e60
9 changed files with 19 additions and 36 deletions
|
@ -7,7 +7,7 @@ use nix::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
file_utils::get_writer_legacy,
|
||||
file_utils::get_writer,
|
||||
profile::{Profile, XRServiceType},
|
||||
runner::{Runner, RunnerStatus},
|
||||
};
|
||||
|
@ -172,7 +172,7 @@ impl CmdRunner {
|
|||
}
|
||||
|
||||
fn save_log(path_s: String, log: &[String]) -> Result<(), std::io::Error> {
|
||||
let mut writer = get_writer_legacy(&path_s);
|
||||
let mut writer = get_writer(&path_s).map_err(std::io::Error::other)?;
|
||||
let log_s = log.concat();
|
||||
writer.write_all(log_s.as_ref())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
constants::CMD_NAME,
|
||||
device_prober::get_xr_usb_devices,
|
||||
file_utils::get_writer_legacy,
|
||||
file_utils::get_writer,
|
||||
paths::get_config_dir,
|
||||
profile::Profile,
|
||||
profiles::{
|
||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||
survive::survive_profile, wivrn::wivrn_profile, wmr::wmr_profile,
|
||||
},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{ser::Error, Deserialize, Serialize};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
fn default_win_size() -> [i32; 2] {
|
||||
|
@ -78,7 +78,7 @@ impl Config {
|
|||
}
|
||||
|
||||
fn save_to_path(&self, path_s: &String) -> Result<(), serde_json::Error> {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).map_err(serde_json::Error::custom)?;
|
||||
serde_json::to_writer_pretty(writer, self)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::APP_ID, file_utils::get_writer_legacy};
|
||||
use crate::{constants::APP_ID, file_utils::get_writer};
|
||||
use reqwest::{
|
||||
header::{HeaderMap, USER_AGENT},
|
||||
Method,
|
||||
|
@ -32,7 +32,7 @@ pub fn download_file(url: String, path: String) -> JoinHandle<Result<(), reqwest
|
|||
if status.is_client_error() || status.is_server_error() {
|
||||
return Err(res.error_for_status().unwrap_err());
|
||||
}
|
||||
let mut writer = get_writer_legacy(&path);
|
||||
let mut writer = get_writer(&path).expect("Unable to write to path");
|
||||
for chunk in res
|
||||
.bytes()
|
||||
.expect("Could not get HTTP response bytes")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{
|
||||
file_utils::{copy_file, deserialize_file, get_writer_legacy, set_file_readonly},
|
||||
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir, SYSTEM_PREFIX},
|
||||
profile::{Profile, XRServiceType},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{ser::Error, Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
@ -71,7 +71,7 @@ fn dump_active_runtime_to_path(
|
|||
active_runtime: &ActiveRuntime,
|
||||
path_s: &String,
|
||||
) -> Result<(), serde_json::Error> {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).map_err(serde_json::Error::custom)?;
|
||||
serde_json::to_writer_pretty(writer, active_runtime)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
file_utils::{deserialize_file, get_writer_legacy},
|
||||
file_utils::{deserialize_file, get_writer},
|
||||
paths::get_xdg_config_dir,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -45,7 +45,7 @@ pub fn get_monado_autorun_config() -> MonadoAutorunConfig {
|
|||
}
|
||||
|
||||
fn dump_monado_autorun_config_to_path(config: &MonadoAutorunConfig, path_s: &String) {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).expect("Unable to save Monado Autorun config");
|
||||
serde_json::to_writer_pretty(writer, config).expect("Unable to save Monado Autorun config");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{
|
||||
file_utils::{copy_file, deserialize_file, get_writer_legacy, set_file_readonly},
|
||||
file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly},
|
||||
paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir},
|
||||
profile::Profile,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{ser::Error, Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct OpenVrPaths {
|
||||
|
@ -67,7 +67,7 @@ fn dump_openvrpaths_to_path(
|
|||
ovr_paths: &OpenVrPaths,
|
||||
path_s: &String,
|
||||
) -> Result<(), serde_json::Error> {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).map_err(serde_json::Error::custom)?;
|
||||
serde_json::to_writer_pretty(writer, ovr_paths)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
file_utils::{deserialize_file, get_writer_legacy},
|
||||
file_utils::{deserialize_file, get_writer},
|
||||
paths::get_xdg_config_dir,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -136,7 +136,7 @@ pub fn get_wivrn_config() -> WivrnConfig {
|
|||
}
|
||||
|
||||
fn dump_wivrn_config_to_path(config: &WivrnConfig, path_s: &String) {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).expect("Unable to save WiVRn config");
|
||||
serde_json::to_writer_pretty(writer, config).expect("Unable to save WiVRn config");
|
||||
}
|
||||
|
||||
|
|
|
@ -24,23 +24,6 @@ pub fn get_writer(path_s: &str) -> anyhow::Result<BufWriter<std::fs::File>> {
|
|||
Ok(BufWriter::new(file))
|
||||
}
|
||||
|
||||
#[deprecated]
|
||||
pub fn get_writer_legacy(path_s: &str) -> BufWriter<std::fs::File> {
|
||||
let path = Path::new(path_s);
|
||||
if let Some(parent) = path.parent() {
|
||||
if !parent.is_dir() {
|
||||
create_dir_all(parent).expect("Could not create dir")
|
||||
}
|
||||
};
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(path)
|
||||
.expect("Could not open file");
|
||||
BufWriter::new(file)
|
||||
}
|
||||
|
||||
pub fn get_reader(path_s: &str) -> Option<BufReader<File>> {
|
||||
let path = Path::new(&path_s);
|
||||
if !(path.is_file() || path.is_symlink()) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
file_utils::get_writer_legacy,
|
||||
file_utils::get_writer,
|
||||
paths::{get_data_dir, get_ipc_file_path, BWRAP_SYSTEM_PREFIX, SYSTEM_PREFIX},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -347,7 +347,7 @@ impl Profile {
|
|||
}
|
||||
|
||||
pub fn dump_profile(&self, path_s: &String) {
|
||||
let writer = get_writer_legacy(path_s);
|
||||
let writer = get_writer(path_s).expect("Could not write profile");
|
||||
serde_json::to_writer_pretty(writer, self).expect("Could not write profile")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue