Skip to content

Commit

Permalink
Merge pull request #1 from ddotthomas/adding-lutris-support
Browse files Browse the repository at this point in the history
Adding lutris support
  • Loading branch information
ddotthomas committed Feb 17, 2023
2 parents e4ef49e + c2f0b82 commit 807d0d7
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 31 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It is a single binary. You can just run it, or add it to your path so you can ca
Quick way to add it to your path:
```
cd Downloads
sudo unzip protonup-rs-linux-amd64.zip -d /usr/bin
unzip protonup-rs-linux-amd64.zip -d ~/.local/bin
```


Expand Down
2 changes: 2 additions & 0 deletions libprotonup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ serde_json = "1.0"
sha2 = "0.10"
structopt = "0.3"
tar = "0.4"
actix-rt = "*"
xz2 = "0"
3 changes: 3 additions & 0 deletions libprotonup/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_INSTALL_DIR: &str = "~/.steam/steam/compatibilitytools.d/";
pub const DEFAULT_INSTALL_DIR_FLATPAK: &str =
"~/.var/app/com.valvesoftware.Steam/data/Steam/compatibilitytools.d/";
pub const DEFAULT_LUTRIS_INSTALL_DIR: &str = "~/.local/share/lutris/runners/wine/";
pub const DEFAULT_LUTRIS_INSTALL_DIR_FLATPAK: &str = "~/.var/app/net.lutris.Lutris/data/lutris/runners/wine/";
pub const TEMP_DIR: &str = "/tmp/";

pub const GITHUB: &str = "https://api.github.com/repos";
pub const GITHUB_REPO: &str = "proton-ge-custom";
pub const LUTRIS_GITHUB_REPO: &str = "wine-ge-custom";
pub const GITHUB_ACCOUNT: &str = "GloriousEggroll";
pub const USER_AGENT: &str = "protoup-rs";

Expand Down
32 changes: 32 additions & 0 deletions libprotonup/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::constants;
use crate::utils;
use anyhow::{Context, Result};
use flate2::read::GzDecoder;
use xz2::read::XzDecoder;
use futures_util::StreamExt;
use reqwest::header::USER_AGENT;
use sha2::{Digest, Sha512};
Expand All @@ -23,6 +24,17 @@ fn path_result(path: &Path) -> String {
}

pub fn decompress(from_path: &Path, destination_path: &Path) -> Result<()> {
let path_str = from_path.as_os_str().to_string_lossy();

if path_str.ends_with("tar.gz") { decompress_gz(from_path, destination_path) }

else if path_str.ends_with("tar.xz") { decompress_xz(from_path, destination_path) }

else { println!("no decompress\nPath: {:?}", from_path); Ok(()) }
}

/// Decompress a tar.gz file
fn decompress_gz(from_path: &Path, destination_path: &Path) -> Result<()> {
let file = File::open(from_path).with_context(|| {
format!(
"[Decompressing] Failed to open file from Path: {}",
Expand All @@ -41,6 +53,26 @@ pub fn decompress(from_path: &Path, destination_path: &Path) -> Result<()> {
Ok(())
}

/// Decompress a tar.xz file
fn decompress_xz(from_path: &Path, destination_path: &Path) -> Result<()> {
let file = File::open(from_path).with_context(|| {
format!(
"[Decompressing] Failed to open file from Path: {}",
path_result(from_path),
)
})?;

let mut archive = Archive::new(XzDecoder::new(file));

archive.unpack(destination_path).with_context(|| {
format!(
"[Decompressing] Failed to unpack into destination : {}",
path_result(destination_path)
)
})?;
Ok(())
}

/// Creates the progress trackers variable pointers
pub fn create_progress_trackers() -> (Arc<AtomicUsize>, Arc<AtomicBool>) {
(
Expand Down
61 changes: 56 additions & 5 deletions libprotonup/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub struct Asset {
browser_download_url: String,
}

pub async fn list_releases() -> Result<ReleaseList, reqwest::Error> {
pub async fn list_releases(lutris: bool) -> Result<ReleaseList, reqwest::Error> {
let agent = format!("{}/v{}", constants::USER_AGENT, constants::VERSION,);

let url = format!(
"{}/{}/{}/releases",
constants::GITHUB,
constants::GITHUB_ACCOUNT,
constants::GITHUB_REPO,
if lutris {constants::LUTRIS_GITHUB_REPO} else {constants::GITHUB_REPO},
);

let client = reqwest::Client::builder().user_agent(agent).build()?;
Expand All @@ -50,7 +50,7 @@ pub struct Download {
pub created_at: String,
}

pub async fn fetch_data_from_tag(tag: &str) -> Result<Download, reqwest::Error> {
pub async fn fetch_data_from_tag(tag: &str, lutris: bool) -> Result<Download, reqwest::Error> {
let agent = format!("{}/v{}", constants::USER_AGENT, constants::VERSION,);

let client = reqwest::Client::builder().user_agent(agent).build()?;
Expand All @@ -62,7 +62,7 @@ pub async fn fetch_data_from_tag(tag: &str) -> Result<Download, reqwest::Error>
"{}/{}/{}/releases/latest",
constants::GITHUB,
constants::GITHUB_ACCOUNT,
constants::GITHUB_REPO,
if lutris { constants::LUTRIS_GITHUB_REPO } else { constants::GITHUB_REPO },
);
let rel: Release = client.get(url).send().await?.json().await?;
rel
Expand All @@ -72,7 +72,7 @@ pub async fn fetch_data_from_tag(tag: &str) -> Result<Download, reqwest::Error>
"{}/{}/{}/releases/tags/{}",
constants::GITHUB,
constants::GITHUB_ACCOUNT,
constants::GITHUB_REPO,
if lutris { constants::LUTRIS_GITHUB_REPO } else { constants::GITHUB_REPO },
&tag
);
let rel: Release = client.get(url).send().await?.json().await?;
Expand All @@ -90,6 +90,57 @@ pub async fn fetch_data_from_tag(tag: &str) -> Result<Download, reqwest::Error>
download.download = asset.browser_download_url.as_str().to_string();
download.size = asset.size as u64;
}
if asset.name.ends_with("tar.xz") {
download.created_at = asset.created_at.clone();
download.download = asset.browser_download_url.as_str().to_string();
download.size = asset.size as u64;
}
}
Ok(download)
}


#[cfg(test)]
mod tests {
use super::*;


#[actix_rt::test]
async fn test_data_fetch() {
let lutris = true;
let tag = "latest";

let result = match fetch_data_from_tag(tag, lutris).await {
Ok(data) => data,
Err(e) => {eprintln!("Error: {}", e); std::process::exit(1)}
};


println!("Got result: {:?}", result);
}

#[actix_rt::test]
async fn test_releases() {
let agent = format!("{}/v{}", constants::USER_AGENT, constants::VERSION,);

let client = match reqwest::Client::builder().user_agent(agent).build() {
Ok(client) => client,
Err(e) => {eprintln!("Error: {}", e); std::process::exit(1)},
};

let url = format!(
"{}/{}/{}/releases/latest",
constants::GITHUB,
constants::GITHUB_ACCOUNT,
constants::LUTRIS_GITHUB_REPO ,
);

let rel: Release = match client.get(url).send().await {
Ok(res) => res,
Err(e) => {eprintln!("Error: {}", e); std::process::exit(1)},
}
.json().await.unwrap();

println!("Result: {:?}", rel);
}
}
Loading

0 comments on commit 807d0d7

Please sign in to comment.