Skip to content

Commit

Permalink
Improve performance of patching significantly
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyX committed Dec 23, 2022
1 parent 83acc4e commit c6db91f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
2 changes: 2 additions & 0 deletions backend/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]
15 changes: 9 additions & 6 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ build = "build.rs"
include = ["src/**/*", "Cargo.toml"]

[dependencies]
tokio = { version = "1.21.2", features = ["full"] }
url = "2.3.1"
tokio = { version = "1.23", features = ["full", "tracing"] }
url = "2.3"
sciter-rs = "0.5"
renegadex_patcher = { git = "https://github.com/SonnyX/RenegadeX-patcher-lib" }
rust-ini = "0.18"
single-instance = "0.3"
socket2 = { version="0.4", features=["all"]}
rand = "0.8"
percent-encoding = "2.2.0"
percent-encoding = "2.2"
unzip = { git = "https://github.com/SonnyX/unzip-rs" }
dirs = "4.0"
runas = { git = "https://github.com/SonnyX/rust-runas" }
Expand All @@ -26,11 +26,14 @@ flexi_logger = "0.24"
download-async = "0.10"
async-trait = "0.1"
json = "0.12"
quick-xml = { version="0.25" }
semver = "1.0.14"
quick-xml = { version="0.26" }
semver = "1.0"
console-subscriber="0.1.8"
tracing-subscriber="0.3"
tracing="0.1"

[build-dependencies]
embed-resource = "1.7.3"
embed-resource = "1.8"

[profile.release]
opt-level = 'z'
Expand Down
22 changes: 22 additions & 0 deletions backend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum Error {
ParseError(url::ParseError),
ParseIntError(std::num::ParseIntError),
UnzipError(std::io::Error),
JsonError(json::Error),
DownloadTimeout(tokio::time::error::Elapsed)
}

impl std::error::Error for Error { }
Expand All @@ -38,6 +40,8 @@ impl std::fmt::Display for Error {
Self::ParseError(e) => write!(f,"ParseError({:?})", e),
Self::ParseIntError(e) => write!(f,"ParseIntError({:?})", e),
Self::UnzipError(e) => write!(f,"UnzipError({:?})", e),
Self::JsonError(e) => write!(f,"JsonError({:?})", e),
Self::DownloadTimeout(e) => write!(f,"DownloadTimeout({:?})", e)
}
}
}
Expand Down Expand Up @@ -81,6 +85,15 @@ impl From<renegadex_patcher::Error> for Error {
}
}

impl From<json::Error> for Error {
#[track_caller]
#[inline(always)]
fn from(error: json::Error) -> Self {
log_error(&error);
Self::JsonError(error)
}
}

impl From<sciter::value::VALUE_RESULT> for Error {
#[track_caller]
#[inline(always)]
Expand Down Expand Up @@ -144,6 +157,15 @@ impl From<std::str::Utf8Error> for Error {
}
}

impl From<tokio::time::error::Elapsed> for Error {
#[track_caller]
#[inline(always)]
fn from(error: tokio::time::error::Elapsed) -> Self {
log_error(&error);
Self::DownloadTimeout(error)
}
}

#[track_caller]
fn log_error(error: &(impl std::error::Error + ?Sized)) {
let location = Some(std::panic::Location::caller());
Expand Down
12 changes: 11 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![windows_subsystem="windows"]
#![windows_subsystem="console"]
#![warn(clippy::multiple_crate_versions)]
extern crate tokio;
#[macro_use] extern crate sciter;
Expand All @@ -15,6 +15,8 @@ extern crate hex;
extern crate log;
extern crate download_async;
extern crate async_trait;
extern crate tracing;
extern crate tracing_subscriber;

mod configuration;
mod handler;
Expand All @@ -29,6 +31,7 @@ use flexi_logger::{Age, Criterion, Cleanup, Logger, Naming};
use log::*;
use single_instance::SingleInstance;
use tokio::sync::Mutex;
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, Layer, util::SubscriberInitExt};
use std::sync::Arc;
use handler::Handler;

Expand Down Expand Up @@ -157,6 +160,13 @@ fn launch_ui(current_dir: String) -> std::thread::JoinHandle<Result<(),Error>> {
}
}
let runtime : tokio::runtime::Runtime = tokio::runtime::Builder::new_multi_thread().enable_all().thread_stack_size(2_usize.pow(22)).build().expect("");
let console_layer = console_subscriber::ConsoleLayer::builder().with_default_env().spawn();

tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer().with_filter(tracing_subscriber::filter::LevelFilter::from_level(tracing::Level::DEBUG)))
.init();

if configuration.get_playername().eq("UnknownPlayer") {
let mut frame = sciter::Window::new();
frame.event_handler(Handler{patcher: Arc::new(Mutex::new(None)), version_information: Arc::new(Mutex::new(None)), configuration: configuration.clone(), runtime: runtime.handle().clone()});
Expand Down
4 changes: 2 additions & 2 deletions backend/src/version_information.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

use std::time::Duration;

use renegadex_patcher::{Error, NamedUrl};
use renegadex_patcher::NamedUrl;

use crate::as_string::AsString;
use crate::{as_string::AsString, error::Error};

#[derive(Clone)]
pub struct VersionInformation {
Expand Down
6 changes: 6 additions & 0 deletions compile with cross.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cd backend
cross update
cross build --release --target=i686-pc-windows-gnu
cd ..
echo F|xcopy /Y backend\target\i686-pc-windows-gnu\release\renegade-x-launcher.exe RenegadeX-Launcher.exe
pause
6 changes: 3 additions & 3 deletions compile.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd backend
cross update
cross build --release --target=i686-pc-windows-gnu
cargo update
cargo build --release
cd ..
echo F|xcopy /Y backend\target\i686-pc-windows-gnu\release\renegade-x-launcher.exe RenegadeX-Launcher.exe
echo F|xcopy /Y backend\target\release\renegade-x-launcher.exe RenegadeX-Launcher.exe
pause

0 comments on commit c6db91f

Please sign in to comment.