feat: removed repair game button

Feature doesn't work like it was in other launchers
This commit is contained in:
Observer KRypt0n_ 2023-05-05 18:22:38 +02:00
parent c6b1c0d71f
commit 92c4b92e13
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 0 additions and 175 deletions

View file

@ -10,7 +10,6 @@ use adw::prelude::*;
use gtk::glib::clone; use gtk::glib::clone;
mod repair_game;
mod apply_patch; mod apply_patch;
mod download_wine; mod download_wine;
mod create_prefix; mod create_prefix;
@ -92,7 +91,6 @@ pub enum AppMsg {
DisableButtons(bool), DisableButtons(bool),
OpenPreferences, OpenPreferences,
RepairGame,
PredownloadUpdate, PredownloadUpdate,
PerformAction, PerformAction,
@ -842,8 +840,6 @@ impl SimpleComponent for App {
PREFERENCES_WINDOW.as_ref().unwrap_unchecked().widget().present(); 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)] #[allow(unused_must_use)]
AppMsg::PredownloadUpdate => { AppMsg::PredownloadUpdate => {
if let Some(LauncherState::PredownloadAvailable(mut game)) = self.state.clone() { if let Some(LauncherState::PredownloadAvailable(mut game)) = self.state.clone() {

View file

@ -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<App>, progress_bar_input: Sender<ProgressBarMsg>) {
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));
});
}

View file

@ -57,7 +57,6 @@ pub enum GeneralAppMsg {
SetMainPatch(Option<MainPatch>), SetMainPatch(Option<MainPatch>),
OpenMigrateInstallation, OpenMigrateInstallation,
RepairGame,
WineOpen(&'static [&'static str]), WineOpen(&'static [&'static str]),
UpdateLauncherStyle(LauncherStyle), UpdateLauncherStyle(LauncherStyle),
@ -253,12 +252,6 @@ impl SimpleAsyncComponent for GeneralApp {
set_tooltip_text: Some(&tr("migrate-installation-description")), set_tooltip_text: Some(&tr("migrate-installation-description")),
connect_clicked => GeneralAppMsg::OpenMigrateInstallation 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(); self.migrate_installation.widget().show();
} }
#[allow(unused_must_use)]
GeneralAppMsg::RepairGame => {
sender.output(Self::Output::RepairGame);
}
GeneralAppMsg::WineOpen(executable) => { GeneralAppMsg::WineOpen(executable) => {
let config = Config::get().unwrap_or_else(|_| CONFIG.clone()); let config = Config::get().unwrap_or_else(|_| CONFIG.clone());

View file

@ -40,7 +40,6 @@ pub enum PreferencesAppMsg {
SetLauncherStyle(LauncherStyle), SetLauncherStyle(LauncherStyle),
UpdateLauncherState, UpdateLauncherState,
RepairGame,
Toast { Toast {
title: String, 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 { PreferencesAppMsg::Toast { title, description } => unsafe {
let toast = adw::Toast::new(&title); let toast = adw::Toast::new(&title);