Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AOx0 committed Oct 16, 2022
1 parent b7f9562 commit 1dbfc4a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 44 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions rrm_installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
13 changes: 7 additions & 6 deletions rrm_installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
});
Expand Down
15 changes: 7 additions & 8 deletions src/async_installer.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,7 +14,7 @@ pub async fn install<T: InstallingOptions>(
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);
Expand Down Expand Up @@ -92,11 +91,11 @@ pub async fn install<T: InstallingOptions>(
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");
Expand Down
37 changes: 14 additions & 23 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ 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};
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")]
Expand Down Expand Up @@ -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<Event>| {
if let Ok(event) = res {
Expand All @@ -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;
}
}
Expand All @@ -269,7 +259,6 @@ pub async fn install(
}
}).unwrap();


let result = {
let mut result = String::new();
let mut num = ids.len();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1dbfc4a

Please sign in to comment.