Skip to content

Commit

Permalink
Merge branch 'develop' into feature/simple-gui
Browse files Browse the repository at this point in the history
  • Loading branch information
ktwrd committed Jun 15, 2024
2 parents 7db917c + 2a2f9a3 commit baf0519
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 61 deletions.
Binary file added Binaries/7z.dll
Binary file not shown.
Binary file added Binaries/7z.so
Binary file not shown.
Binary file added Binaries/c7zip.dll
Binary file not shown.
Binary file added Binaries/libc7zip.so
Binary file not shown.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "beans-rs"
version = "1.4.2"
version = "1.4.4"
edition = "2021"
authors = [
"Adastral Group (https://adastral.net)",
"Kate Ward <[email protected]>"
]
description = "Installer for Open Fortress"
repository = "https://github.com/AdastralGroup/beans-rs"
repository = "https://github.com/ktwrd/beans-rs"
license = "GPL-3.0"

[dependencies]
Expand All @@ -31,11 +30,11 @@ clap = { version = "4.5.4", features = ["cargo"] }
bitflags = "2.5.0"
log = "0.4.21"
native-dialog = "0.7.0"
sentry = "0.33.0"
sentry = "0.34.0"
lazy_static = "1.4.0"
thread-id = "4.2.1"
colored = "2.1.0"
sentry-log = "0.33.0"
sentry-log = "0.34.0"

fltk = { version = "1.4.30", features = ["fltk-bundled"] }
fltk-theme = "0.7.2"
Expand All @@ -44,7 +43,7 @@ fltk-theme = "0.7.2"
fl2rust = "0.5.19"

[target.'cfg(target_os = "windows")'.dependencies]
winconsole = "0.11.1"
winconsole = { version = "0.11.1", features = ["window"] }
winreg = "0.52.0"
dunce = "1.0.4"

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub async fn task_launch(&mut self, matches: &ArgMatches) {
### Binaries
All the bundled/embedded binaries are for x86-64/AMD64 systems. We only support that architecture because that's what Open Fortress supports.

Please do not make any PRs to remove the embedded executables in favor of downloading. Some users would like to use this application offline, or they may have unreliable internet.

Linux Systems not using glibc have not been tested.

### FLTK Linux Dependencies
Expand Down Expand Up @@ -110,4 +112,4 @@ sudo apt-get install -y \
sudo yum groupinstall -y "Development Tools"
sudo yum groupinstall -y "X Software Development"
sudo yum groupinstall -y "C Development Tools and Libraries"
```
```
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly-2024-05-24"
22 changes: 0 additions & 22 deletions src/butler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,4 @@ pub fn patch(
Ok(w)
}
}
}

pub fn fetch_7z_libs() -> Result<ExitStatus, BeansError> {
println!("[butler::fetch_7z_libs] fetching 7z libraries");
match std::process::Command::new(&depends::get_butler_location())
.arg("fetch-7z-libs")
.spawn() {
Err(e) => {
let xe = BeansError::IO {
error: e,
backtrace: Backtrace::capture()
};

sentry::capture_error(&xe);
Err(xe)
},
Ok(mut v) => {
let w = v.wait()?;
debug!("Exited with {:#?}", w);
Ok(w)
}
}
}
24 changes: 16 additions & 8 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::helper::{find_sourcemod_path, InstallType, parse_location};
use crate::version::{RemotePatch, RemoteVersion, RemoteVersionResponse};
#[cfg(target_os = "linux")]
use std::os::unix::fs::PermissionsExt;
use log::{debug, error, info};
use log::{debug, error, info, trace};

#[derive(Debug, Clone)]
pub struct RunnerContext
Expand Down Expand Up @@ -235,12 +235,17 @@ impl RunnerContext
}
}
match x {
Err(e) => Err(BeansError::TarExtractFailure{
src_file: tar_tmp_location,
target_dir: out_dir,
error: e,
backtrace: Backtrace::capture()
}),
Err(e) => {
let xe = BeansError::TarExtractFailure {
src_file: tar_tmp_location,
target_dir: out_dir,
error: e,
backtrace: Backtrace::capture()
};
trace!("[RunnerContext::extract_package] {:}\n{:#?}", xe, xe);
sentry::capture_error(&xe);
return Err(xe);
},
Ok(_) => Ok(())
}
}
Expand All @@ -254,7 +259,10 @@ impl RunnerContext
let ln_location = format!("{}{}", mod_location, target);
if helper::file_exists(ln_location.clone())
&& helper::is_symlink(ln_location.clone()) == false {
std::fs::remove_file(&ln_location)?;
if let Err(e) = std::fs::remove_file(&ln_location) {
trace!("[RunnerContext::prepare_symlink] failed to remove {}\n{:#?}", ln_location, e);
return Err(e.into());
}
}
}

Expand Down
37 changes: 29 additions & 8 deletions src/depends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
use std::os::unix::fs::PermissionsExt;
#[cfg(target_os = "windows")]
use std::backtrace::Backtrace;
use crate::{BeansError, BUTLER_BINARY, helper, butler};
#[allow(unused_imports)]
use log::{debug, error, info, trace};
use crate::{BeansError, BUTLER_BINARY, BUTLER_LIB_1, BUTLER_LIB_2, helper};
use log::{debug, error};

/// try and write aria2c and butler if it doesn't exist
/// paths that are used will be fetched from binary_locations()
pub fn try_write_deps()
{
safe_write_file(get_butler_location().as_str(), &**BUTLER_BINARY);
safe_write_file(get_butler_1_location().as_str(), &**BUTLER_LIB_1);
safe_write_file(get_butler_2_location().as_str(), &**BUTLER_LIB_2);
#[cfg(not(target_os = "windows"))]
if helper::file_exists(get_butler_location()) {
let p = std::fs::Permissions::from_mode(0744 as u32);
Expand All @@ -21,11 +22,6 @@ pub fn try_write_deps()
}
debug!("[depends::try_write_deps] set perms on {}", get_butler_location());
}

if let Err(e) = butler::fetch_7z_libs() {
error!("[depends::try_write_deps] Failed to fetch 7z libaries");
error!("[depends::try_write_deps] {:#?}", e);
}
}
fn safe_write_file(location: &str, data: &[u8]) {
if !helper::file_exists(location.to_string())
Expand Down Expand Up @@ -102,6 +98,8 @@ pub async fn try_install_vcredist() -> Result<(), BeansError>

pub fn butler_exists() -> bool {
helper::file_exists(get_butler_location())
&& helper::file_exists(get_butler_1_location())
&& helper::file_exists(get_butler_2_location())
}

pub fn get_butler_location() -> String
Expand All @@ -110,8 +108,31 @@ pub fn get_butler_location() -> String
path.push_str(BUTLER_LOCATION);
path
}
pub fn get_butler_1_location() -> String {
let mut path = get_tmp_dir();
path.push_str(BUTLER_1);
path
}
pub fn get_butler_2_location() -> String {
let mut path = get_tmp_dir();
path.push_str(BUTLER_2);
path
}
fn get_tmp_dir() -> String {
let path = helper::get_tmp_dir();
helper::format_directory_path(path)
}

#[cfg(target_os = "windows")]
const BUTLER_LOCATION: &str = "butler.exe";
#[cfg(not(target_os = "windows"))]
const BUTLER_LOCATION: &str = "butler";

#[cfg(target_os = "windows")]
const BUTLER_1: &str = "7z.dll";
#[cfg(not(target_os = "windows"))]
const BUTLER_1: &str = "7z.so";
#[cfg(target_os = "windows")]
const BUTLER_2: &str = "c7zip.dll";
#[cfg(not(target_os = "windows"))]
const BUTLER_2: &str = "libc7zip.so";
10 changes: 5 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ pub enum BeansError
location: String,
error: std::io::Error
},
#[error("Failed to extract {src_file} to directory {target_dir}")]
#[error("Failed to extract {src_file} to directory {target_dir} ({error:})")]
TarExtractFailure {
src_file: String,
target_dir: String,
error: std::io::Error,
backtrace: Backtrace
},
#[error("Failed to send request")]
#[error("Failed to send request ({error:})")]
Reqwest {
error: reqwest::Error,
backtrace: Backtrace
},
#[error("Failed to serialize or deserialize data")]
#[error("Failed to serialize or deserialize data ({error:})")]
SerdeJson {
error: serde_json::Error,
backtrace: Backtrace
Expand Down Expand Up @@ -65,7 +65,7 @@ pub enum BeansError
backtrace: Backtrace
},

#[error("Failed to run the verify command with butler.")]
#[error("Failed to run the verify command with butler. ({error:})")]
ButlerVerifyFailure {
signature_url: String,
gamedir: String,
Expand Down Expand Up @@ -118,7 +118,7 @@ pub enum BeansError
error: serde_json::Error,
instance: AdastralVersionFile
},
#[error("Failed to parse the version in {old_location}. It's content was {old_content}")]
#[error("Failed to parse the version in {old_location}. It's content was {old_content} ({error:})")]
VersionFileParseFailure {
error: ParseIntError,
old_location: String,
Expand Down
36 changes: 29 additions & 7 deletions src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::path::PathBuf;
use indicatif::{ProgressBar, ProgressStyle};
use futures::StreamExt;
use futures_util::SinkExt;
use log::{debug, error, trace};
use log::{debug, error, trace, warn};
use crate::{BeansError, DownloadFailureReason, RunnerContext};
use rand::{distributions::Alphanumeric, Rng};
use reqwest::header::USER_AGENT;
Expand Down Expand Up @@ -367,12 +367,29 @@ pub fn format_size(i: u64) -> String {
}
return format!("{}{}", whole, dec_x);
}
/// Create directory in temp directory with name of "beans-rs"
pub fn get_tmp_dir() -> String
{
#[cfg(not(target_os = "windows"))]
return format_directory_path(String::from("/var/tmp"));
#[cfg(target_os = "windows")]
return format_directory_path(std::env::temp_dir().to_str().unwrap_or("").to_string());
let mut dir = std::env::temp_dir().to_str().unwrap_or("").to_string();
if cfg!(target_os = "android") {
dir = String::from("/data/var/tmp");
} else if cfg!(not(target_os = "windows")) {
dir = String::from("/var/tmp");
}
dir = format_directory_path(dir);
dir = join_path(dir, String::from("beans-rs"));
dir = format_directory_path(dir);

if !file_exists(dir.clone()) {
if let Err(e) = std::fs::create_dir(&dir) {
warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e);
sentry::capture_error(&e);
} else {
trace!("[helper::get_tmp_dir] created directory {}", dir);
}
}

return dir;
}
/// Generate a full file location for a temporary file.
pub fn get_tmp_file(filename: String) -> String
Expand Down Expand Up @@ -428,12 +445,17 @@ pub fn restore_gameinfo(ctx: &mut RunnerContext, data: Vec<u8>) -> Result<(), Be
if let Ok(m) = std::fs::metadata(&loc) {
trace!("gameinfo metadata: {:#?}", m);
}
if let Err(e) = ctx.gameinfo_perms() {
error!("[helper::restore_gameinfo] Failed to update permissions on gameinfo.txt {:}", e);
sentry::capture_error(&e);
return Err(e);
}
if let Err(e) = std::fs::write(&loc, data) {
trace!("error: {:#?}", e);
error!("[UpdateWorkflow::wizard] Failed to write gameinfo.txt backup {:}", e);
error!("[helper::restore_gameinfo] Failed to write gameinfo.txt backup {:}", e);
}
if let Err(e) = ctx.gameinfo_perms() {
error!("[UpdateWorkflow::wizard] Failed to update permissions on gameinfo.txt {:}", e);
error!("[helper::restore_gameinfo] Failed to update permissions on gameinfo.txt {:}", e);
sentry::capture_error(&e);
return Err(e);
}
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(error_generic_member_access)]
#![feature(panic_info_message)]

use include_flate::flate;

Expand Down Expand Up @@ -53,3 +54,11 @@ pub const STAGING_DIR: &str = "\\butler-staging";
flate!(pub static BUTLER_BINARY: [u8] from "Binaries/butler.exe");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_BINARY: [u8] from "Binaries/butler");
#[cfg(target_os = "windows")]
flate!(pub static BUTLER_LIB_1: [u8] from "Binaries/7z.dll");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_LIB_1: [u8] from "Binaries/7z.so");
#[cfg(target_os = "windows")]
flate!(pub static BUTLER_LIB_2: [u8] from "Binaries/c7zip.dll");
#[cfg(not(target_os = "windows"))]
flate!(pub static BUTLER_LIB_2: [u8] from "Binaries/libc7zip.so");
3 changes: 1 addition & 2 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl CustomLogger {
sentry: sentry_log::SentryLogger::new().filter(|md| match md.level() {
log::Level::Error => LogFilter::Exception,
log::Level::Warn => LogFilter::Event,
log::Level::Info | log::Level::Debug => LogFilter::Breadcrumb,
log::Level::Trace => LogFilter::Ignore,
log::Level::Info | log::Level::Debug | log::Level::Trace => LogFilter::Breadcrumb,
})
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Trace;
pub const DEFAULT_LOG_LEVEL: LevelFilter = DEFAULT_LOG_LEVEL_RELEASE;

fn main() {
#[cfg(target_os = "windows")]
let _ = winconsole::window::show(true);
#[cfg(target_os = "windows")]
let _ = winconsole::console::set_title(format!("beans v{}", beans_rs::VERSION).as_str());

Expand Down
1 change: 1 addition & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub async fn get_version_list() -> Result<RemoteVersionResponse, BeansError>
}
};
let response_text = response.text().await?;
trace!("[version::get_version_list] response text: {}", response_text);
let data: RemoteVersionResponse = serde_json::from_str(&response_text)?;

return Ok(data);
Expand Down
2 changes: 1 addition & 1 deletion src/workflows/update.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{debug, error, info, trace};
use log::{debug, info};
use crate::{BeansError, butler, helper, RunnerContext};

pub struct UpdateWorkflow
Expand Down

0 comments on commit baf0519

Please sign in to comment.