finish unzip, deploy, undeploy, and cli
This commit is contained in:
parent
251ee8b2c5
commit
67a5061830
|
@ -8,5 +8,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
clap = { version = "4.3.11", features = ["derive"] }
|
||||
compress-tools = "0.14.3"
|
||||
opener = "0.6.1"
|
||||
serde = { version = "1.0.170", features = ["derive"] }
|
||||
serde_json = "1.0.100"
|
||||
walkdir = "2.3.3"
|
||||
|
|
79
src/lib.rs
79
src/lib.rs
|
@ -3,6 +3,7 @@ use std::{
|
|||
fs::{self, File},
|
||||
path::Path,
|
||||
};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -110,11 +111,89 @@ pub fn unzip(cfg: Config) {
|
|||
pub fn deploy(cfg: Config) {
|
||||
// get all folders in cfg.folders
|
||||
// copy the contents of them into cfg.game_folder
|
||||
//
|
||||
// for $folder in folders:
|
||||
// cp $folder/* $gamefolder
|
||||
// end
|
||||
if let Some(_) = Path::new(&cfg.archives).parent() {
|
||||
fs::create_dir_all(&cfg.archives).expect("couldn't create needed folders")
|
||||
};
|
||||
if let Some(_) = Path::new(&cfg.folders).parent() {
|
||||
fs::create_dir_all(&cfg.folders).expect("couldn't create needed folders")
|
||||
};
|
||||
|
||||
let all = fs::read_dir(cfg.folders).expect("couldn't read folders path");
|
||||
for a in all {
|
||||
let p = a.unwrap();
|
||||
let internalfiles = fs::read_dir(&p.path()).expect("couldn't get mod contents");
|
||||
println!("{}", p.file_name().to_str().unwrap());
|
||||
for f in internalfiles {
|
||||
let newf = f.unwrap().path();
|
||||
for e in WalkDir::new(&newf /* WHY WHY WHY */)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
if e.metadata().unwrap().is_file() {
|
||||
let full_path = e.path().display().to_string();
|
||||
let split = full_path
|
||||
.split(p.file_name().to_str().unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
let game_path = split[split.len() - 1];
|
||||
println!(" - {game_path}");
|
||||
|
||||
let deployed_path = format!("{}{}", cfg.game_folder, game_path);
|
||||
let mut deployed_path_split = deployed_path.split('/').collect::<Vec<&str>>();
|
||||
deployed_path_split.pop();
|
||||
let new_deployed_path = deployed_path_split.join("/");
|
||||
fs::create_dir_all(new_deployed_path).expect("couldn't make folders in game folder (nice error message asshat i bet this'll be real nice for users to figure out)");
|
||||
|
||||
fs::copy(
|
||||
format!("{}/{}", p.path().display(), game_path),
|
||||
deployed_path,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn undeploy(cfg: Config) {
|
||||
// get all folders in cfg.folders
|
||||
// remove the contents of all of them from cfg.game_folder
|
||||
if let Some(_) = Path::new(&cfg.archives).parent() {
|
||||
fs::create_dir_all(&cfg.archives).expect("couldn't create needed folders")
|
||||
};
|
||||
if let Some(_) = Path::new(&cfg.folders).parent() {
|
||||
fs::create_dir_all(&cfg.folders).expect("couldn't create needed folders")
|
||||
};
|
||||
|
||||
let all = fs::read_dir(cfg.folders).expect("couldn't read folders path");
|
||||
for a in all {
|
||||
let p = a.unwrap();
|
||||
let internalfiles = fs::read_dir(&p.path()).expect("couldn't get mod contents");
|
||||
println!("{}", p.file_name().to_str().unwrap());
|
||||
for f in internalfiles {
|
||||
let newf = f.unwrap().path();
|
||||
for e in WalkDir::new(&newf /* WHY WHY WHY */)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
if e.metadata().unwrap().is_file() {
|
||||
let full_path = e.path().display().to_string();
|
||||
let split = full_path
|
||||
.split(p.file_name().to_str().unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
let game_path = split[split.len() - 1];
|
||||
println!(" - {game_path}");
|
||||
|
||||
let deployed_path = format!("{}{}", cfg.game_folder, game_path);
|
||||
|
||||
fs::remove_file(deployed_path).expect("couldnt remove the fuckin. the thing. the got damn. the old mod. yeah i'm a cs professional how could you tell");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -1,29 +1,17 @@
|
|||
use std::{path::Path, fs::{File, self}};
|
||||
|
||||
use clap::Parser;
|
||||
use compress_tools::*;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
struct Args {
|
||||
#[arg(short, long)]
|
||||
input: String,
|
||||
|
||||
#[arg(short, long)]
|
||||
output: String,
|
||||
}
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
// let args = Args::parse();
|
||||
// println!("{:?}", args);
|
||||
|
||||
let config_location = cyber_mod_manager::get_config_location();
|
||||
let steam_location = cyber_mod_manager::get_steam_location();
|
||||
|
||||
println!("Config: {}", config_location);
|
||||
println!("Steam: {}", steam_location);
|
||||
|
||||
cyber_mod_manager::create_config(&format!("{config_location}/CyberModManager/config.json"));
|
||||
|
||||
let cfg = cyber_mod_manager::read_config(&format!("{config_location}/CyberModManager/config.json"));
|
||||
cyber_mod_manager::unzip(cfg);
|
||||
let cfg =
|
||||
cyber_mod_manager::read_config(&format!("{config_location}/CyberModManager/config.json"));
|
||||
|
||||
match &env::args().collect::<Vec<String>>()[1][..] {
|
||||
"deploy" => cyber_mod_manager::deploy(cfg),
|
||||
"undeploy" => cyber_mod_manager::undeploy(cfg),
|
||||
"unzip" => cyber_mod_manager::unzip(cfg),
|
||||
"openfolder" => opener::open(cfg.archives).unwrap(),
|
||||
_ => panic!("arg not supported")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue