diff --git a/Cargo.lock b/Cargo.lock index 504652f..63a35d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1360,7 +1360,6 @@ version = "0.0.1-alpha.7" dependencies = [ "directories", "dotenv", - "fs_extra", "include_dir", "rrm_locals", "serde", diff --git a/rrm_installer/Cargo.toml b/rrm_installer/Cargo.toml index b1713ee..2653152 100644 --- a/rrm_installer/Cargo.toml +++ b/rrm_installer/Cargo.toml @@ -11,15 +11,10 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -dev = [] - - [dependencies] serde = {version = "1.0.137", features = ["derive"]} serde_json = "1.0.81" include_dir = "0.7.2" directories = "4.0.1" dotenv = "0.15.0" -fs_extra = "1.2.0" rrm_locals = {path="../rrm_locals", version="0.0.1-alpha.7"} diff --git a/rrm_installer/src/lib.rs b/rrm_installer/src/lib.rs index 1a796a5..d8eaf8b 100644 --- a/rrm_installer/src/lib.rs +++ b/rrm_installer/src/lib.rs @@ -2,20 +2,18 @@ extern crate core; use rrm_locals::GamePath; use serde::{Deserialize, Serialize}; -use std::env::current_dir; use std::fs; use std::fs::{File, OpenOptions}; use std::io::{BufReader, Read, Write}; +use directories; use include_dir::{include_dir, Dir}; use std::path::{Path, PathBuf}; use std::process::exit; -use directories; -use fs_extra; +use directories::{ProjectDirs, UserDirs}; #[cfg(any(target_os = "macos", target_os = "linux"))] use std::os::unix::fs::PermissionsExt; -use directories::{ProjectDirs, UserDirs}; #[cfg(target_os = "windows")] static DEFAULT_PAGING_SOFTWARE: &str = r"C:\Windows\System32\more.com"; @@ -42,7 +40,7 @@ mod tests { } pub fn get_or_create_config_dir() -> PathBuf { - if let Some(path) = env_var_config("XDG_CONFIG_HOME") { + if let Some(path) = env_var_config("XDG_CONFIG_HOME") { return path; } @@ -233,7 +231,10 @@ impl Installer { .read(false) .open(&get_or_create_config_dir().join("config")) .unwrap_or_else(|err| { - eprintln!("Failed to open config file at {}", &get_or_create_config_dir().join("config").display()); + eprintln!( + "Failed to open config file at {}", + &get_or_create_config_dir().join("config").display() + ); eprintln!("Error: {}", err); exit(1); }); diff --git a/src/async_installer.rs b/src/async_installer.rs index 24bfe74..2c08212 100644 --- a/src/async_installer.rs +++ b/src/async_installer.rs @@ -1,10 +1,9 @@ use crate::args::InstallingOptions; use crate::utils::*; use async_recursion::async_recursion; +use notify::{RecommendedWatcher, Watcher}; use rrm_installer::{get_or_create_config_dir, Installer}; use std::process::Stdio; -use std::sync::Arc; -use notify::{RecommendedWatcher, Watcher}; use tokio::{ io::{AsyncBufReadExt, BufReader}, process::Command, @@ -15,7 +14,7 @@ pub async fn install( args: T, mods: &[&str], installer: Installer, - mut start_file_watcher: &mut RecommendedWatcher, + start_file_watcher: &mut RecommendedWatcher, path_downloads: &Path, ) -> String { let install_message = Installer::gen_install_string(&mods); @@ -92,11 +91,11 @@ pub async fn install( while let Some(line) = reader.next_line().await.unwrap() { if line.contains("Waiting for client config...OK") { start_file_watcher - .watch( - &get_or_create_config_dir().join(path_downloads.parent().unwrap()), - notify::RecursiveMode::Recursive, - ) - .unwrap(); + .watch( + &get_or_create_config_dir().join(path_downloads.parent().unwrap()), + notify::RecursiveMode::Recursive, + ) + .unwrap(); } if line.contains("Update complete") { log!(Warning: "SteamCMD updated"); diff --git a/src/install.rs b/src/install.rs index 8b54086..0748ecf 100644 --- a/src/install.rs +++ b/src/install.rs @@ -4,6 +4,9 @@ use crate::utils::*; use async_recursion::async_recursion; use fs_extra::dir; use fs_extra::dir::CopyOptions; +use notify::event::CreateKind; +use notify::Event; +use notify::Watcher; use regex::Regex; use rrm_locals::{FilterBy, Filtrable}; use rrm_scrap::{FlagSet, ModSteamInfo}; @@ -11,13 +14,6 @@ use std::cell::RefCell; use std::collections::HashSet; use std::io; use std::io::prelude::*; -use std::slice::SliceIndex; -use std::sync::mpsc::channel; -use std::sync::{Arc, Mutex}; -use std::sync::atomic::AtomicUsize; -use std::thread::sleep; -use notify::Event; -use notify::event::CreateKind; use text_io::try_read; #[cfg(target_os = "windows")] @@ -235,18 +231,12 @@ pub async fn install( clear_leftlovers(&path_downloads, &args); clear_leftlovers(&PathBuf::from(PATH), &args); - extern crate notify; - - use notify::{Watcher}; - use std::time::Duration; - if args.is_verbose() { log!(Warning: "Starting file watcher"); } - let mut cur: AtomicUsize = AtomicUsize::new(0); + let mut cur = 0; let number_to_install = ids.len(); - let verbose = args.is_verbose(); let mut last_printed = String::new(); let mut watcher = notify::recommended_watcher(move |res: notify::Result| { if let Ok(event) = res { @@ -258,8 +248,8 @@ pub async fn install( let name = name.to_str().unwrap(); if name == "294100" { if current != last_printed { - *cur.get_mut() += 1; - log!(Status: "[{1:0>3}/{2:0>3}] Downloading {0}", current, cur.get_mut(), number_to_install); + cur += 1; + log!(Status: "[{1:0>3}/{2:0>3}] Downloading {0}", current, cur, number_to_install); last_printed = current; } } @@ -269,7 +259,6 @@ pub async fn install( } }).unwrap(); - let result = { let mut result = String::new(); let mut num = ids.len(); @@ -287,7 +276,7 @@ pub async fn install( &ids[n..n + 200], i.clone(), &mut watcher, - &path_downloads + &path_downloads, ) .await; result.push_str(&r); @@ -303,7 +292,7 @@ pub async fn install( &ids[n..n + num], i.clone(), &mut watcher, - &path_downloads + &path_downloads, ) .await; result.push_str(&r); @@ -314,9 +303,9 @@ pub async fn install( log!(Status: "Installer finished"); } - watcher.unwatch( - &rrm_installer::get_or_create_config_dir().join(path_downloads.parent().unwrap()), - ).unwrap(); + watcher + .unwatch(&rrm_installer::get_or_create_config_dir().join(path_downloads.parent().unwrap())) + .unwrap(); let mut successful_ids = HashSet::new(); @@ -349,7 +338,9 @@ pub async fn install( let source = format!( "{}", rrm_installer::get_or_create_config_dir() - .join(PATH).join(&id).display() + .join(PATH) + .join(&id) + .display() ); let options = CopyOptions { diff --git a/src/main.rs b/src/main.rs index 22ec512..cb348e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ extern crate core; use crate::args::Options; use std::collections::HashSet; -use rrm_installer::get_or_create_config_dir; mod args; mod async_installer;