-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create and start vm via quickemu
- Loading branch information
1 parent
dde2255
commit da55fcc
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod quickemu; | ||
|
||
use derive_new::new; | ||
use home::home_dir; | ||
use serde::{Deserialize, Serialize}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |