Skip to content

Commit

Permalink
Merge upstream updates into working gui branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ddotthomas committed Oct 16, 2023
2 parents 8e78cda + 45114f8 commit 60969c8
Show file tree
Hide file tree
Showing 15 changed files with 784 additions and 1,250 deletions.
895 changes: 118 additions & 777 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
resolver="2"
resolver = "2"

members = ["libprotonup", "protonup-rs", "protonup-gui"]

Expand Down
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@ Lib, CLI and GUI(wip) program to automate the installation and update of Proton-

> **NOTE**: This has no relations with the original ProtonUp project, and I am glad it was created.
> ~~This is not nearly as feature complete as the original Protonup~~.
>
> I've create it because the original project had a few issues with its Python dependencies (that most likely got fixed already).
>
> I've create it because the original project had a few issues with its Python dependencies (that most likely got fixed already).
> I wanted to to re-create it in rust, in a way it could be used as a lib and a CLI.
> ~~If this repo gets to a stable and feature rich state, I will publish it to Cargo and other repositories.~~ I guess it got there! Thanks!
[![asciicast](https://asciinema.org/a/rEO6Oipjn4rBkTWAtH1IFf3Xe.svg)](https://asciinema.org/a/rEO6Oipjn4rBkTWAtH1IFf3Xe)
[![asciicast](https://asciinema.org/a/QZ97c4yRwQ6YczTliB1ziZy5Z.svg)](https://asciinema.org/a/QZ97c4yRwQ6YczTliB1ziZy5Z)

## Usage

The default way is to simply invoke the cli, and navigate the text interface.

```bash
protonup-rs
```

To run a quick update and get the latest GE Proton version without navigating the TUI, you can use the quick flags:
```bash
-q, --quick-download Download latest directly
-f, --quick-download-flatpak Download latest for Steam FlatPak
-l, --lutris-quick-download Download latest Wine GE for Lutris
-L, --lutris-quick-download-flatpak Download latest Wine GE for Lutris FlatPak
-h, --help Print help
```
You can also combine them and get all the latest version running:
To run a quick update and get the latest GE Proton version without navigating the TUI, you can use the quick flag:

```bash
protonup-rs -q -f -l -L
Usage: protonup-rs [OPTIONS]

Options:
-q, --quick-download Skip Menu, auto detect apps and download using default parameters
-h, --help Print help
```

---
Expand All @@ -42,7 +39,7 @@ protonup-rs -q -f -l -L
wget https://github.com/auyer/Protonup-rs/releases/latest/download/protonup-rs-linux-amd64.tar.gz -O - | tar -xz && zenity --password | sudo -S mv protonup-rs /usr/bin/
```

This assumes `/usr/bin` is in your path. You may change this to any other location (in your path ```echo $PATH```).
This assumes `/usr/bin` is in your path. You may change this to any other location (in your path `echo $PATH`).

### Or manually:

Expand All @@ -53,12 +50,12 @@ 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:
or download the zip from the releases page

```
cd Downloads
sudo unzip protonup-rs-linux-amd64.zip -d /usr/bin
```


## Building from source

You can install from source using the last released version in Crates.io:
Expand All @@ -75,10 +72,8 @@ cargo build -p protonup-rs --release
mv ./target/release/protonup-rs "your path"
```


## GUI

Not ready for usage.

The GUI is in its [early stages](https://github.com/auyer/Protonup-rs/tree/feature/gui). My current plan is to develop it in the iced framework, but GUI development is not my forte.

4 changes: 2 additions & 2 deletions libprotonup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libprotonup"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
authors = ["Auyer <[email protected]>"]
repository = "https://github.com/auyer/protonup-rs"
Expand Down Expand Up @@ -30,4 +30,4 @@ tar = "0.4"
xz2 = "0.1"

[dev-dependencies]
tokio = { version = "1.27", features = ["macros", "rt"] }
tokio = { version = "1.28", features = ["macros", "rt"] }
132 changes: 132 additions & 0 deletions libprotonup/src/apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use crate::{
files::{self, list_folders_in_path},
variants::Variant,
};
use std::fmt;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum App {
Steam,
Lutris,
// TODO: HeroicGamesLauncher,
}

// APP_VARIANTS is a shorthand to all app variants
pub static APP_VARIANTS: &[App] = &[App::Steam, App::Lutris];

impl fmt::Display for App {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Steam => write!(f, "Steam"),
Self::Lutris => write!(f, "Lutris"),
}
}
}

impl App {
pub fn app_available_variants(&self) -> Vec<Variant> {
match *self {
Self::Steam => vec![Variant::GEProton],
Self::Lutris => vec![Variant::WineGE, Variant::GEProton],
}
}

pub fn app_default_variant(&self) -> Variant {
match *self {
Self::Steam => Variant::GEProton,
Self::Lutris => Variant::WineGE,
}
}

pub fn app_installations(&self) -> Vec<AppInstallations> {
match *self {
Self::Steam => vec![AppInstallations::Steam, AppInstallations::SteamFlatpak],
Self::Lutris => vec![AppInstallations::Lutris, AppInstallations::LutrisFlatpak],
}
}

pub fn detect_installation_method(&self) -> Vec<AppInstallations> {
match *self {
Self::Steam => {
detect_installations(&[AppInstallations::Steam, AppInstallations::SteamFlatpak])
}
Self::Lutris => {
detect_installations(&[AppInstallations::Lutris, AppInstallations::LutrisFlatpak])
}
}
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum AppInstallations {
Steam,
SteamFlatpak,
Lutris,
LutrisFlatpak,
}

impl fmt::Display for AppInstallations {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Steam => write!(f, "Steam \"Native\" "),
Self::SteamFlatpak => write!(f, "Steam Flatpak"),
Self::Lutris => write!(f, "Lutris \"Native\""),
Self::LutrisFlatpak => write!(f, "Lutris Flatpak"),
}
}
}

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

pub fn app_base_dir(&self) -> &'static str {
match *self {
Self::Steam => "~/.steam/steam/",
Self::SteamFlatpak => "~/.var/app/com.valvesoftware.Steam/data/Steam/",
Self::Lutris => "~/.local/share/lutris/",
Self::LutrisFlatpak => "~/.var/app/net.lutris.Lutris/data/lutris/",
}
}

pub fn list_installed_versions(&self) -> Result<Vec<String>, anyhow::Error> {
list_folders_in_path(self.default_install_dir())
}

pub fn into_app(&self) -> App {
match *self {
Self::Steam | Self::SteamFlatpak => App::Steam,
Self::Lutris | Self::LutrisFlatpak => App::Lutris,
}
}
}

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

/// detect_installations returns a vector of App variants that are detected based on the provided
fn detect_installations(app_installations: &[AppInstallations]) -> Vec<AppInstallations> {
app_installations
.iter()
.filter(|app| files::check_if_exists(app.app_base_dir(), ""))
.cloned()
.collect()
}

// APP_INSTALLATIONS_VARIANTS contains the subset of variants of the App enum that are actual apps
pub static APP_INSTALLATIONS_VARIANTS: &[AppInstallations] = &[
AppInstallations::Steam,
AppInstallations::SteamFlatpak,
AppInstallations::Lutris,
AppInstallations::LutrisFlatpak,
];
6 changes: 0 additions & 6 deletions libprotonup/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

pub const DEFAULT_STEAM_INSTALL_DIR: &str = "~/.steam/steam/compatibilitytools.d/";
pub const DEFAULT_STEAM_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_URL: &str = "https://api.github.com/repos";
Expand Down
37 changes: 32 additions & 5 deletions libprotonup/src/file.rs → libprotonup/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn path_result(path: &Path) -> String {
}
}

// decompress will detect the extension and decompress the file with the appropriate function
pub fn decompress(from_path: &Path, destination_path: &Path) -> Result<()> {
let path_str = from_path.as_os_str().to_string_lossy();

Expand Down Expand Up @@ -84,13 +85,40 @@ pub fn create_progress_trackers() -> (Arc<AtomicUsize>, Arc<AtomicBool>) {
)
}

/// Check if the Proton/Wine version (tag) exists at path
// check_if_exists checks if a folder exists in a path
pub fn check_if_exists(path: &str, tag: &str) -> bool {
let f_path = utils::expand_tilde(format!("{path}/{tag}")).unwrap();
let p = std::path::Path::new(&f_path);
let f_path = utils::expand_tilde(format!("{path}{tag}/")).unwrap();
let p = f_path.as_path();
p.is_dir()
}

// list_folders_in_path returns a vector of strings of the folders in a path
pub fn list_folders_in_path(path: &str) -> Result<Vec<String>, anyhow::Error> {
let f_path = utils::expand_tilde(path).unwrap();
let p = f_path.as_path();
let paths: Vec<String> = p
.read_dir()
.with_context(|| format!("Failed to read directory : {}", path_result(p)))?
.filter_map(|e| e.ok())
.filter(|e| e.path().is_dir())
.map(|e| {
let path = e.path();
let name = path.file_name().unwrap();
name.to_str().unwrap().to_string()
})
.collect();
Ok(paths)
}

// removes a directory and all its contents
pub fn remove_dir_all(path: &str) -> Result<()> {
let f_path = utils::expand_tilde(path).unwrap();
let p = f_path.as_path();
std::fs::remove_dir_all(p)
.with_context(|| format!("[Remove] Failed to remove directory : {}", path_result(p)))?;
Ok(())
}

/// requires pointers to store the progress, and another to store "done" status
/// Create them with `create_progress_trackers`
pub async fn download_file_progress(
Expand Down Expand Up @@ -140,8 +168,7 @@ pub async fn download_file_progress(
Ok(())
}

/// Downloads sha512 hash returned as Result<String> to verify download integrity
pub async fn download_sha512_into_memory(url: &String) -> Result<String> {
pub async fn download_file_into_memory(url: &String) -> Result<String> {
let client = reqwest::Client::new();
let res = client
.get(url)
Expand Down
16 changes: 8 additions & 8 deletions libprotonup/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::constants;
use crate::parameters::VariantParameters;
use crate::variants::VariantParameters;
use anyhow::Result;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -95,20 +95,20 @@ pub async fn fetch_data_from_tag(

#[cfg(test)]
mod tests {
use crate::parameters;
use crate::variants;

use super::*;

#[tokio::test]
async fn test_fetch_data_from_tag() {
let conditions = &[
(
parameters::Variant::WineGE.parameters(),
variants::Variant::WineGE.parameters(),
"latest",
"Get Steam",
),
(
parameters::Variant::GEProton.parameters(),
variants::Variant::GEProton.parameters(),
"latest",
"Download Lutris",
),
Expand Down Expand Up @@ -150,8 +150,8 @@ mod tests {
#[tokio::test]
async fn test_list_releases() {
let conditions = &[
(parameters::Variant::WineGE.parameters(), "List WineGE"),
(parameters::Variant::GEProton.parameters(), "List GEProton"),
(variants::Variant::WineGE.parameters(), "List WineGE"),
(variants::Variant::GEProton.parameters(), "List GEProton"),
];

for (source_parameters, desc) in conditions {
Expand Down Expand Up @@ -188,8 +188,8 @@ mod tests {
};

let conditions = &[
(parameters::Variant::WineGE.parameters(), "Get WineGE"),
(parameters::Variant::GEProton.parameters(), "Get GEProton"),
(variants::Variant::WineGE.parameters(), "Get WineGE"),
(variants::Variant::GEProton.parameters(), "Get GEProton"),
];
for (source_parameters, desc) in conditions {
let url = format!(
Expand Down
5 changes: 3 additions & 2 deletions libprotonup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod apps;
pub mod constants;
pub mod file;
pub mod files;
pub mod github;
pub mod parameters;
pub mod utils;
pub mod variants;
4 changes: 4 additions & 0 deletions libprotonup/src/parameters.rs → libprotonup/src/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl VariantParameters {
}

/// Variant is an enum with all supported "Proton" versions
#[derive(Debug, Clone)]
pub enum Variant {
GEProton,
WineGE,
Expand Down Expand Up @@ -91,3 +92,6 @@ impl Variant {
}
}
}

// ALL_VARIANTS is a shorthand to all app variants
pub static ALL_VARIANTS: &[Variant] = &[Variant::GEProton, Variant::WineGE];
Loading

0 comments on commit 60969c8

Please sign in to comment.