require references

close #67
This commit is contained in:
mxve 2024-02-07 11:37:34 +01:00
parent ccdde3d99f
commit 1dd18317cf

View File

@ -34,7 +34,11 @@ fn get_installed_games(games: &Vec<Game>) -> Vec<(u32, PathBuf)> {
for game in games { for game in games {
if let Ok(Some((app, library))) = steamdir.find_app(game.app_id) { if let Ok(Some((app, library))) = steamdir.find_app(game.app_id) {
let game_path = library.path().join("steamapps").join("common").join(&app.install_dir); let game_path = library
.path()
.join("steamapps")
.join("common")
.join(&app.install_dir);
installed_games.push((game.app_id, game_path)); installed_games.push((game.app_id, game_path));
} }
} }
@ -130,13 +134,9 @@ async fn windows_launcher_install(games: &Vec<Game<'_>>) {
println!("{}: {}", id, path.display()); println!("{}: {}", id, path.display());
} }
println!("Enter the ID of the game you want to install the AlterWare client for, enter 0 for manual selection:"); println!("Enter the ID of the game you want to install the AlterWare client for:");
let input: u32 = misc::stdin().parse().unwrap(); let input: u32 = misc::stdin().parse().unwrap();
if input == 0 {
return manual_install(games).await;
}
for (id, path) in installed_games.iter() { for (id, path) in installed_games.iter() {
if *id == input { if *id == input {
let game = games.iter().find(|&g| g.app_id == input).unwrap(); let game = games.iter().find(|&g| g.app_id == input).unwrap();
@ -156,31 +156,33 @@ async fn windows_launcher_install(games: &Vec<Game<'_>>) {
} }
std::process::exit(0); std::process::exit(0);
} else { } else {
manual_install(games).await;
}
}
fn prompt_client_selection(games: &[Game]) -> String {
println!( println!(
"Couldn't detect any games, please select a client to install in the current directory:" "No installed games found. Make sure to place the launcher in the game directory."
); );
for (i, g) in games.iter().enumerate() {
for c in g.client.iter() {
println!("{}: {}", i, c);
} }
} }
let input: usize = misc::stdin().parse().unwrap();
String::from(games[input].client[0])
}
async fn manual_install(games: &[Game<'_>]) { // fn prompt_client_selection(games: &[Game]) -> String {
let selection = prompt_client_selection(games); // println!(
let game = games.iter().find(|&g| g.client[0] == selection).unwrap(); // "Couldn't detect any games, please select a client to install in the current directory:"
update(game, &env::current_dir().unwrap(), false, false).await; // );
println!("Installation complete. Please run the launcher again or use a shortcut to launch the game."); // for (i, g) in games.iter().enumerate() {
std::io::stdin().read_line(&mut String::new()).unwrap(); // for c in g.client.iter() {
std::process::exit(0); // println!("{}: {}", i, c);
} // }
// }
// let input: usize = misc::stdin().parse().unwrap();
// String::from(games[input].client[0])
// }
// async fn manual_install(games: &[Game<'_>]) {
// let selection = prompt_client_selection(games);
// let game = games.iter().find(|&g| g.client[0] == selection).unwrap();
// update(game, &env::current_dir().unwrap(), false, false).await;
// println!("Installation complete. Please run the launcher again or use a shortcut to launch the game.");
// std::io::stdin().read_line(&mut String::new()).unwrap();
// std::process::exit(0);
// }
fn total_download_size(cdn_info: &Vec<CdnFile>, remote_dir: &str) -> u64 { fn total_download_size(cdn_info: &Vec<CdnFile>, remote_dir: &str) -> u64 {
let remote_dir = format!("{}/", remote_dir); let remote_dir = format!("{}/", remote_dir);
@ -312,7 +314,10 @@ async fn update(game: &Game<'_>, dir: &Path, bonus_content: bool, force: bool) {
Err(_) => continue, Err(_) => continue,
}; };
if iw4x_dirs.iter().any(|prefix| file_path_rel.starts_with(Path::new(prefix))) { if iw4x_dirs
.iter()
.any(|prefix| file_path_rel.starts_with(Path::new(prefix)))
{
if !cdn_info if !cdn_info
.iter() .iter()
.any(|cdn_file| cdn_file.name.starts_with("iw4")) .any(|cdn_file| cdn_file.name.starts_with("iw4"))
@ -337,7 +342,7 @@ async fn update(game: &Game<'_>, dir: &Path, bonus_content: bool, force: bool) {
misc::cute_path(&file_path) misc::cute_path(&file_path)
); );
if let Err(_) = fs::remove_file(&file_path) { if fs::remove_file(&file_path).is_err() {
println!( println!(
"[{}] Couldn't delete {}", "[{}] Couldn't delete {}",
"Error".bright_red(), "Error".bright_red(),
@ -364,7 +369,7 @@ async fn update(game: &Game<'_>, dir: &Path, bonus_content: bool, force: bool) {
for f in game.delete.iter() { for f in game.delete.iter() {
let file_path = dir.join(f); let file_path = dir.join(f);
if file_path.exists() { if file_path.exists() {
if let Err(_) = fs::remove_file(&file_path) { if fs::remove_file(&file_path).is_err() {
println!( println!(
"[{}] Couldn't delete {}", "[{}] Couldn't delete {}",
"Error".bright_red(), "Error".bright_red(),
@ -620,9 +625,6 @@ async fn main() {
#[cfg(windows)] #[cfg(windows)]
windows_launcher_install(&games).await; windows_launcher_install(&games).await;
#[cfg(not(windows))]
manual_install(&games).await;
println!("{}", "Game not found!".bright_red()); println!("{}", "Game not found!".bright_red());
println!("Place the launcher in the game folder, if that doesn't work specify the client on the command line (ex. alterware-launcher.exe iw4-sp)"); println!("Place the launcher in the game folder, if that doesn't work specify the client on the command line (ex. alterware-launcher.exe iw4-sp)");
println!("Press enter to exit..."); println!("Press enter to exit...");