diff --git a/Cargo.lock b/Cargo.lock index 171792e..c7e12e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1261,6 +1261,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures" version = "0.3.32" @@ -3889,6 +3895,7 @@ version = "0.1.0" dependencies = [ "clap", "crossterm", + "fs_extra", "iced", "ratatui", "rayon", diff --git a/Cargo.toml b/Cargo.toml index 0d9c6ae..02341ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] clap = { version = "4.6.1", features = ["derive"] } crossterm = "0.29.0" +fs_extra = "1.3.0" iced = { version = "0.14.0", features = ["advanced", "tokio"] } ratatui = "0.30.0" rayon = "1.12.0" diff --git a/src/install.rs b/src/install.rs index 50a05a8..a818c94 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,8 +1,10 @@ +use fs_extra::dir::{CopyOptions, copy, create}; use std::env; use std::error::Error; -use std::fs::{File, create_dir_all}; +use std::fs::{File, create_dir_all, read_dir, remove_dir_all}; use std::io::Write; use std::path::PathBuf; +use std::process::Command; use std::process::exit; use tetanus::funcs::get_user_input; @@ -10,12 +12,16 @@ pub fn install() -> Result<(), Box> { if let Some(homedir) = env::home_dir() { let mut config_path = homedir.clone(); config_path.push(".config/tetanus"); + let root_config_folder_path = config_path.clone(); let mut projects_path = config_path.clone(); projects_path.push("projects"); let mut module_path = config_path.clone(); - module_path.push("modules/default"); + module_path.push("modules"); + let default_module_path = module_path.join("default"); + create_dir_all(&default_module_path)?; + let mut note_templates_path = config_path.clone(); + note_templates_path.push("note_templates"); create_dir_all(&module_path)?; - module_path.pop(); module_path.push("custom"); create_dir_all(&module_path)?; module_path.pop(); @@ -44,7 +50,7 @@ pub fn install() -> Result<(), Box> { let mut default_project_file = File::create(projects_path)?; config_path.pop(); config_path.push("server.conf"); - let mut server_config_file = File::create(config_path)?; + let mut server_config_file = File::create(&config_path)?; server_config_file.write("address: 127.0.0.1:31337\n".as_bytes())?; server_config_file.write("running: false\n".as_bytes())?; default_project_file.write("org_name: default\n".as_bytes())?; @@ -64,6 +70,32 @@ pub fn install() -> Result<(), Box> { .write(format!("upcoming_notes: {}\n", upcoming_notes_path.display()).as_bytes())?; client_config_file.write(format!("module_path: {}\n", module_path.display()).as_bytes())?; client_config_file.write(format!("template_box: {}\n", template_box).as_bytes())?; + println!("\ndefault config files written!"); + println!("downloading default notes and modules..."); + create_dir_all("./temp")?; + env::set_current_dir("./temp")?; + let (git_clone_status) = Command::new("git") + .arg("clone") + .arg("https://git.pyro.monster/pyro/tetanus.git") + .status()? + .success(); + if git_clone_status { + let mut options = CopyOptions::new(); + options.overwrite = true; + println!("copying note_templates..."); + copy( + "./tetanus/note_templates", + root_config_folder_path, + &options, + )?; + println!("copying default-modules..."); + for entry in read_dir("./tetanus/default-modules")? { + let entry = entry?; + copy(entry.path(), default_module_path.clone(), &options)?; + } + env::set_current_dir("../")?; + remove_dir_all("./temp")?; + } } else { eprintln!("error finding home directory!"); exit(1);