mirror of
https://github.com/winapps-org/winapps.git
synced 2025-06-06 23:27:19 +02:00
feat: make vm name configurable
This commit is contained in:
parent
6ab6b73adb
commit
6242117629
@ -27,19 +27,16 @@ fn main() {
|
|||||||
let cli = cli();
|
let cli = cli();
|
||||||
let matches = cli.clone().get_matches();
|
let matches = cli.clone().get_matches();
|
||||||
|
|
||||||
|
let config = winapps::load_config(None);
|
||||||
let client: &dyn RemoteClient = &Freerdp {};
|
let client: &dyn RemoteClient = &Freerdp {};
|
||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
Some(("check", _)) => {
|
Some(("check", _)) => {
|
||||||
println!("Checking remote connection");
|
println!("Checking remote connection");
|
||||||
|
|
||||||
let config = winapps::load_config(None);
|
|
||||||
client.check_depends(config);
|
client.check_depends(config);
|
||||||
}
|
}
|
||||||
Some(("connect", _)) => {
|
Some(("connect", _)) => {
|
||||||
println!("Connecting to remote");
|
println!("Connecting to remote");
|
||||||
|
|
||||||
let config = winapps::load_config(None);
|
|
||||||
client.run_app(config, "explorer");
|
client.run_app(config, "explorer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,16 +44,16 @@ fn main() {
|
|||||||
match command.subcommand() {
|
match command.subcommand() {
|
||||||
Some(("create", _)) => {
|
Some(("create", _)) => {
|
||||||
println!("Creating windows 10 vm..");
|
println!("Creating windows 10 vm..");
|
||||||
create_vm();
|
create_vm(config);
|
||||||
}
|
}
|
||||||
Some(("start", _)) => {
|
Some(("start", _)) => {
|
||||||
println!("Starting vm..");
|
println!("Starting vm..");
|
||||||
start_vm();
|
start_vm(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(("kill", _)) => {
|
Some(("kill", _)) => {
|
||||||
println!("Killing vm..");
|
println!("Killing vm..");
|
||||||
kill_vm();
|
kill_vm(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((_, _)) => {
|
Some((_, _)) => {
|
||||||
|
@ -1,38 +1,9 @@
|
|||||||
use home::home_dir;
|
use crate::{get_data_dir, save_config, Config};
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn get_data_dir() -> PathBuf {
|
pub fn create_vm(mut config: Config) {
|
||||||
let home = home_dir().expect("Could not find the home path!");
|
|
||||||
|
|
||||||
let data_dir = match env::var("XDG_DATA_HOME") {
|
|
||||||
Ok(dir) => PathBuf::from(dir).join("winapps"),
|
|
||||||
Err(_) => {
|
|
||||||
println!("Couldn't read XDG_DATA_HOME, falling back to ~/.local/share");
|
|
||||||
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 data_dir = get_data_dir();
|
||||||
|
|
||||||
let output = match Command::new("quickget")
|
let output = match Command::new("quickget")
|
||||||
@ -49,15 +20,25 @@ pub fn create_vm() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config.vm.name = "windows-10-22H2".to_string();
|
||||||
|
config.vm.short_name = "windows-10".to_string();
|
||||||
|
|
||||||
|
save_config(&config, None).expect("Failed to save config, VM will not start properly");
|
||||||
|
|
||||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_vm() {
|
pub fn start_vm(config: Config) {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
|
|
||||||
let command = match Command::new("quickemu")
|
let command = match Command::new("quickemu")
|
||||||
.current_dir(data_dir)
|
.current_dir(data_dir)
|
||||||
.args(["--vm", "windows-10-22H2.conf", "--display", "none"])
|
.args([
|
||||||
|
"--vm",
|
||||||
|
&format!("{}.conf", config.vm.name),
|
||||||
|
"--display",
|
||||||
|
"none",
|
||||||
|
])
|
||||||
.spawn()
|
.spawn()
|
||||||
{
|
{
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
@ -80,10 +61,12 @@ pub fn start_vm() {
|
|||||||
println!("{}", String::from_utf8_lossy(&output.stdout));
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kill_vm() {
|
pub fn kill_vm(config: Config) {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
|
|
||||||
match fs::read_to_string(data_dir.join("windows-10/windows-10-22H2.pid")) {
|
match fs::read_to_string(
|
||||||
|
data_dir.join(format!("{}/{}.pid", config.vm.short_name, config.vm.name)),
|
||||||
|
) {
|
||||||
Ok(pid) => {
|
Ok(pid) => {
|
||||||
let pid = pid.trim();
|
let pid = pid.trim();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user