mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2026-03-21 21:58:52 +00:00
Compare commits
2 Commits
e41eece4a8
...
5e3c640e4e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e3c640e4e | |||
| e1fee118d6 |
@ -24,6 +24,30 @@ pub async fn run(
|
|||||||
let mut wine_component: Option<WineComponent> = None;
|
let mut wine_component: Option<WineComponent> = None;
|
||||||
let mut wine: Option<Wine> = 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;
|
||||||
if let Err(error) = state_result {
|
if let Err(error) = state_result {
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user