Skip to content

Commit

Permalink
Start integrating update check into client mod
Browse files Browse the repository at this point in the history
  • Loading branch information
RubberDuckShobe committed Apr 27, 2024
1 parent 031ba8d commit ae006aa
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
4 changes: 3 additions & 1 deletion updater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wavebreaker_up"
version = "0.1.0"
version = "1.0.0"
edition = "2021"

[dependencies]
Expand All @@ -17,3 +17,5 @@ tracing = "0.1.40"
lazy_async_promise = { path = "./lazy_async_promise" }
reqwest = "0.12.4"
zip-extract = "0.1.3"
open = "5.1.2"
sysinfo = "0.30.11"
44 changes: 40 additions & 4 deletions updater/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::{borrow::Cow, io::Cursor, path::Path};
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use std::{borrow::Cow, io::Cursor, path::Path, time::Duration};

use anyhow::{anyhow, bail, Context};
use eframe::egui::{
self, Align, FontData, FontDefinitions, FontFamily, IconData, Layout, ProgressBar, RichText, Vec2, ViewportBuilder
self, Align, FontData, FontDefinitions, FontFamily, Layout, ProgressBar, RichText, Vec2,
ViewportBuilder, ViewportCommand,
};
use lazy_async_promise::{
ImmediateValuePromise, ImmediateValueState, Progress, ProgressTrackedImValProm, StringStatus,
};
use sysinfo::{ProcessRefreshKind, RefreshKind, System};

#[tokio::main]
async fn main() -> eframe::Result<()> {
Expand Down Expand Up @@ -104,7 +108,7 @@ impl MyEguiApp {
.ok_or_else(|| anyhow!("Failed to find asset in latest release"))?;

s.send(StringStatus::new(
Progress::from_percent(20),
Progress::from_percent(25),
format!("Grabbing {}", release_asset_url).into(),
))
.await
Expand All @@ -118,7 +122,7 @@ impl MyEguiApp {
.context("Failed to get response bytes")?;

s.send(StringStatus::new(
Progress::from_percent(40),
Progress::from_percent(50),
"Extracting files".into(),
))
.await
Expand All @@ -129,6 +133,37 @@ impl MyEguiApp {
zip_extract::extract(Cursor::new(bytes), Path::new("."), false)
.context("Failed to extract zip")?;

s.send(StringStatus::new(
Progress::from_percent(75),
"Launching game".into(),
))
.await
.unwrap();
open::that_detached("steam://launch/12900")
.context("Failed to launch game!")?;

let mut system = System::new_with_specifics(
RefreshKind::new().with_processes(ProcessRefreshKind::everything()),
);
// Wait until the game is launched
while system
.processes_by_exact_name("QuestViewer.exe")
.collect::<Vec<_>>()
.is_empty()
{
tokio::time::sleep(Duration::from_millis(500)).await;
system.refresh_processes_specifics(
ProcessRefreshKind::new().with_exe(sysinfo::UpdateKind::OnlyIfNotSet),
);
}

s.send(StringStatus::new(
Progress::from_percent(100),
"Done!".into(),
))
.await
.unwrap();

Ok(())
})
},
Expand Down Expand Up @@ -163,6 +198,7 @@ impl eframe::App for MyEguiApp {
ui.label(
RichText::new("Done!").color(catppuccin_egui::MACCHIATO.green),
);
ctx.send_viewport_cmd(ViewportCommand::Close)
}
ImmediateValueState::Error(err) => {
ui.label(
Expand Down
6 changes: 5 additions & 1 deletion wavebreaker_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wavebreaker_client"
version = "3.2.0"
version = "3.3.0"
edition = "2021"

[lib]
Expand Down Expand Up @@ -34,6 +34,10 @@ lofty = "0.19.0"
url_encoded_data = "0.6.1"
bass-sys = "2.3.0"
rfd = "0.14.1"
octocrab = "0.38.0"
semver = "1.0.22"
pollster = "0.3.0"
tokio = { version = "1.37.0", features = ["full"] }

[build-dependencies]
bindgen = "0.69.4"
1 change: 1 addition & 0 deletions wavebreaker_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Config {

#[derive(Deserialize)]
pub struct Main {
pub auto_update: bool,
pub server: String,
pub force_insecure: bool,
}
Expand Down
29 changes: 27 additions & 2 deletions wavebreaker_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use std::{
thread,
};

use anyhow::Context;
use bass_sys::{BASS_ErrorGetCode, BASS_PluginLoad};
use config::Config;
use figment::{
providers::{Env, Format, Toml},
Figment,
};
use bass_sys::{BASS_ErrorGetCode, BASS_PluginLoad};
use pollster::FutureExt;
use tracing::{debug, error, info};
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};
Expand Down Expand Up @@ -55,6 +57,28 @@ unsafe fn main() -> anyhow::Result<()> {
.extract()?;
let _ = config::CONFIG.set(config);

if config::CONFIG.get().unwrap().main.auto_update {
info!("Checking for updates");
let octocrab = octocrab::instance();
let repo = octocrab.repos("AudiosurfResearch", "Wavebreaker-Hook");
let release = repo
.releases()
.get_latest()
.block_on()
.context("Failed to get releases from repo")?;
let tag_version =
semver::Version::parse(&release.tag_name).context("Failed to parse tag")?;
let current_version = semver::Version::parse(env!("CARGO_PKG_VERSION"))?;
info!(
"Current version {}, latest is tag_version {}",
current_version, tag_version
);
if tag_version > current_version {
info!("New version {} available!", tag_version);
std::process::exit(0); //just brutally kill the game
}
}

while GetModuleHandleA(s!("17C5B19F-4273-423C-A158-CA6F73046D43.dll")).is_err()
|| GetModuleHandleA(s!("HTTP_Fetch_Unicode.dll")).is_err()
|| GetModuleHandleA(s!("bass.dll")).is_err()
Expand All @@ -70,7 +94,8 @@ unsafe fn main() -> anyhow::Result<()> {

info!("Loading Opus BASS plugin");
let opus_plugin_name = CString::new("bassopus").unwrap();
let plugin_handle: *const () = BASS_PluginLoad(opus_plugin_name.as_ptr().cast(), 0) as *const ();
let plugin_handle: *const () =
BASS_PluginLoad(opus_plugin_name.as_ptr().cast(), 0) as *const ();
debug!("BASSOPUS handle: {:p}", plugin_handle);
debug!("BASS error code: {:?}", BASS_ErrorGetCode());

Expand Down

0 comments on commit ae006aa

Please sign in to comment.