diff --git a/src/ui/main/mod.rs b/src/ui/main/mod.rs index b5197bc..b42ff40 100644 --- a/src/ui/main/mod.rs +++ b/src/ui/main/mod.rs @@ -10,7 +10,6 @@ use adw::prelude::*; use gtk::glib::clone; -mod repair_game; mod apply_patch; mod download_wine; mod create_prefix; @@ -92,7 +91,6 @@ pub enum AppMsg { DisableButtons(bool), OpenPreferences, - RepairGame, PredownloadUpdate, PerformAction, @@ -842,8 +840,6 @@ impl SimpleComponent for App { PREFERENCES_WINDOW.as_ref().unwrap_unchecked().widget().present(); } - AppMsg::RepairGame => repair_game::repair_game(sender, self.progress_bar.sender().to_owned()), - #[allow(unused_must_use)] AppMsg::PredownloadUpdate => { if let Some(LauncherState::PredownloadAvailable(mut game)) = self.state.clone() { diff --git a/src/ui/main/repair_game.rs b/src/ui/main/repair_game.rs deleted file mode 100644 index 79bff9e..0000000 --- a/src/ui/main/repair_game.rs +++ /dev/null @@ -1,151 +0,0 @@ -use relm4::{ - prelude::*, - Sender -}; - -use gtk::glib::clone; - -use std::path::Path; - -use crate::*; -use crate::i18n::*; -use crate::ui::components::*; -use super::{App, AppMsg}; - -#[allow(unused_must_use)] -pub fn repair_game(sender: ComponentSender, progress_bar_input: Sender) { - let config = Config::get().unwrap(); - - progress_bar_input.send(ProgressBarMsg::UpdateCaption(Some(tr("verifying-files")))); - sender.input(AppMsg::SetDownloading(true)); - - std::thread::spawn(move || { - match repairer::try_get_integrity_files(None) { - Ok(files) => { - let game_path = config.game.path.for_edition(config.launcher.edition).to_path_buf(); - - progress_bar_input.send(ProgressBarMsg::UpdateProgress(0, 0)); - - let mut total = 0; - - for file in &files { - total += file.size; - } - - let median_size = total / config.launcher.repairer.threads; - let mut i = 0; - - let (verify_sender, verify_receiver) = std::sync::mpsc::channel(); - - for _ in 0..config.launcher.repairer.threads { - let mut thread_files = Vec::new(); - let mut thread_files_size = 0; - - while i < files.len() { - thread_files.push(files[i].clone()); - - thread_files_size += files[i].size; - i += 1; - - if thread_files_size >= median_size { - break; - } - } - - let thread_sender = verify_sender.clone(); - - std::thread::spawn(clone!(@strong game_path => move || { - for file in thread_files { - let status = if config.launcher.repairer.fast { - file.fast_verify(&game_path) - } else { - file.verify(&game_path) - }; - - thread_sender.send((file, status)).unwrap(); - } - })); - } - - // We have [config.launcher.repairer.threads] copies of this sender + the original one - // receiver will return Err when all the senders will be dropped. - // [config.launcher.repairer.threads] senders will be dropped when threads will finish verifying files - // but this one will live as long as current thread exists so we should drop it manually - drop(verify_sender); - - let mut broken = Vec::new(); - let mut processed = 0; - - while let Ok((file, status)) = verify_receiver.recv() { - processed += file.size; - - if !status { - broken.push(file); - } - - progress_bar_input.send(ProgressBarMsg::UpdateProgress(processed, total)); - } - - if !broken.is_empty() { - progress_bar_input.send(ProgressBarMsg::UpdateCaption(Some(tr("repairing-files")))); - progress_bar_input.send(ProgressBarMsg::DisplayFraction(false)); - progress_bar_input.send(ProgressBarMsg::UpdateProgress(0, 0)); - - tracing::warn!("Found broken files:\n{}", broken.iter().fold(String::new(), |acc, file| acc + &format!("- {}\n", file.path.to_string_lossy()))); - - let total = broken.len() as f64; - - let main_patch = MainPatch::from_folder(&config.patch.path, config.launcher.edition).unwrap() - .is_applied(&game_path).unwrap(); - - tracing::debug!("Patch status: {main_patch}"); - - fn should_ignore(path: &Path, main_patch: bool) -> bool { - // Main patch related files - if main_patch { - for part in ["StarRailBase.dll", "UnityPlayer.dll"] { - if path.ends_with(part) { - return true; - } - } - } - - false - } - - for (i, file) in broken.into_iter().enumerate() { - if !should_ignore(&file.path, main_patch) { - tracing::debug!("Repairing file: {}", file.path.to_string_lossy()); - - if let Err(err) = file.repair(&game_path) { - sender.input(AppMsg::Toast { - title: tr("game-file-repairing-error"), - description: Some(err.to_string()) - }); - - tracing::error!("Failed to repair game file: {err}"); - } - } - - else { - tracing::debug!("Skipped file: {}", file.path.to_string_lossy()); - } - - progress_bar_input.send(ProgressBarMsg::UpdateProgress(i as u64, total as u64)); - } - } - } - - Err(err) => { - tracing::error!("Failed to get inregrity failes: {err}"); - - sender.input(AppMsg::Toast { - title: tr("integrity-files-getting-error"), - description: Some(err.to_string()) - }); - } - } - - sender.input(AppMsg::SetDownloading(false)); - }); -} diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index 875427f..05546df 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -57,7 +57,6 @@ pub enum GeneralAppMsg { SetMainPatch(Option), OpenMigrateInstallation, - RepairGame, WineOpen(&'static [&'static str]), UpdateLauncherStyle(LauncherStyle), @@ -253,12 +252,6 @@ impl SimpleAsyncComponent for GeneralApp { set_tooltip_text: Some(&tr("migrate-installation-description")), connect_clicked => GeneralAppMsg::OpenMigrateInstallation - }, - - gtk::Button { - set_label: &tr("repair-game"), - - connect_clicked => GeneralAppMsg::RepairGame } } }, @@ -722,11 +715,6 @@ impl SimpleAsyncComponent for GeneralApp { self.migrate_installation.widget().show(); } - #[allow(unused_must_use)] - GeneralAppMsg::RepairGame => { - sender.output(Self::Output::RepairGame); - } - GeneralAppMsg::WineOpen(executable) => { let config = Config::get().unwrap_or_else(|_| CONFIG.clone()); diff --git a/src/ui/preferences/main.rs b/src/ui/preferences/main.rs index aefd30b..3acbcd3 100644 --- a/src/ui/preferences/main.rs +++ b/src/ui/preferences/main.rs @@ -40,7 +40,6 @@ pub enum PreferencesAppMsg { SetLauncherStyle(LauncherStyle), UpdateLauncherState, - RepairGame, Toast { title: String, @@ -152,13 +151,6 @@ impl SimpleAsyncComponent for PreferencesApp { }); } - #[allow(unused_must_use)] - PreferencesAppMsg::RepairGame => unsafe { - PREFERENCES_WINDOW.as_ref().unwrap_unchecked().close(); - - sender.output(Self::Output::RepairGame); - } - PreferencesAppMsg::Toast { title, description } => unsafe { let toast = adw::Toast::new(&title);