Skip to content

Commit

Permalink
Merge pull request #3 from Amanse/ulwgl
Browse files Browse the repository at this point in the history
Ulgwl: Everything changed lol
  • Loading branch information
Amanse authored Feb 6, 2024
2 parents 1dd755a + 85182bf commit dba62c3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 63 deletions.
14 changes: 0 additions & 14 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ enum ConfigMenu {
DeleteGame,
PrefixDir,
RunnerDir,
AddUlwglDir,
}

impl std::fmt::Display for ConfigMenu {
Expand All @@ -55,7 +54,6 @@ impl std::fmt::Display for ConfigMenu {
ConfigMenu::DeleteGame => write!(f, "Delete game"),
ConfigMenu::PrefixDir => write!(f, "Add prefix directory"),
ConfigMenu::RunnerDir => write!(f, "Add runners directory"),
ConfigMenu::AddUlwglDir => write!(f, "Add ULGWL directory"),
}
}
}
Expand Down Expand Up @@ -159,18 +157,6 @@ impl MainConfig {
confy::store("game-rs", "Extra", self.extra.clone())?;
return Ok(());
}
ConfigMenu::AddUlwglDir => {
let old = self.extra.ulwgl_path.clone().unwrap_or("".to_string());

let path: String = Input::new()
.with_prompt("Add path to the ULGWL(directory of ./gamelauncher.sh)")
.default(old)
.interact_text()?;

self.extra.ulwgl_path = Some(path);
confy::store("game-rs", "Extra", self.extra.clone())?;
return Ok(());
}
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/config/extra_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct ExtraConfig {
pub runner_path: Option<String>,
pub prefix_dir: Option<String>,
pub runner_dirs: Option<Vec<String>>,
pub ulwgl_path: Option<String>,
}

impl ::std::default::Default for ExtraConfig {
Expand All @@ -16,7 +15,6 @@ impl ::std::default::Default for ExtraConfig {
runner_path: None,
prefix_dir: None,
runner_dirs: None,
ulwgl_path: None,
}
}
}
Expand Down Expand Up @@ -65,22 +63,29 @@ impl ExtraConfig {
let runner_path: String;
let runner_list = self.get_runners()?;
let runner_s = Select::new()
.with_prompt(
"Wine Runner [You can add runner dir to automatically fetch these in config]",
)
.with_prompt("Wine Runner")
.default(0)
.item("Custom path")
.item("Auto download(needs ulwgl)")
.items(&runner_list)
.interact()?;

if runner_s != 0 {
runner_path = runner_list[runner_s - 1].clone();
} else {
runner_path = Input::new()
.with_prompt("Path to proton/wine binary")
.default(self.runner_path.clone().unwrap_or("".to_string()))
.interact_text()?;
// @TODO: Remove this crap with wine-ge phaseout
match runner_s {
0 => {
runner_path = Input::new()
.with_prompt("Path to proton/wine binary")
.default(self.runner_path.clone().unwrap_or("".to_string()))
.interact_text()?;
}
1 => {
runner_path = "".to_string();
}
_ => {
runner_path = runner_list[runner_s - 1].clone();
}
}

Ok(runner_path)
}
}
22 changes: 14 additions & 8 deletions src/download/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ use eyre::{eyre, Result};
pub fn download(what: &DownloadOptions) -> Result<()> {
match what {
DownloadOptions::Proton => util::download_and_extract(&get_proton_url()?, true),
DownloadOptions::ULGWL => util::download_and_extract(
"https://api.github.com/repos/Open-Wine-Components/ULWGL-launcher/tarball",
false,
),
DownloadOptions::ULWGL => util::download_and_extract(&get_ulgwl_url()?, false),
}
}

fn get_ulgwl_url() -> Result<String> {
get_latest_release(
"https://api.github.com/repos/Open-Wine-Components/ULWGL-launcher".to_string(),
)
}

fn get_proton_url() -> Result<String> {
let resp: serde_json::Value =
ureq::get("https://api.github.com/repos/GloriousEggroll/wine-ge-custom/releases/latest")
.call()?
.into_json()?;
get_latest_release("https://api.github.com/repos/GloriousEggroll/wine-ge-custom".to_string())
}

fn get_latest_release(repo: String) -> Result<String> {
let resp: serde_json::Value = ureq::get(&format!("{}/releases/latest", repo))
.call()?
.into_json()?;

Ok(resp["assets"][1]["browser_download_url"]
.as_str()
Expand Down
27 changes: 17 additions & 10 deletions src/download/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ use std::{fs, io::BufWriter};
use tar::Archive;

pub fn download_and_extract(download_url: &str, is_xz: bool) -> Result<()> {
let output = Input::new()
.with_prompt("Where do you want to download? (put / at the end)")
.default("".to_string())
.show_default(false)
.interact_text()?;

let file_path = download_to_tmp(download_url, "file")?;

extract(file_path, output, is_xz)?;
let output = {
if is_xz {
Input::new()
.with_prompt("Where do you want to download? (put / at the end)")
.default("".to_string())
.show_default(false)
.interact_text()?
} else {
String::from("")
}
};

download_to_tmp(download_url, "file")?;

extract("/tmp/file".to_string(), output, is_xz)?;
Ok(())
}

Expand All @@ -30,7 +36,8 @@ fn extract(file_path: String, output: String, is_xz: bool) -> Result<()> {
let decomp = flate2::read::GzDecoder::new(file);
let mut a = Archive::new(decomp);

a.unpack(output).unwrap();
a.unpack(format!("{}/.local/share/ULWGL", std::env::var("HOME")?))
.unwrap();
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum Command {
#[derive(Subcommand)]
pub enum DownloadOptions {
Proton,
ULGWL,
ULWGL,
}

#[derive(Args)]
Expand Down
21 changes: 3 additions & 18 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ impl<'a> Runner<'a> {
envs.insert("PROTONPATH", game.runner_path.as_str());
envs.insert("GAMEID", "game-rs");

run_ulwgl(
&envs,
self.config
.extra
.ulwgl_path
.clone()
.expect("ULGWL path not set in config"),
game.exect_path,
self.is_verbose,
);
run_ulwgl(&envs, game.exect_path, self.is_verbose);

return Ok(());
}
Expand All @@ -87,14 +78,8 @@ impl<'a> Runner<'a> {
}
}

fn run_ulwgl(envs: &HashMap<&str, &str>, ulwgl_path: String, exect_path: String, is_verbose: bool) {
let ulwgl_path = {
if ulwgl_path.chars().last().unwrap() != '/' {
format!("{}/gamelauncher.sh", ulwgl_path)
} else {
format!("{}gamelauncher.sh", ulwgl_path)
}
};
fn run_ulwgl(envs: &HashMap<&str, &str>, exect_path: String, is_verbose: bool) {
let ulwgl_path = String::from("~/.local/share/ULWGL/ulwgl-run");

let mut args: Vec<String> = vec![];

Expand Down

0 comments on commit dba62c3

Please sign in to comment.