diff --git a/winapps-cli/src/main.rs b/winapps-cli/src/main.rs index a7af7dd..98e3d63 100644 --- a/winapps-cli/src/main.rs +++ b/winapps-cli/src/main.rs @@ -1,4 +1,5 @@ use clap::Command; +use winapps::quickemu::{create_vm, run_vm}; fn cli() -> Command { Command::new("winapps-cli") @@ -8,6 +9,8 @@ fn cli() -> Command { .allow_external_subcommands(true) .subcommand(Command::new("check").about("Checks remote connection")) .subcommand(Command::new("connect").about("Connects to remote")) + .subcommand(Command::new("create-vm").about("Create a windows 10 vm using quickemu")) + .subcommand(Command::new("run-vm").about("Start the vm using quickemu")) } fn main() { @@ -23,6 +26,14 @@ fn main() { Some(("connect", _)) => { println!("Connecting to remote"); } + Some(("create-vm", _)) => { + println!("Creating windows 10 vm.."); + create_vm(); + } + Some(("run-vm", _)) => { + println!("Starting vm.."); + run_vm(); + } Some((_, _)) => { cli.about("Command not found, try existing ones!") .print_help() diff --git a/winapps/src/lib.rs b/winapps/src/lib.rs index 8e6937b..9ed98cc 100644 --- a/winapps/src/lib.rs +++ b/winapps/src/lib.rs @@ -1,3 +1,5 @@ +pub mod quickemu; + use derive_new::new; use home::home_dir; use serde::{Deserialize, Serialize}; diff --git a/winapps/src/quickemu.rs b/winapps/src/quickemu.rs new file mode 100644 index 0000000..e5a534a --- /dev/null +++ b/winapps/src/quickemu.rs @@ -0,0 +1,66 @@ +use home::home_dir; +use std::path::PathBuf; +use std::process::exit; +use std::process::Command; + +pub(crate) fn get_data_dir() -> PathBuf { + let home = home_dir().expect("Could not find the home path!"); + let data_dir = home.join(".local/share/winapps"); + + if !data_dir.exists() { + let dir = data_dir.clone(); + println!( + "Data directory {:?} does not exist! Creating...", + dir.to_str() + ); + std::fs::create_dir_all(dir).expect("Failed to create directory"); + } + + if !data_dir.is_dir() { + panic!("Data directory {:?} is not a directory!", data_dir.to_str()); + } + + data_dir +} + +pub fn create_vm() { + let data_dir = get_data_dir(); + + let output = match Command::new("quickget") + .current_dir(data_dir) + .arg("windows") + .arg("10") + .output() + { + Ok(o) => o, + Err(e) => { + println!("Failed to execute quickget: {}", e); + println!("Please make sure quickget is installed and in your PATH"); + exit(1); + } + }; + + println!("{}", String::from_utf8_lossy(&output.stdout)); +} + +pub fn run_vm() { + let data_dir = get_data_dir(); + + let output = match Command::new("quickemu") + .current_dir(data_dir) + .arg("--vm") + .arg("windows-10-22H2.conf") + .spawn() + .unwrap() + .wait_with_output() + { + Ok(o) => o, + Err(e) => { + println!("Failed to execute quickemu: {}", e); + println!("Please make sure quickemu is installed and in your PATH"); + exit(1); + } + }; + + println!("{}", String::from_utf8_lossy(&output.stdout)); +}