'V B ~vomiting face~'- cherry, 2023

This commit is contained in:
2023-06-10 09:33:16 +02:00
parent 46f452a71f
commit b6933d357a
18 changed files with 562 additions and 710 deletions

25
src/http.rs Normal file
View File

@@ -0,0 +1,25 @@
use std::{fs, io::Write, path::Path, str};
pub fn get_body(url: &str) -> Vec<u8> {
let mut res: Vec<u8> = Vec::new();
http_req::request::get(url, &mut res).unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
res
}
pub fn _get_body_string(url: &str) -> String {
String::from_utf8(get_body(url)).unwrap()
}
pub fn download_file(url: &str, file_path: &Path) {
let body = get_body(url);
let mut f = fs::File::create(file_path).unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
f.write_all(&body).unwrap_or_else(|error| {
panic!("\n\n{}:\n{:?}", "Error", error);
});
}

49
src/main.rs Normal file
View File

@@ -0,0 +1,49 @@
mod http;
use std::path::PathBuf;
const MASTER: &str = "https://master.alterware.dev";
fn download_and_launch(url: &str, file_path: &PathBuf) {
http::download_file(url, file_path);
std::process::Command::new(file_path)
.spawn()
.unwrap()
.wait()
.unwrap();
}
fn main() {
let args: Vec<String> = std::env::args().collect();
let game: String;
if args.len() > 1 {
game = String::from(&args[1]);
} else {
// check if iw4sp.exe or iw4mp.exe exists
if std::path::Path::new("iw4sp.exe").exists() || std::path::Path::new("iw4mp.exe").exists()
{
game = String::from("iw4-sp");
} else if std::path::Path::new("iw5sp.exe").exists()
|| std::path::Path::new("iw5mp.exe").exists()
|| std::path::Path::new("iw5mp_server.exe").exists()
{
game = String::from("iw5-mod");
} else {
println!("No game specified and no game found in current directory");
return;
}
}
if game == "iw4-sp" {
download_and_launch(
&format!("{}/iw4/iw4-sp.exe", MASTER),
&PathBuf::from("iw4-sp.exe"),
);
} else if game == "iw5-mod" {
download_and_launch(
&format!("{}/iw5/iw5-mod.exe", MASTER),
&PathBuf::from("iw5-mod.exe"),
);
} else {
println!("Invalid game");
}
}