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
babylonia-terminal-cli/TDData-data.db
babylonia-terminal-cli/backtrace.txt

View File

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

View File

@ -75,8 +75,8 @@ async fn main() {
GameState::GameNotInstalled => {
info!("Game not installed, installing it...");
GameManager::install_game(
GameState::get_config_directory(),
DownloadReporter::create(true),
GameState::get_config_directory().join("PGR"),
DownloadReporter::create(false),
)
.await
.expect("Failed to install the game");
@ -90,5 +90,9 @@ async fn main() {
}
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",
"downloader",
"flate2",
"fs_extra",
"log",
"reqwest 0.12.2",
"serde",
@ -346,6 +347,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "futures"
version = "0.3.30"

View File

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

View File

@ -7,8 +7,9 @@ use std::{
use downloader::progress::Reporter;
use flate2::read::GzDecoder;
use log::info;
use log::{debug, info};
use tar::Archive;
use tokio::fs::create_dir_all;
use tokio::time::sleep;
use wincompatlib::{prelude::*, wine::bundle::proton};
use xz::read::XzDecoder;
@ -126,11 +127,13 @@ impl GameManager {
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
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?;
let mut config = GameState::get_config().await?;
@ -140,8 +143,9 @@ impl GameManager {
Ok(())
}
pub async fn start_game(wine: &Wine) {
wine.run("/home/alez/.steam/steam/steamapps/compatdata/3841903579/pfx/drive_c/Punishing Gray Raven/launcher.exe").unwrap();
pub async fn start_game(wine: &Wine, game_dir: PathBuf) {
debug!("Wine version : {:?}", wine.version().unwrap());
wine.run(game_dir.join("PGR.exe")).unwrap();
loop {
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 {
pub fn build_download_url(&self, base_url: &str, zip_uri: &str) -> String {
format!("{}{}{}", base_url, zip_uri, self.dest)