Compare commits

..

6 Commits

Author SHA1 Message Date
ALEZ
131009dc7e
Merge pull request #52 from ALEZ-DEV/proton_to_wine
Transition from proton to wine
2025-12-19 18:53:47 +01:00
5e3c640e4e ask to delete old setup on gui 2025-12-19 18:53:10 +01:00
e1fee118d6 ask to delete old setup on cli 2025-12-19 17:57:32 +01:00
e41eece4a8 some little fixes (and nixos fix specific) 2025-12-19 00:52:35 +01:00
ALEZ-DEV
1795b9d580 all the install process work fine now 2025-12-17 09:52:16 +01:00
bbfb912f5b changed proton to wine 2025-12-16 21:41:13 +01:00
14 changed files with 324 additions and 201 deletions

28
Cargo.lock generated
View File

@ -374,7 +374,9 @@ dependencies = [
"serde_json", "serde_json",
"tar", "tar",
"tokio", "tokio",
"whatadistro",
"wincompatlib", "wincompatlib",
"xz2",
] ]
[[package]] [[package]]
@ -2069,6 +2071,17 @@ version = "0.4.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
[[package]]
name = "lzma-sys"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.4" version = "2.7.4"
@ -3951,6 +3964,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "whatadistro"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c97ebad4f59809511083f2161587445631bff21bb78d9e046b9ca5b2d05d913"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@ -4269,6 +4288,15 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "xz2"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
dependencies = [
"lzma-sys",
]
[[package]] [[package]]
name = "yoke" name = "yoke"
version = "0.7.5" version = "0.7.5"

View File

@ -3,7 +3,7 @@ use std::{path::PathBuf, str::FromStr, sync::Arc};
use babylonia_terminal_sdk::{ use babylonia_terminal_sdk::{
components::{ components::{
dxvk_component::{DXVK_DEV, DXVK_REPO}, dxvk_component::{DXVK_DEV, DXVK_REPO},
proton_component::{ProtonComponent, PROTON_DEV, PROTON_REPO}, wine_component::{WineComponent, WINE_DEV, WINE_REPO},
}, },
game_config::GameConfig, game_config::GameConfig,
game_manager::{EnvironmentVariable, GameManager}, game_manager::{EnvironmentVariable, GameManager},
@ -21,8 +21,32 @@ pub async fn run(
env_vars: Vec<EnvironmentVariable>, env_vars: Vec<EnvironmentVariable>,
show_logs: bool, show_logs: bool,
) { ) {
let mut proton_component: Option<ProtonComponent> = None; let mut wine_component: Option<WineComponent> = None;
let mut proton: Option<Proton> = None; let mut wine: Option<Wine> = None;
// Deleting old setup
if None == GameConfig::get_config().await.launcher_version {
info!("You seem to have the old setup to play the game.");
info!("do you want to delete it to setup the new one ? (y/n) (default - yes): ");
let input = BufReader::new(tokio::io::stdin())
.lines()
.next_line()
.await
.unwrap();
if None == input
|| Some("".to_string()) == input
|| Some("y".to_string()) == input
|| Some("yes".to_string()) == input
{
info!("Deleting old setup...");
babylonia_terminal_sdk::utils::remove_setup().await;
info!("done!");
} else {
info!("Keeping old setup...");
}
}
loop { loop {
let state_result = GameState::get_current_state().await; let state_result = GameState::get_current_state().await;
@ -32,40 +56,42 @@ pub async fn run(
} }
let state = state_result.unwrap(); let state = state_result.unwrap();
if state != GameState::ProtonNotInstalled && proton == None { if state != GameState::WineNotInstalled && wine == None {
let proton_component = ProtonComponent::new(GameConfig::get_config_directory().await); let wine_component = WineComponent::new(GameConfig::get_config_directory().await);
match proton_component.init_proton() { match wine_component.init_wine() {
Ok(p) => proton = Some(p), Ok(p) => wine = Some(p),
Err(err) => panic!("{}", err), Err(err) => panic!("{}", err),
}; };
} }
match state { match state {
GameState::ProtonNotInstalled => { GameState::WineNotInstalled => {
let release; let release;
if utils::use_latest("Do you want to install latest version of Proton GE or a specific version of it?") { if utils::use_latest(
release = 0; "Do you want to install latest version of wine GE or a specific version of it?",
} else { ) {
release = utils::choose_release_version( release = 0;
PROTON_DEV, } else {
PROTON_REPO, release = utils::choose_release_version(
"Please, select a version of Proton GE to install.", WINE_DEV,
) WINE_REPO,
.await "Please, select a version of wine GE to install.",
.expect("Failed to fetch proton version!"); )
} .await
.expect("Failed to fetch wine version!");
}
info!("Proton not installed, installing it..."); info!("Wine not installed, installing it...");
proton_component = Some( wine_component = Some(
GameManager::install_wine( GameManager::install_wine(
GameConfig::get_config_directory().await, GameConfig::get_config_directory().await,
release, release,
Some(DownloadReporter::create(false)), Some(DownloadReporter::create(false)),
) )
.await .await
.expect("Failed to install Wine"), .expect("Failed to install wine"),
); );
info!("Proton installed"); info!("wine installed");
} }
GameState::DXVKNotInstalled => { GameState::DXVKNotInstalled => {
let release; let release;
@ -84,9 +110,9 @@ pub async fn run(
} }
info!("DXVK not installed, installing it..."); info!("DXVK not installed, installing it...");
debug!("{:?}", proton_component); debug!("{:?}", wine_component);
GameManager::install_dxvk( GameManager::install_dxvk(
&proton.clone().unwrap(), &wine.clone().unwrap(),
GameConfig::get_config_directory().await, GameConfig::get_config_directory().await,
release, release,
Some(DownloadReporter::create(false)), Some(DownloadReporter::create(false)),
@ -97,14 +123,14 @@ pub async fn run(
} }
GameState::FontNotInstalled => { GameState::FontNotInstalled => {
info!("Fonts not installed, installing it..."); info!("Fonts not installed, installing it...");
GameManager::install_font(&proton.clone().unwrap(), None::<Arc<DownloadReporter>>) GameManager::install_font(&wine.clone().unwrap(), None::<Arc<DownloadReporter>>)
.await .await
.expect("Failed to install fonts"); .expect("Failed to install fonts");
info!("Fonts installed"); info!("Fonts installed");
} }
GameState::DependecieNotInstalled => { GameState::DependecieNotInstalled => {
info!("Dependecies not installed, installing it..."); info!("Dependecies not installed, installing it...");
GameManager::install_dependencies(&proton.clone().unwrap()) GameManager::install_dependencies(&wine.clone().unwrap())
.await .await
.expect("Failed to install dependecies"); .expect("Failed to install dependecies");
info!("Dependecies installed"); info!("Dependecies installed");
@ -167,9 +193,9 @@ pub async fn run(
} }
info!("Starting game..."); info!("Starting game...");
debug!("{:?}", proton); debug!("{:?}", wine);
GameManager::start_game( GameManager::start_game(
&proton.unwrap(), &wine.unwrap(),
GameConfig::get_game_dir() GameConfig::get_game_dir()
.await .await
.expect("Failed to start game, the game directory was not found"), .expect("Failed to start game, the game directory was not found"),

View File

@ -1,8 +1,8 @@
use std::{ops::Deref, sync::Arc}; use std::{ops::Deref, sync::Arc};
use babylonia_terminal_sdk::{ use babylonia_terminal_sdk::{
components::proton_component::ProtonComponent, game_config::GameConfig, components::wine_component::WineComponent, game_config::GameConfig, game_manager::GameManager,
game_manager::GameManager, utils::github_requester::GithubRelease, utils::github_requester::GithubRelease,
}; };
use downloader::download; use downloader::download;
use log::{debug, error}; use log::{debug, error};
@ -10,7 +10,7 @@ use relm4::{
tokio::{self, sync::OnceCell}, tokio::{self, sync::OnceCell},
Worker, Worker,
}; };
use wincompatlib::prelude::Proton; use wincompatlib::prelude::Wine;
use crate::ui::{ use crate::ui::{
self, self,
@ -23,36 +23,33 @@ use crate::ui::{
}, },
}; };
static PROTON: OnceCell<Proton> = OnceCell::const_new(); static WINE: OnceCell<Wine> = OnceCell::const_new();
pub async fn get_proton() -> anyhow::Result<Proton> { pub async fn get_wine() -> anyhow::Result<Wine> {
if !PROTON.initialized() { if !WINE.initialized() {
let proton_component = ProtonComponent::new(GameConfig::get_config().await.config_dir); let wine_component = WineComponent::new(GameConfig::get_config().await.config_dir);
let proton = proton_component.init_proton(); let wine = wine_component.init_wine();
if let Err(ref e) = proton { if let Err(ref e) = wine {
error!("Failed to initialize proton : {}", e); error!("Failed to initialize wine : {}", e);
anyhow::bail!("Failed to initialize proton : {}", e); anyhow::bail!("Failed to initialize wine : {}", e);
} }
Ok(PROTON Ok(WINE.get_or_init(|| async { wine.unwrap() }).await.clone())
.get_or_init(|| async { proton.unwrap() })
.await
.clone())
} else { } else {
Ok(PROTON.get().unwrap().clone()) Ok(WINE.get().unwrap().clone())
} }
} }
pub async fn run_game() -> anyhow::Result<()> { pub async fn run_game() -> anyhow::Result<()> {
let proton = get_proton().await?; let wine = get_wine().await?;
let game_dir = GameConfig::get_config().await.game_dir; let game_dir = GameConfig::get_config().await.game_dir;
if game_dir.is_none() { if game_dir.is_none() {
error!("Failed to start game, the game directory was not found"); error!("Failed to start game, the game directory was not found");
anyhow::bail!("Failed to start game, the game directory was not found"); anyhow::bail!("Failed to start game, the game directory was not found");
} }
GameManager::start_game(&proton, game_dir.unwrap(), None, vec![], false).await?; GameManager::start_game(&wine, game_dir.unwrap(), None, vec![], false).await?;
Ok(()) Ok(())
} }
@ -217,7 +214,7 @@ pub enum HandleComponentInstallationMsg {
usize, usize,
Arc<download_components::DownloadComponentProgressBarReporter>, Arc<download_components::DownloadComponentProgressBarReporter>,
), ),
), // proton release and dxvk release ), // wine release and dxvk release
} }
#[derive(Debug)] #[derive(Debug)]
@ -237,7 +234,7 @@ impl Worker for HandleComponentInstallation {
fn update(&mut self, message: Self::Input, sender: relm4::ComponentSender<Self>) { fn update(&mut self, message: Self::Input, sender: relm4::ComponentSender<Self>) {
match message { match message {
HandleComponentInstallationMsg::StartInstallation(( HandleComponentInstallationMsg::StartInstallation((
proton_release, wine_release,
dxvk_release, dxvk_release,
progress_bar, progress_bar,
)) => { )) => {
@ -248,20 +245,20 @@ impl Worker for HandleComponentInstallation {
.block_on(async { .block_on(async {
let _ = sender.output( let _ = sender.output(
download_components::DownloadComponentsMsg::UpdateProgressBarMsg( download_components::DownloadComponentsMsg::UpdateProgressBarMsg(
String::from("Starting download for proton"), String::from("Starting download for wine"),
Some(String::from("Unpacking and initializing proton")), Some(String::from("Unpacking and initializing wine")),
), ),
); );
let _ = sender.output( let _ = sender.output(
download_components::DownloadComponentsMsg::UpdateCurrentlyInstalling( download_components::DownloadComponentsMsg::UpdateCurrentlyInstalling(
download_components::CurrentlyInstalling::Proton, download_components::CurrentlyInstalling::Wine,
), ),
); );
let _ = sender.output( let _ = sender.output(
download_components::DownloadComponentsMsg::UpdateDownloadedComponentName( download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(
String::from("proton"), String::from("wine"),
), ),
); );
@ -271,8 +268,8 @@ impl Worker for HandleComponentInstallation {
GameConfig::get_config_directory().await GameConfig::get_config_directory().await
}; };
if let Err(error) = GameManager::install_wine(game_dir.clone(), proton_release, Some(progress_bar.clone())).await { if let Err(error) = GameManager::install_wine(game_dir.clone(), wine_release, Some(progress_bar.clone())).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install proton : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install wine : {}", error))).unwrap();
return; return;
} }
@ -283,15 +280,15 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("DXVK"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("DXVK")));
let proton = match get_proton().await { let wine = match get_wine().await {
Ok(p) => p, Ok(p) => p,
Err(e) => { Err(e) => {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to initialize proton : {:?}", e))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to initialize wine : {:?}", e))).unwrap();
return; return;
} }
}; };
if let Err(error) = GameManager::install_dxvk(&proton, game_dir, dxvk_release, Some(progress_bar.clone())).await { if let Err(error) = GameManager::install_dxvk(&wine, game_dir, dxvk_release, Some(progress_bar.clone())).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install DXVK : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install DXVK : {}", error))).unwrap();
return; return;
} }
@ -303,7 +300,7 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("fonts"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("fonts")));
if let Err(error) = GameManager::install_font(&proton, Some(progress_bar.clone())).await { if let Err(error) = GameManager::install_font(&wine, Some(progress_bar.clone())).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install fonts : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install fonts : {}", error))).unwrap();
return; return;
} }
@ -315,7 +312,7 @@ impl Worker for HandleComponentInstallation {
let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("denpendecies"))); let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("denpendecies")));
if let Err(error) = GameManager::install_dependencies(&proton).await { if let Err(error) = GameManager::install_dependencies(&wine).await {
sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install dependencies : {}", error))).unwrap(); sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install dependencies : {}", error))).unwrap();
return; return;
} }

View File

@ -1,9 +1,9 @@
use std::{convert::identity, fmt::format}; use std::{convert::identity, fmt::format, process::Command};
use arboard::Clipboard; use arboard::Clipboard;
use babylonia_terminal_sdk::game_state::GameState; use babylonia_terminal_sdk::{game_config::GameConfig, game_state::GameState, utils};
use libadwaita::prelude::{MessageDialogExt, PreferencesPageExt}; use libadwaita::prelude::{ApplicationExt, MessageDialogExt, PreferencesPageExt};
use log::error; use log::{debug, error};
use relm4::{ use relm4::{
adw, adw,
gtk::{ gtk::{
@ -11,7 +11,7 @@ use relm4::{
prelude::{ButtonExt, GtkWindowExt, OrientableExt, WidgetExt}, prelude::{ButtonExt, GtkWindowExt, OrientableExt, WidgetExt},
}, },
prelude::{AsyncComponentParts, SimpleAsyncComponent}, prelude::{AsyncComponentParts, SimpleAsyncComponent},
Component, RelmWidgetExt, WorkerController, tokio, Component, RelmWidgetExt, WorkerController,
}; };
use crate::{ use crate::{
@ -31,6 +31,7 @@ pub struct GamePage {
progress_bar_reporter: std::sync::Arc<ProgressBarGameInstallationReporter>, progress_bar_reporter: std::sync::Arc<ProgressBarGameInstallationReporter>,
progress_bar_message: String, progress_bar_message: String,
fraction: f64, fraction: f64,
delete_old_setup_manager: DeleteOldSetupManager,
} }
#[derive(Debug)] #[derive(Debug)]
@ -41,6 +42,7 @@ pub enum GamePageMsg {
UpdateGameState, UpdateGameState,
UpdateProgressBar(u64, u64), UpdateProgressBar(u64, u64),
ShowError(String), ShowError(String),
DeleteOldSetup,
} }
#[relm4::component(pub, async)] #[relm4::component(pub, async)]
@ -222,6 +224,7 @@ impl SimpleAsyncComponent for GamePage {
) -> relm4::prelude::AsyncComponentParts<Self> { ) -> relm4::prelude::AsyncComponentParts<Self> {
let model = GamePage { let model = GamePage {
progress_bar_reporter: ProgressBarGameInstallationReporter::create(sender.clone()), progress_bar_reporter: ProgressBarGameInstallationReporter::create(sender.clone()),
delete_old_setup_manager: DeleteOldSetupManager::new(sender.clone()),
game_state, game_state,
game_handler: manager::HandleGameProcess::builder() game_handler: manager::HandleGameProcess::builder()
.detach_worker(()) .detach_worker(())
@ -238,10 +241,18 @@ impl SimpleAsyncComponent for GamePage {
let widgets = view_output!(); let widgets = view_output!();
if None == GameConfig::get_config().await.launcher_version {
sender.input(GamePageMsg::DeleteOldSetup);
}
AsyncComponentParts { model, widgets } AsyncComponentParts { model, widgets }
} }
async fn update(&mut self, message: Self::Input, _: relm4::AsyncComponentSender<Self>) -> () { async fn update(
&mut self,
message: Self::Input,
sender: relm4::AsyncComponentSender<Self>,
) -> () {
match message { match message {
GamePageMsg::SetIsGameRunning(value) => self.is_game_running = value, GamePageMsg::SetIsGameRunning(value) => self.is_game_running = value,
GamePageMsg::SetIsDownloading(value) => self.is_downloading = value, GamePageMsg::SetIsDownloading(value) => self.is_downloading = value,
@ -287,6 +298,32 @@ impl SimpleAsyncComponent for GamePage {
} }
}); });
dialog.present();
}
GamePageMsg::DeleteOldSetup => {
let dialog = unsafe {
adw::MessageDialog::new(
MAIN_WINDOW.as_ref(),
Some("Remove old setup"),
Some("You seem to have a old environment. You need to delete it if you want to continue to play."),
)
};
dialog.add_response("remove", "Remove setup and restart");
dialog.set_response_appearance("remove", adw::ResponseAppearance::Suggested);
let remove_old_setup_manager = self.delete_old_setup_manager.clone();
dialog.connect_response(Some("remove"), move |_, _| {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
remove_old_setup_manager.delete_old_setup().await;
});
});
dialog.present(); dialog.present();
} }
} }
@ -337,3 +374,25 @@ impl downloader::progress::Reporter for ProgressBarGameInstallationReporter {
*guard = None; *guard = None;
} }
} }
#[derive(Debug, Clone)]
struct DeleteOldSetupManager {
sender: relm4::AsyncComponentSender<GamePage>,
}
impl DeleteOldSetupManager {
pub fn new(sender: relm4::AsyncComponentSender<GamePage>) -> Self {
Self { sender }
}
pub async fn delete_old_setup(&self) {
if let Err(e) = utils::remove_setup().await {
self.sender.input(GamePageMsg::ShowError(e.to_string()));
} else {
if let Ok(bin_path) = std::env::current_exe() {
let _ = Command::new(bin_path).arg("--gui").spawn();
};
relm4::main_application().quit();
}
}
}

View File

@ -4,7 +4,7 @@ use arboard::Clipboard;
use babylonia_terminal_sdk::{ use babylonia_terminal_sdk::{
components::{ components::{
dxvk_component::{self, DXVKComponent}, dxvk_component::{self, DXVKComponent},
proton_component::{self, ProtonComponent}, wine_component::{self, WineComponent},
}, },
game_config::GameConfig, game_config::GameConfig,
game_state::GameState, game_state::GameState,
@ -43,7 +43,7 @@ pub enum DownloadComponentsMsg {
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum CurrentlyInstalling { pub enum CurrentlyInstalling {
None, None,
Proton, Wine,
DXVK, DXVK,
Fonts, Fonts,
Denpendecies, Denpendecies,
@ -52,14 +52,14 @@ pub enum CurrentlyInstalling {
#[derive(Debug)] #[derive(Debug)]
pub struct DownloadComponentsPage { pub struct DownloadComponentsPage {
// widgets // widgets
proton_combo: adw::ComboRow, wine_combo: adw::ComboRow,
dxvk_combo: adw::ComboRow, dxvk_combo: adw::ComboRow,
//error_dialog: Controller<CopyDialog>, //error_dialog: Controller<CopyDialog>,
// values // values
proton_versions: Vec<GithubRelease>, wine_versions: Vec<GithubRelease>,
dxvk_versions: Vec<GithubRelease>, dxvk_versions: Vec<GithubRelease>,
selected_proton_version: Option<GithubRelease>, selected_wine_version: Option<GithubRelease>,
selected_dxvk_version: Option<GithubRelease>, selected_dxvk_version: Option<GithubRelease>,
game_config: GameConfig, game_config: GameConfig,
@ -108,11 +108,11 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
set_vexpand: true, set_vexpand: true,
#[local_ref] #[local_ref]
proton_combo -> adw::ComboRow { wine_combo -> adw::ComboRow {
set_title: "proton version", set_title: "Wine version",
set_model: Some(&gtk::StringList::new(model set_model: Some(&gtk::StringList::new(model
.proton_versions .wine_versions
.iter() .iter()
.map(|r| r.tag_name.as_str()) .map(|r| r.tag_name.as_str())
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
@ -142,7 +142,7 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
set_hexpand: false, set_hexpand: false,
set_width_request: 200, set_width_request: 200,
connect_clicked => DownloadComponentsMsg::UpdateCurrentlyInstalling(CurrentlyInstalling::Proton), connect_clicked => DownloadComponentsMsg::UpdateCurrentlyInstalling(CurrentlyInstalling::Wine),
}, },
}, },
}, },
@ -168,21 +168,21 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
set_vexpand: true, set_vexpand: true,
adw::ActionRow { adw::ActionRow {
set_title: "Proton", set_title: "Wine",
#[watch] #[watch]
set_subtitle: match &model.selected_proton_version { set_subtitle: match &model.selected_wine_version {
Some(release) => &release.tag_name, Some(release) => &release.tag_name,
None => "WTF??!! there's no proton version found ????", None => "WTF??!! there's no wine version found ????",
}, },
#[watch] #[watch]
set_icon_name: if model.currently_installing != CurrentlyInstalling::Proton && model.game_config.is_wine_installed { Some("emblem-ok-symbolic") } else { None }, set_icon_name: if model.currently_installing != CurrentlyInstalling::Wine && model.game_config.is_wine_installed { Some("emblem-ok-symbolic") } else { None },
add_prefix = &gtk::Spinner { add_prefix = &gtk::Spinner {
set_spinning: true, set_spinning: true,
#[watch] #[watch]
set_visible: model.currently_installing == CurrentlyInstalling::Proton, set_visible: model.currently_installing == CurrentlyInstalling::Wine,
} }
}, },
@ -191,7 +191,7 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
#[watch] #[watch]
set_subtitle: match &model.selected_dxvk_version { set_subtitle: match &model.selected_dxvk_version {
Some(release) => &release.tag_name, Some(release) => &release.tag_name,
None => "WTF??!! there's no proton version found ????", None => "WTF??!! there's no wine version found ????",
}, },
#[watch] #[watch]
@ -285,12 +285,10 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
root: Self::Root, root: Self::Root,
sender: AsyncComponentSender<Self>, sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> { ) -> AsyncComponentParts<Self> {
let proton_releases = ProtonComponent::get_github_releases( let wine_releases =
proton_component::PROTON_DEV, WineComponent::get_github_releases(wine_component::WINE_DEV, wine_component::WINE_REPO)
proton_component::PROTON_REPO, .await
) .unwrap(); //TODO: remove unwrap()
.await
.unwrap(); //TODO: remove unwrap()
let dxvk_releases = let dxvk_releases =
DXVKComponent::get_github_releases(dxvk_component::DXVK_DEV, dxvk_component::DXVK_REPO) DXVKComponent::get_github_releases(dxvk_component::DXVK_DEV, dxvk_component::DXVK_REPO)
@ -298,12 +296,12 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
.unwrap(); //TODO: remove unwrap() .unwrap(); //TODO: remove unwrap()
let model = DownloadComponentsPage { let model = DownloadComponentsPage {
proton_combo: adw::ComboRow::new(), wine_combo: adw::ComboRow::new(),
dxvk_combo: adw::ComboRow::new(), dxvk_combo: adw::ComboRow::new(),
proton_versions: proton_releases, wine_versions: wine_releases,
dxvk_versions: dxvk_releases, dxvk_versions: dxvk_releases,
selected_proton_version: None, selected_wine_version: None,
selected_dxvk_version: None, selected_dxvk_version: None,
game_config: GameConfig::get_config().await, game_config: GameConfig::get_config().await,
@ -320,7 +318,7 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
msg_when_done: None, msg_when_done: None,
}; };
let proton_combo = &model.proton_combo; let wine_combo = &model.wine_combo;
let dxvk_combo = &model.dxvk_combo; let dxvk_combo = &model.dxvk_combo;
let widgets = view_output!(); let widgets = view_output!();
@ -395,21 +393,21 @@ impl SimpleAsyncComponent for DownloadComponentsPage {
DownloadComponentsMsg::Quit => relm4::main_application().quit(), DownloadComponentsMsg::Quit => relm4::main_application().quit(),
} }
if self.selected_proton_version.is_none() if self.selected_wine_version.is_none()
&& self.selected_dxvk_version.is_none() && self.selected_dxvk_version.is_none()
&& self.currently_installing != CurrentlyInstalling::None && self.currently_installing != CurrentlyInstalling::None
{ {
let proton_index = self.proton_combo.selected() as usize; let wine_index = self.wine_combo.selected() as usize;
let dxvk_index = self.dxvk_combo.selected() as usize; let dxvk_index = self.dxvk_combo.selected() as usize;
let proton_release = self.proton_versions[proton_index].clone(); let wine_release = self.wine_versions[wine_index].clone();
let dxvk_release = self.dxvk_versions[dxvk_index].clone(); let dxvk_release = self.dxvk_versions[dxvk_index].clone();
self.selected_proton_version = Some(proton_release); self.selected_wine_version = Some(wine_release);
self.selected_dxvk_version = Some(dxvk_release); self.selected_dxvk_version = Some(dxvk_release);
let _ = self.installation_handler.sender().send( let _ = self.installation_handler.sender().send(
manager::HandleComponentInstallationMsg::StartInstallation(( manager::HandleComponentInstallationMsg::StartInstallation((
proton_index, wine_index,
dxvk_index, dxvk_index,
self.progress_bar_reporter.clone(), self.progress_bar_reporter.clone(),
)), )),

View File

@ -27,10 +27,11 @@ serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115" serde_json = "1.0.115"
tar = "0.4.40" tar = "0.4.40"
tokio = { version = "1.37.0", features = ["fs"] } tokio = { version = "1.37.0", features = ["fs"] }
whatadistro = "0.1.0"
wincompatlib = { version = "0.7.5", features = [ wincompatlib = { version = "0.7.5", features = [
"dxvk", "dxvk",
"wine-bundles", "wine-bundles",
"wine-proton",
"wine-fonts", "wine-fonts",
"winetricks", "winetricks",
] } ] }
xz2 = "0.1.7"

View File

@ -55,12 +55,7 @@ impl<'a> ComponentDownloader for DXVKComponent<'a> {
Self::uncompress(file_output.clone(), self.path.clone()).await?; Self::uncompress(file_output.clone(), self.path.clone()).await?;
let wine_with_proton_prefix = self // wine take the data/wine/pfx prefix, but we want the data/wine prefix self.wine
.wine
.clone()
.with_prefix(self.wine.prefix.parent().unwrap());
wine_with_proton_prefix
.install_dxvk(self.path.clone(), InstallParams::default()) .install_dxvk(self.path.clone(), InstallParams::default())
.expect("Failed to installed DXVK"); .expect("Failed to installed DXVK");

View File

@ -1,4 +1,4 @@
pub mod component_downloader; pub mod component_downloader;
pub mod dxvk_component; pub mod dxvk_component;
pub mod game_component; pub mod game_component;
pub mod proton_component; pub mod wine_component;

View File

@ -6,37 +6,37 @@ use std::{
}; };
use downloader::{progress::Reporter, Downloader}; use downloader::{progress::Reporter, Downloader};
use flate2::read::GzDecoder;
use log::debug; use log::debug;
use tar::Archive; use tar::Archive;
use wincompatlib::wine::ext::WineBootExt; use wincompatlib::wine::ext::WineBootExt;
use xz2::read::XzDecoder;
use super::component_downloader::ComponentDownloader; use super::component_downloader::ComponentDownloader;
use crate::utils::github_requester::GithubRequester; use crate::utils::github_requester::GithubRequester;
pub static PROTON_DEV: &str = "GloriousEggroll"; pub static WINE_DEV: &str = "Kron4ek";
pub static PROTON_REPO: &str = "proton-ge-custom"; pub static WINE_REPO: &str = "Wine-Builds";
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct ProtonComponent { pub struct WineComponent {
path: PathBuf, path: PathBuf,
github_release_index: usize, github_release_index: usize,
} }
impl GithubRequester for ProtonComponent { impl GithubRequester for WineComponent {
fn set_github_release_index(&mut self, new_release_index: usize) { fn set_github_release_index(&mut self, new_release_index: usize) {
self.github_release_index = new_release_index; self.github_release_index = new_release_index;
} }
} }
impl ComponentDownloader for ProtonComponent { impl ComponentDownloader for WineComponent {
async fn install<P: Reporter + 'static>(&self, progress: Option<Arc<P>>) -> anyhow::Result<()> { async fn install<P: Reporter + 'static>(&self, progress: Option<Arc<P>>) -> anyhow::Result<()> {
let file_output = self let file_output = self
.download( .download(
&self &self
.path .path
.parent() .parent()
.expect("Failed to get the parent directory of Wine") .expect("Failed to get the parent directory of wine")
.to_path_buf(), .to_path_buf(),
progress, progress,
) )
@ -52,7 +52,7 @@ impl ComponentDownloader for ProtonComponent {
progress: Option<Arc<P>>, progress: Option<Arc<P>>,
) -> anyhow::Result<PathBuf> { ) -> anyhow::Result<PathBuf> {
let release = let release =
Self::get_github_release_version(PROTON_DEV, PROTON_REPO, self.github_release_index) Self::get_github_release_version(WINE_DEV, WINE_REPO, self.github_release_index)
.await?; .await?;
let asset = release let asset = release
@ -79,12 +79,12 @@ impl ComponentDownloader for ProtonComponent {
async fn uncompress(file: PathBuf, new_directory_name: PathBuf) -> anyhow::Result<()> { async fn uncompress(file: PathBuf, new_directory_name: PathBuf) -> anyhow::Result<()> {
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let tar_xz = File::open(file.clone()).unwrap(); let tar_xz = File::open(file.clone()).unwrap();
let tar = GzDecoder::new(tar_xz); let tar = XzDecoder::new(tar_xz);
let mut archive = Archive::new(tar); let mut archive = Archive::new(tar);
archive.unpack(new_directory_name.parent().unwrap())?; archive.unpack(new_directory_name.parent().unwrap())?;
remove_file(file.clone())?; remove_file(file.clone())?;
rename( rename(
file.to_str().unwrap().strip_suffix(".tar.gz").unwrap(), file.to_str().unwrap().strip_suffix(".tar.xz").unwrap(),
new_directory_name, new_directory_name,
)?; )?;
@ -96,49 +96,48 @@ impl ComponentDownloader for ProtonComponent {
} }
} }
impl ProtonComponent { impl WineComponent {
pub fn new(path: PathBuf) -> Self { pub fn new(path: PathBuf) -> Self {
ProtonComponent { WineComponent {
path: path.join("proton"), path: path.join("wine"),
github_release_index: 0, github_release_index: 0,
} }
} }
pub fn init_proton(&self) -> Result<wincompatlib::prelude::Proton, String> { pub fn init_wine(&self) -> Result<wincompatlib::prelude::Wine, String> {
let prefix = self.path.parent().unwrap().join("data"); let prefix = self.path.parent().unwrap().join("data");
let wine_bin_location = self.path.join("bin/wine");
debug!("Initializing prefix with -> {:?}", prefix);
debug!("Wine binary path : {:?}", wine_bin_location);
let mut proton = let mut wine = wincompatlib::prelude::Wine::from_binary(wine_bin_location);
wincompatlib::prelude::Proton::new(self.path.clone(), Some(prefix.clone())); wine.prefix = prefix.clone();
let steam_location = Self::get_steam_location()?;
debug!("Steam location used -> {:?}", steam_location); wine.init_prefix(Some(prefix)).unwrap();
proton.steam_client_path = Some(steam_location); Ok(wine)
proton.init_prefix(Some(prefix)).unwrap();
Ok(proton)
} }
fn get_steam_location() -> Result<PathBuf, String> { //fn get_steam_location() -> Result<PathBuf, String> {
let specified_steam_location = std::env::var("BT_STEAM_CLIENT_PATH"); // let specified_steam_location = std::env::var("BT_STEAM_CLIENT_PATH");
if let Ok(location) = specified_steam_location { // if let Ok(location) = specified_steam_location {
return Ok(PathBuf::from(location)); // return Ok(PathBuf::from(location));
} // }
let location_to_check = [ // let location_to_check = [
dirs::home_dir().unwrap().join(".steam/steam"), // dirs::home_dir().unwrap().join(".steam/steam"),
dirs::home_dir() // dirs::home_dir()
.unwrap() // .unwrap()
.join(".var/app/com.valvesoftware.Steam/steam"), // for the flatpak version of steam // .join(".var/app/com.valvesoftware.Steam/steam"), // for the flatpak version of steam
]; // ];
for location in location_to_check { // for location in location_to_check {
if location.exists() { // if location.exists() {
return Ok(location); // return Ok(location);
} // }
} // }
debug!("Can't find steam installation"); // debug!("Can't find steam installation");
Err(String::from_str("We can't find your steam installation, please install steam in '~/.steam/steam' or specify your steam installation").unwrap()) // Err(String::from_str("We can't find your steam installation, please install steam in '~/.steam/steam' or specify your steam installation").unwrap())
} //}
} }

View File

@ -18,6 +18,7 @@ pub struct GameConfig {
pub is_game_installed: bool, pub is_game_installed: bool,
pub is_game_patched: bool, pub is_game_patched: bool,
pub launch_options: Option<String>, pub launch_options: Option<String>,
pub launcher_version: Option<String>,
} }
impl GameConfig { impl GameConfig {
@ -100,6 +101,7 @@ impl Default for GameConfig {
is_game_installed: false, is_game_installed: false,
is_game_patched: false, is_game_patched: false,
launch_options: None, launch_options: None,
launcher_version: Some(env!("CARGO_PKG_VERSION").to_string()),
} }
} }
} }

View File

@ -16,7 +16,7 @@ use wincompatlib::prelude::*;
use crate::{ use crate::{
components::{ components::{
component_downloader::ComponentDownloader, dxvk_component::DXVKComponent, component_downloader::ComponentDownloader, dxvk_component::DXVKComponent,
game_component::GameComponent, proton_component::ProtonComponent, game_component::GameComponent, wine_component::WineComponent,
}, },
game_config::GameConfig, game_config::GameConfig,
game_patcher, game_patcher,
@ -46,11 +46,11 @@ impl GameManager {
config_dir: PathBuf, config_dir: PathBuf,
release_index: usize, release_index: usize,
progress: Option<Arc<P>>, progress: Option<Arc<P>>,
) -> anyhow::Result<ProtonComponent> ) -> anyhow::Result<WineComponent>
where where
P: Reporter + 'static, P: Reporter + 'static,
{ {
let mut wine_component = ProtonComponent::new(config_dir); let mut wine_component = WineComponent::new(config_dir);
wine_component.set_github_release_index(release_index); wine_component.set_github_release_index(release_index);
wine_component.install(progress).await?; wine_component.install(progress).await?;
@ -63,7 +63,7 @@ impl GameManager {
} }
pub async fn install_dxvk<P>( pub async fn install_dxvk<P>(
proton: &Proton, wine: &Wine,
config_dir: PathBuf, config_dir: PathBuf,
release_index: usize, release_index: usize,
progress: Option<Arc<P>>, progress: Option<Arc<P>>,
@ -71,7 +71,7 @@ impl GameManager {
where where
P: Reporter + 'static, P: Reporter + 'static,
{ {
let mut dxvk_component = DXVKComponent::from_wine(proton.wine(), config_dir); let mut dxvk_component = DXVKComponent::from_wine(wine, config_dir);
dxvk_component.set_github_release_index(release_index); dxvk_component.set_github_release_index(release_index);
dxvk_component.install(progress).await?; dxvk_component.install(progress).await?;
@ -83,15 +83,10 @@ impl GameManager {
Ok(()) Ok(())
} }
pub async fn install_font<P>(proton: &Proton, progress: Option<Arc<P>>) -> anyhow::Result<()> pub async fn install_font<P>(wine: &Wine, progress: Option<Arc<P>>) -> anyhow::Result<()>
where where
P: Reporter + 'static, P: Reporter + 'static,
{ {
let wine_with_proton_prefix = proton // wine take the data/wine/pfx prefix, but we want the data/wine prefix
.wine()
.clone()
.with_prefix(proton.wine().prefix.parent().unwrap());
let max = 1; let max = 1;
if let Some(p) = &progress { if let Some(p) = &progress {
@ -100,7 +95,7 @@ impl GameManager {
notify_fonts_progress(0, max, &progress); notify_fonts_progress(0, max, &progress);
wine_with_proton_prefix.install_font(Font::Arial)?; wine.install_font(Font::Arial)?;
notify_fonts_progress(1, max, &progress); notify_fonts_progress(1, max, &progress);
let mut config = GameConfig::get_config().await; let mut config = GameConfig::get_config().await;
@ -110,13 +105,8 @@ impl GameManager {
Ok(()) Ok(())
} }
pub async fn install_dependencies(proton: &Proton) -> anyhow::Result<()> { pub async fn install_dependencies(wine: &Wine) -> anyhow::Result<()> {
let wine_with_proton_prefix = proton // wine take the data/wine/pfx prefix, but we want the data/wine prefix let winetricks = Winetricks::from_wine("/bin/winetricks", wine);
.wine()
.clone()
.with_prefix(proton.wine().prefix.parent().unwrap());
let winetricks = Winetricks::from_wine("/bin/winetricks", wine_with_proton_prefix);
//winetricks.install("corefonts")?; //winetricks.install("corefonts")?;
let mut child = winetricks.install("vcrun2022")?; let mut child = winetricks.install("vcrun2022")?;
@ -165,26 +155,26 @@ impl GameManager {
} }
pub async fn start_game( pub async fn start_game(
proton: &Proton, wine: &Wine,
game_dir: PathBuf, game_dir: PathBuf,
options: Option<String>, options: Option<String>,
env_variables: Vec<EnvironmentVariable>, env_variables: Vec<EnvironmentVariable>,
show_logs: bool, show_logs: bool,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let proton_version = proton.wine().version()?; let wine_version = wine.version()?;
let binary_path = game_dir let binary_path = game_dir
.join(get_game_name()) .join(get_game_name())
.join(get_game_name_with_executable()); .join(get_game_name_with_executable());
debug!("Wine version : {:?}", proton_version); debug!("wine version : {:?}", wine_version);
let mut child = if let Some(custom_command) = options { let mut child = if let Some(custom_command) = options {
Self::run(proton, binary_path, Some(custom_command), env_variables).await? Self::run(wine, binary_path, Some(custom_command), env_variables).await?
} else { } else {
if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() { if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() {
Self::run(proton, binary_path, Some(custom_command), env_variables).await? Self::run(wine, binary_path, Some(custom_command), env_variables).await?
} else { } else {
Self::run(proton, binary_path, None, env_variables).await? Self::run(wine, binary_path, None, env_variables).await?
} }
}?; }?;
@ -205,7 +195,7 @@ impl GameManager {
.lines() .lines()
.inspect(|s| { .inspect(|s| {
if let Ok(str) = s { if let Ok(str) = s {
info!("[Proton] > {}", str); info!("[wine] > {}", str);
stdout_save.push_str(str); stdout_save.push_str(str);
} }
}) })
@ -219,7 +209,7 @@ impl GameManager {
.lines() .lines()
.inspect(|s| { .inspect(|s| {
if let Ok(str) = s { if let Ok(str) = s {
info!("[Proton] > {}", str); info!("[wine] > {}", str);
stderr_save.push_str(str); stderr_save.push_str(str);
} }
}) })
@ -292,21 +282,31 @@ impl GameManager {
} }
async fn run( async fn run(
proton: &Proton, wine: &Wine,
binary_path: PathBuf, binary_path: PathBuf,
custom_command: Option<String>, custom_command: Option<String>,
env_variables: Vec<EnvironmentVariable>, env_variables: Vec<EnvironmentVariable>,
) -> anyhow::Result<Result<Child, std::io::Error>> { ) -> anyhow::Result<Result<Child, std::io::Error>> {
let mut command: Vec<&str> = vec![]; let mut command: Vec<&str> = vec![];
let proton_path = GameConfig::get_config_directory() let wine_path = GameConfig::get_config_directory()
.await .await
.join("proton") .join("wine")
.join("proton"); .join("bin")
.join("wine");
let mut wine_path = wine_path.to_str().unwrap();
command.push(proton.python.to_str().unwrap()); if let Some(distro) = whatadistro::identify() {
command.push(proton_path.to_str().unwrap()); if distro.is_similar("nixos") {
command.push("run"); wine_path = "wine";
info!("Nixos detected, using system Wine...");
};
};
//command.push(wine.python.to_str().unwrap());
command.push(wine_path);
//command.push("run");
command.push(binary_path.to_str().unwrap()); command.push(binary_path.to_str().unwrap());
let launch_option; let launch_option;
@ -334,11 +334,14 @@ impl GameManager {
} }
debug!("Command preview -> {}", command.join(" ")); debug!("Command preview -> {}", command.join(" "));
debug!(
"Command envs -> {:?}",
wine.get_envs()["WINEPREFIX"].clone()
);
Ok(Command::new(command[0]) Ok(Command::new(command[0])
.args(&command[1..command.len()]) .args(&command[1..command.len()])
.envs(proton.get_envs()) .env("WINE_PREFIX", wine.get_envs()["WINEPREFIX"].clone())
.env("PROTON_LOG", "1")
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())

View File

@ -58,29 +58,29 @@ pub async fn patch_game(game_dir: PathBuf) -> anyhow::Result<()> {
// section to replace the executable with the patched one // section to replace the executable with the patched one
let executable_path = game_dir //let executable_path = game_dir
.join(get_game_name()) // .join(get_game_name())
.join(get_game_name_with_executable()); // .join(get_game_name_with_executable());
debug!("{:?}", executable_path); //debug!("{:?}", executable_path);
if executable_path.exists() { //if executable_path.exists() {
remove_file(executable_path.clone()).await?; // remove_file(executable_path.clone()).await?;
} //}
match PatchedGameExecutable::get_exectable() { //match PatchedGameExecutable::get_exectable() {
Some(exe) => { // Some(exe) => {
let mut file = File::create(executable_path).await?; // let mut file = File::create(executable_path).await?;
let data: Result<Vec<_>, _> = exe.data.bytes().collect(); // let data: Result<Vec<_>, _> = exe.data.bytes().collect();
let data = data.expect("Unable to read executable data"); // let data = data.expect("Unable to read executable data");
file.write_all(&data).await?; // file.write_all(&data).await?;
} // }
None => anyhow::bail!( // None => anyhow::bail!(
"Game executable not included in the binary! Please report this to the developer!" // "Game executable not included in the binary! Please report this to the developer!"
), // ),
} //}
let mut config = GameConfig::get_config().await; let mut config = GameConfig::get_config().await;
config.is_game_patched = true; config.is_game_patched = true;

View File

@ -2,7 +2,7 @@ use crate::{game_config::GameConfig, utils::kuro_prod_api::GameInfo};
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub enum GameState { pub enum GameState {
ProtonNotInstalled, WineNotInstalled,
DXVKNotInstalled, DXVKNotInstalled,
FontNotInstalled, FontNotInstalled,
DependecieNotInstalled, DependecieNotInstalled,
@ -17,7 +17,7 @@ impl GameState {
let config = GameConfig::get_config().await; let config = GameConfig::get_config().await;
if !config.is_wine_installed { if !config.is_wine_installed {
return Ok(GameState::ProtonNotInstalled); return Ok(GameState::WineNotInstalled);
} }
if !config.is_dxvk_installed { if !config.is_dxvk_installed {

View File

@ -1,3 +1,10 @@
use std::io;
use log::debug;
use tokio::fs::remove_dir_all;
use crate::game_config::GameConfig;
pub mod github_requester; pub mod github_requester;
pub mod kuro_prod_api; pub mod kuro_prod_api;
@ -8,3 +15,11 @@ pub fn get_game_name() -> String {
pub fn get_game_name_with_executable() -> String { pub fn get_game_name_with_executable() -> String {
format!("{}.exe", get_game_name()) format!("{}.exe", get_game_name())
} }
pub async fn remove_setup() -> io::Result<()> {
let config_dir = GameConfig::get_config_directory().await;
debug!("Current setup directory : {:?}", config_dir);
remove_dir_all(config_dir).await
}