Skip to content

Commit

Permalink
Merge pull request #19 from themadprofessor/dont_install_existing
Browse files Browse the repository at this point in the history
Don't install existing apps during quick install unless forced
  • Loading branch information
auyer authored Mar 7, 2024
2 parents d3bf27b + 3c977a7 commit 389e628
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
12 changes: 11 additions & 1 deletion libprotonup/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::constants;
use crate::variants::VariantGithubParameters;
use crate::variants::{Variant, VariantGithubParameters};
use anyhow::Result;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -75,6 +75,16 @@ pub struct Download {
pub download_url: String,
pub size: u64,
}

impl Download {
pub fn output_dir(&self, variant: &Variant) -> &str {
match variant {
Variant::GEProton => &self.version,
Variant::WineGE => &self.download_url.rsplit_once("/wine-").unwrap().1.rsplit_once(".tar.xz").unwrap().0
}
}
}

#[cfg(test)]
mod tests {
use crate::variants;
Expand Down
19 changes: 10 additions & 9 deletions protonup-rs/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub(crate) async fn unpack_file(
Ok(())
}

pub async fn run_quick_downloads() {
pub async fn run_quick_downloads(force: bool) {
let found_apps = apps::list_installed_apps();
if found_apps.is_empty() {
println!("No apps found. Please install at least one app before using this feature.");
Expand Down Expand Up @@ -142,6 +142,10 @@ pub async fn run_quick_downloads() {
}
};

if files::check_if_exists(app_inst.default_install_dir(), download.output_dir(&wine_version)) && !force {
continue;
}

let file = download_file(download).await.unwrap();
unpack_file(&file, &destination, &wine_version)
.await
Expand Down Expand Up @@ -230,16 +234,13 @@ pub async fn download_to_selected_app(app: Option<apps::App>) {
// versions_to_install = vec![];

// Let the user choose which releases they want to use
let mut release_list = match helper_menus::multiple_select_menu(
let mut release_list = helper_menus::multiple_select_menu(
"Select the versions you want to download :",
release_list,
) {
Ok(release_list) => release_list,
Err(e) => {
eprintln!("The tag list could not be processed.\nError: {}", e);
vec![]
}
};
).unwrap_or_else(|e| {
eprintln!("The tag list could not be processed.\nError: {}", e);
vec![]
});

// Check if the versions the user selected are already on the disk
check_if_already_downloaded(&mut release_list, &install_dir).await;
Expand Down
10 changes: 7 additions & 3 deletions protonup-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct Opt {
/// Skip Menu, auto detect apps and download using default parameters
#[arg(short, long)]
quick_download: bool,

/// Force install for existing apps during quick downloads
#[arg(short, long)]
force: bool
}

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -58,9 +62,9 @@ impl fmt::Display for InitialMenu {
#[tokio::main]
async fn main() {
// run quick downloads and skip InitialMenu
let Opt { quick_download } = Opt::parse();
let Opt { quick_download, force } = Opt::parse();
if quick_download {
download::run_quick_downloads().await
download::run_quick_downloads(force).await
} else {
let answer: InitialMenu = Select::new(
"ProtonUp Menu: Choose your action:",
Expand All @@ -72,7 +76,7 @@ async fn main() {

// Set parameters based on users choice
match answer {
InitialMenu::QuickUpdate => download::run_quick_downloads().await,
InitialMenu::QuickUpdate => download::run_quick_downloads(force).await,
InitialMenu::DownloadForSteam => download::download_to_selected_app(Some(App::Steam)).await,
InitialMenu::DownloadForLutris => download::download_to_selected_app(Some(App::Lutris)).await,
InitialMenu::DownloadIntoCustomLocation => download::download_to_selected_app(None).await,
Expand Down

0 comments on commit 389e628

Please sign in to comment.