mirror of
https://github.com/winapps-org/winapps.git
synced 2025-06-05 22:57:19 +02:00
feat: create and start vm via quickemu
This commit is contained in:
parent
dde2255b57
commit
da55fcc2ed
@ -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()
|
||||
|
@ -1,3 +1,5 @@
|
||||
pub mod quickemu;
|
||||
|
||||
use derive_new::new;
|
||||
use home::home_dir;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
66
winapps/src/quickemu.rs
Normal file
66
winapps/src/quickemu.rs
Normal file
@ -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));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user