Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more async and allow parallel downloads #21

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ repos:
rev: v1.14.5
hooks:
- id: typos
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: clippy
114 changes: 102 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions libprotonup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ readme = "../README.md"
description = "Library for Custom Proton Download and installation"

[dependencies]
arcstr = "1.1.5"
anyhow = "1.0"
async-compression = { version = "0.4.6", features = ['gzip', 'xz', 'tokio'] }
dirs = "5.0"
flate2 = "1.0"
futures-util = "0.3"
hex = "0.4"
hex-literal = "0.4"
pin-project = "1.1.5"
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls",
"stream",
"rustls",
"json",
"rustls-tls",
"stream",
"rustls",
"json",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10"
structopt = "0.3"
tar = "0.4"
xz2 = "0.1"
tokio = { version = "1.36", features = ["macros"] }
tokio-stream = { version = "0.1.14", features = ["fs"] }
tokio-tar = "0.3.1"
tokio-util = "0.7.10"

[dev-dependencies]
tokio = { version = "1.35", features = ["macros", "rt"] }
51 changes: 33 additions & 18 deletions libprotonup/src/apps.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use arcstr::ArcStr;
use futures_util::stream::{self, StreamExt};
use std::fmt;

use crate::{
files::{self, list_folders_in_path},
variants::Variant,
};
use std::fmt;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum App {
Expand Down Expand Up @@ -41,13 +44,15 @@ impl App {
}

/// Checks the versions (Native vs Flatpak) of the App that are installed
pub fn detect_installation_method(&self) -> Vec<AppInstallations> {
pub async fn detect_installation_method(&self) -> Vec<AppInstallations> {
match *self {
Self::Steam => {
detect_installations(&[AppInstallations::Steam, AppInstallations::SteamFlatpak])
.await
}
Self::Lutris => {
detect_installations(&[AppInstallations::Lutris, AppInstallations::LutrisFlatpak])
.await
}
}
}
Expand All @@ -74,19 +79,23 @@ impl fmt::Display for AppInstallations {

impl AppInstallations {
/// Default directory that wine is extracted to
pub fn default_install_dir(&self) -> &'static str {
pub const fn default_install_dir(&self) -> ArcStr {
match *self {
Self::Steam => "~/.steam/steam/compatibilitytools.d/",
Self::Steam => arcstr::literal!("~/.steam/steam/compatibilitytools.d/"),
Self::SteamFlatpak => {
"~/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/"
arcstr::literal!(
"~/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/"
)
}
Self::Lutris => arcstr::literal!("~/.local/share/lutris/runners/wine/"),
Self::LutrisFlatpak => {
arcstr::literal!("~/.var/app/net.lutris.Lutris/data/lutris/runners/wine/")
}
Self::Lutris => "~/.local/share/lutris/runners/wine/",
Self::LutrisFlatpak => "~/.var/app/net.lutris.Lutris/data/lutris/runners/wine/",
}
}

/// The app root folder
pub fn app_base_dir(&self) -> &'static str {
pub const fn app_base_dir(&self) -> &'static str {
match *self {
Self::Steam => "~/.steam/steam/",
Self::SteamFlatpak => "~/.var/app/com.valvesoftware.Steam/data/Steam/",
Expand All @@ -96,12 +105,12 @@ impl AppInstallations {
}

/// Get a list of the currently installed wine versions
pub fn list_installed_versions(&self) -> Result<Vec<String>, anyhow::Error> {
list_folders_in_path(self.default_install_dir())
pub async fn list_installed_versions(&self) -> Result<Vec<String>, anyhow::Error> {
list_folders_in_path(&self.default_install_dir()).await
}

/// Returns the base App
pub fn into_app(&self) -> App {
pub const fn as_app(&self) -> App {
match *self {
Self::Steam | Self::SteamFlatpak => App::Steam,
Self::Lutris | Self::LutrisFlatpak => App::Lutris,
Expand All @@ -110,17 +119,23 @@ impl AppInstallations {
}

/// list_installed_apps returns a vector of App variants that are installed
pub fn list_installed_apps() -> Vec<AppInstallations> {
detect_installations(APP_INSTALLATIONS_VARIANTS)
pub async fn list_installed_apps() -> Vec<AppInstallations> {
detect_installations(APP_INSTALLATIONS_VARIANTS).await
}

/// detect_installations returns a vector of App variants that are detected
fn detect_installations(app_installations: &[AppInstallations]) -> Vec<AppInstallations> {
app_installations
.iter()
.filter(|app| files::check_if_exists(app.app_base_dir(), ""))
.cloned()
async fn detect_installations(app_installations: &[AppInstallations]) -> Vec<AppInstallations> {
stream::iter(app_installations)
.filter_map(|app| async move {
if files::check_if_exists(app.app_base_dir(), "").await {
Some(app.clone())
} else {
None
}
})
.map(|app| app.clone())
.collect()
.await
}

/// APP_INSTALLATIONS_VARIANTS contains the subset of variants of the App enum that are actual apps
Expand Down
2 changes: 0 additions & 2 deletions libprotonup/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

pub const TEMP_DIR: &str = "/tmp/";

pub const GITHUB_URL: &str = "https://api.github.com/repos";

pub const GEPROTON_GITHUB_REPO: &str = "proton-ge-custom";
Expand Down
Loading
Loading