Progress work normally now

This commit is contained in:
ALEZ-DEV 2024-04-29 22:10:59 +02:00
parent 2c6e1c67b2
commit c1a4c5c2f6
8 changed files with 45 additions and 8 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
set_github_env.sh set_github_env.sh
babylonia-terminal-cli/TDData-data.db
babylonia-terminal-cli/backtrace.txt

View File

@ -80,6 +80,7 @@ dependencies = [
"dotenv", "dotenv",
"downloader", "downloader",
"flate2", "flate2",
"fs_extra",
"log", "log",
"reqwest 0.12.2", "reqwest 0.12.2",
"serde", "serde",
@ -397,6 +398,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.30" version = "0.3.30"

View File

@ -75,8 +75,8 @@ async fn main() {
GameState::GameNotInstalled => { GameState::GameNotInstalled => {
info!("Game not installed, installing it..."); info!("Game not installed, installing it...");
GameManager::install_game( GameManager::install_game(
GameState::get_config_directory(), GameState::get_config_directory().join("PGR"),
DownloadReporter::create(true), DownloadReporter::create(false),
) )
.await .await
.expect("Failed to install the game"); .expect("Failed to install the game");
@ -90,5 +90,9 @@ async fn main() {
} }
info!("Starting game..."); info!("Starting game...");
GameManager::start_game(&wine.unwrap()).await; GameManager::start_game(
&wine.unwrap(),
GameState::get_config_directory().join("PGR"),
)
.await;
} }

View File

@ -67,6 +67,7 @@ dependencies = [
"dotenv", "dotenv",
"downloader", "downloader",
"flate2", "flate2",
"fs_extra",
"log", "log",
"reqwest 0.12.2", "reqwest 0.12.2",
"serde", "serde",
@ -346,6 +347,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.30" version = "0.3.30"

View File

@ -12,6 +12,7 @@ dirs = "5.0.1"
dotenv = "0.15.0" dotenv = "0.15.0"
downloader = { git = "https://github.com/ALEZ-DEV/downloader" } # version = "0.2.7", downloader = { git = "https://github.com/ALEZ-DEV/downloader" } # version = "0.2.7",
flate2 = "1.0.28" flate2 = "1.0.28"
fs_extra = "1.3.0"
log = "0.4.21" log = "0.4.21"
reqwest = { version = "0.12.2", features = ["gzip"] } reqwest = { version = "0.12.2", features = ["gzip"] }
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }

View File

@ -7,8 +7,9 @@ use std::{
use downloader::progress::Reporter; use downloader::progress::Reporter;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use log::info; use log::{debug, info};
use tar::Archive; use tar::Archive;
use tokio::fs::create_dir_all;
use tokio::time::sleep; use tokio::time::sleep;
use wincompatlib::{prelude::*, wine::bundle::proton}; use wincompatlib::{prelude::*, wine::bundle::proton};
use xz::read::XzDecoder; use xz::read::XzDecoder;
@ -126,11 +127,13 @@ impl GameManager {
Ok(()) Ok(())
} }
pub async fn install_game<P>(config_dir: PathBuf, progress: Arc<P>) -> anyhow::Result<()> pub async fn install_game<P>(game_dir: PathBuf, progress: Arc<P>) -> anyhow::Result<()>
where where
P: Reporter + 'static, P: Reporter + 'static,
{ {
let game_component = GameComponent::new(config_dir); let _ = create_dir_all(game_dir.clone()).await;
let game_component = GameComponent::new(game_dir);
game_component.install(Some(progress)).await?; game_component.install(Some(progress)).await?;
let mut config = GameState::get_config().await?; let mut config = GameState::get_config().await?;
@ -140,8 +143,9 @@ impl GameManager {
Ok(()) Ok(())
} }
pub async fn start_game(wine: &Wine) { pub async fn start_game(wine: &Wine, game_dir: PathBuf) {
wine.run("/home/alez/.steam/steam/steamapps/compatdata/3841903579/pfx/drive_c/Punishing Gray Raven/launcher.exe").unwrap(); debug!("Wine version : {:?}", wine.version().unwrap());
wine.run(game_dir.join("PGR.exe")).unwrap();
loop { loop {
sleep(Duration::from_millis(10000)).await; sleep(Duration::from_millis(10000)).await;

View File

@ -129,6 +129,16 @@ impl GameInfo {
} }
} }
impl Resources {
pub fn get_max_size_resources(&self) -> u64 {
let mut max_size: u64 = 0;
self.resource.iter().for_each(|r| max_size += r.size as u64);
max_size
}
}
impl Resource { impl Resource {
pub fn build_download_url(&self, base_url: &str, zip_uri: &str) -> String { pub fn build_download_url(&self, base_url: &str, zip_uri: &str) -> String {
format!("{}{}{}", base_url, zip_uri, self.dest) format!("{}{}{}", base_url, zip_uri, self.dest)