Skip to content

Commit

Permalink
Merge pull request #23 from ktwrd/develop
Browse files Browse the repository at this point in the history
v1.5.1
  • Loading branch information
ktwrd authored Jul 11, 2024
2 parents e7611d4 + faecdcb commit 71998f2
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 29 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,35 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-20.04
filename: 'beans-rs'
target: x86_64-unknown-linux-musl
- os: windows-latest
target: x86_64-pc-windows-msvc
filename: 'beans-rs.exe'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose

- name: Install Build Dependencies (ubuntu)
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
sudo apt-get update;
sudo apt-get install -y \
libssl-dev \
musl-tools
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-05-24
target: ${{ matrix.target }}

- uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --all-features --target ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ matrix.target }}
path: target/${{ matrix.target }}/debug/${{ matrix.filename }}
24 changes: 20 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,39 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-20.04
filename: 'beans-rs'
target: x86_64-unknown-linux-musl

- os: windows-latest
target: x86_64-pc-windows-msvc
filename: 'beans-rs.exe'

steps:
- uses: actions/checkout@master

- name: Install Build Dependencies (ubuntu)
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
sudo apt-get update;
sudo apt-get install -y \
libssl-dev \
musl-tools
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly-2024-05-24
target: ${{ matrix.target }}

- uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-features
args: --release --all-features --target ${{ matrix.target }}

- name: Upload binaries to release
uses: softprops/action-gh-release@v1
with:
files: target/release/${{ matrix.filename }}
files: target/${{ matrix.target }}/release/${{ matrix.filename }}
tag_name: ${{ github.event.inputs.tag }}
draft: false
prerelease: true
Expand Down
25 changes: 22 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "beans-rs"
version = "1.4.5"
version = "1.5.1"
edition = "2021"
authors = [
"Kate Ward <[email protected]>"
Expand Down Expand Up @@ -30,7 +30,6 @@ clap = { version = "4.5.4", features = ["cargo"] }
bitflags = "2.5.0"
log = "0.4.21"
native-dialog = "0.7.0"
sentry = "0.34.0"
lazy_static = "1.4.0"
thread-id = "4.2.1"
colored = "2.1.0"
Expand All @@ -42,6 +41,20 @@ winconsole = { version = "0.11.1", features = ["window"] }
winreg = "0.52.0"
dunce = "1.0.4"

[dependencies.sentry]
version = "0.34.0"
default-features = false
features = [
"backtrace",
"contexts",
"debug-images",
"panic",

"reqwest",
"rustls"
]


[dependencies.tokio]
version = "1.37.0"
features = [
Expand All @@ -54,8 +67,14 @@ version = "0.12.4"
features = [
"multipart",
"stream",
"json"
"json",

"rustls-tls",
"charset",
"http2",
"macos-system-configuration"
]
default-features = false

[target.'cfg(target_os = "windows")'.build-dependencies]
winres = "0.1.12"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is a complete rewrite of the original [beans](https://github.com/int-72h/of

`beans-rs` is licensed under `GPLv3-only`, so please respect it!

**Note** Releases for Linux v1.5.0 and later are built with Ubuntu 20.04 (using `libssl v1.1`)

## Developing
Requirements
- Rust Toolchain (nightly, only for building)
Expand Down
11 changes: 11 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pub enum BeansError
location: String,
error: std::io::Error
},
#[error("Failed to create directory {location} ({error:})")]
DirectoryCreateFailure {
location: String,
error: std::io::Error
},
#[error("Failed to extract {src_file} to directory {target_dir} ({error:})")]
TarExtractFailure {
src_file: String,
Expand Down Expand Up @@ -154,6 +159,12 @@ pub enum BeansError
#[error("Failed to backup gameinfo.txt, {reason:}")]
GameinfoBackupFailure {
reason: GameinfoBackupFailureReason
},

#[error("Failed to remove files in {location} ({error:})")]
CleanTempFailure {
location: String,
error: std::io::Error
}
}
#[derive(Debug)]
Expand Down
109 changes: 102 additions & 7 deletions src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{BeansError, DownloadFailureReason, GameinfoBackupCreateDirectoryFail
use rand::{distributions::Alphanumeric, Rng};
use reqwest::header::USER_AGENT;
use crate::appvar::AppVarData;
use std::collections::HashMap;

#[derive(Clone, Debug)]
pub enum InstallType
Expand Down Expand Up @@ -127,6 +128,11 @@ pub fn file_exists(location: String) -> bool
{
std::path::Path::new(&location).exists()
}
/// Check if the location provided exists and it's a directory.
pub fn dir_exists(location: String) -> bool
{
file_exists(location.clone()) && is_directory(location.clone())
}
pub fn is_directory(location: String) -> bool
{
let x = PathBuf::from(&location);
Expand Down Expand Up @@ -164,6 +170,16 @@ pub fn join_path(tail: String, head: String) -> String

format!("{}{}", format_directory_path(tail), h)
}
pub fn remove_path_head(location: String) -> String
{
let p = std::path::Path::new(&location);
if let Some(x) = p.parent() {
if let Some(m) = x.to_str() {
return m.to_string();
}
}
return String::new();
}
/// Make sure that the location provided is formatted as a directory (ends with `crate::PATH_SEP`).
pub fn format_directory_path(location: String) -> String
{
Expand Down Expand Up @@ -226,17 +242,25 @@ pub fn parse_location(location: String) -> String
/// Get the amount of free space on the drive in the location provided.
pub fn get_free_space(location: String) -> Result<u64, BeansError>
{
let real_location = parse_location(location);
let mut data: HashMap<String, u64> = HashMap::new();
for disk in sysinfo::Disks::new_with_refreshed_list().list() {
if let Some(mp) = disk.mount_point().to_str() {
if real_location.clone().starts_with(&mp) {
return Ok(disk.available_space())
}
debug!("[get_free_space] space: {} {}", mp, disk.available_space());
data.insert(mp.to_string(), disk.available_space());
}
}

let mut l = parse_location(location.clone());
while l.len() >= 2 {
debug!("[get_free_space] Checking if {} is in data", l);
if let Some(x) = data.get(&l) {
return Ok(x.clone());
}
l = remove_path_head(l.clone());
}

Err(BeansError::FreeSpaceCheckFailure {
location: real_location
location: parse_location(location.clone())
})
}
/// Check if the location provided has enough free space.
Expand Down Expand Up @@ -356,17 +380,42 @@ pub fn format_size(i: usize) -> String {
pub fn get_tmp_dir() -> String
{
let mut dir = std::env::temp_dir().to_str().unwrap_or("").to_string();
if cfg!(target_os = "android") {
if is_steamdeck() {
trace!("[helper::get_tmp_dir] Detected that we are running on a steam deck. Using ~/.tmp/beans-rs");
match simple_home_dir::home_dir() {
Some(v) => {
match v.to_str() {
Some(k) => {
dir = format_directory_path(k.to_string());
dir = join_path(dir, String::from(".tmp"));
},
None => {
trace!("[helper::get_tmp_dir] Failed to convert PathBuf to &str");
}
}
},
None => {
trace!("[helper::get_tmp_dir] Failed to get home directory.");
}
};
} else 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);
if !dir_exists(dir.clone()) {
if let Err(e) = std::fs::create_dir(&dir) {
trace!("[helper::get_tmp_dir] {:#?}", e);
warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e);
}
}
dir = join_path(dir, String::from("beans-rs"));
dir = format_directory_path(dir);

if !file_exists(dir.clone()) {
if !dir_exists(dir.clone()) {
if let Err(e) = std::fs::create_dir(&dir) {
trace!("[helper::get_tmp_dir] {:#?}", e);
warn!("[helper::get_tmp_dir] failed to make tmp directory at {} ({:})", dir, e);
sentry::capture_error(&e);
} else {
Expand All @@ -376,6 +425,52 @@ pub fn get_tmp_dir() -> String

return dir;
}
/// Check if the content of `uname -r` contains `valve` (Linux Only)
///
/// ## Returns
/// - `true` when;
/// - The output of `uname -r` contains `valve`
/// - `false` when;
/// - `target_os` is not `linux`
/// - Failed to run `uname -r`
/// - Failed to parse the stdout of `uname -r` as a String.
///
/// ## Note
/// Will always return `false` when `cfg!(not(target_os = "linux"))`.
///
/// This function will write to `log::trace` with the full error details before writing it to `log::warn` or `log::error`. Since errors from this
/// aren't significant, `sentry::capture_error` will not be called.
pub fn is_steamdeck() -> bool {
if cfg!(not(target_os = "linux")) {
return false;
}

match std::process::Command::new("uname").arg("-r").output() {
Ok(cmd) => {
trace!("[helper::is_steamdeck] exit status: {}", &cmd.status);
let stdout = &cmd.stdout.to_vec();
let stderr = &cmd.stderr.to_vec();
if let Ok(x) = String::from_utf8(stderr.clone()) {
trace!("[helper::is_steamdeck] stderr: {}", x);
}
match String::from_utf8(stdout.clone()) {
Ok(x) => {
trace!("[helper::is_steamdeck] stdout: {}", x);
x.contains("valve")
},
Err(e) => {
trace!("[helper::is_steamdeck] Failed to parse as utf8 {:#?}", e);
false
}
}
},
Err(e) => {
trace!("[helper::is_steamdeck] {:#?}", e);
warn!("[helper::is_steamdeck] Failed to detect {:}", e);
return false;
}
}
}
/// Generate a full file location for a temporary file.
pub fn get_tmp_file(filename: String) -> String
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub const PANIC_MSG_CONTENT: &str = include_str!("text/msgbox_panic_text.txt");
///
/// just like the `pause` thing in batch.
pub static mut PAUSE_ONCE_DONE: bool = false;
/// When `true`, everything that prompts the user for Y/N should use the default option.
pub static mut PROMPT_DO_WHATEVER: bool = false;


// ------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 71998f2

Please sign in to comment.