Skip to content

Commit

Permalink
fix: update NorthstarProton url
Browse files Browse the repository at this point in the history
  • Loading branch information
AnActualEmerald committed Apr 18, 2024
1 parent 3cd219b commit 5247a6a
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose --features all

coverage:
name: Coverage
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
description = "Crate for managing Northstar mods"
license = "MIT"
repository = "https://forge.greenboi.me/Emerald/thermite"
exclude = ["commands/", "*.zip"]
exclude = ["commands/", "*.zip" , "*.tar.gz"]

[workspace]
members = ["xtask"]
Expand Down Expand Up @@ -35,6 +35,7 @@ zip = { default-features = false, version = "^0.6", features = ["deflate"] }
default = []
steam = ["steamlocate"]
proton = ["tar", "flate2"]
all = ["steam", "proton"]

[dev-dependencies]
indicatif = "0.17.3"
Expand Down
39 changes: 39 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";

fenix-flake = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
flake-utils,
fenix-flake,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
Expand All @@ -18,7 +24,16 @@

devShells.default = pkgs.mkShell {
nativeBuildInputs = [pkgs.rustc];
packages = with pkgs; [cargo git-cliff];
packages = with pkgs; [cargo git-cliff rust-analyzer clippy];
};

devShells.coverage = let pkgs = import nixpkgs{ inherit system; overlays = [fenix-flake.overlays.default]; }; in pkgs.mkShell {
nativeBuildInputs = [pkgs.rustc];
packages = with pkgs; [ grcov (fenix.complete.withComponents [
"cargo"
"rustc"
"llvm-tools-preview"
])];
};
});
}
2 changes: 1 addition & 1 deletion src/core/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn download(output: impl Write, url: impl AsRef<str>) -> Result<u64> {
download_with_progress(output, url, |_, _, _| {})
}

#[deprecated(since = "0.7.1")]
#[deprecated(since = "0.7.1", note = "just use std::fs directly")]
pub fn uninstall(mods: &[impl AsRef<Path>]) -> Result<()> {
for p in mods {
if fs::remove_dir_all(p).is_err() {
Expand Down
Binary file added src/core/test_media/NorthstarProton8-28.tar.gz
Binary file not shown.
54 changes: 47 additions & 7 deletions src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,47 +305,87 @@ pub(crate) mod steam {
//#[deprecated(since = "0.8.0", note = "Northstar Proton is no longer required")]
pub(crate) mod proton {
use flate2::read::GzDecoder;
use std::{fs::File, io::Write, path::Path};
use std::{io::{Read, Write}, path::Path};
use tar::Archive;
use tracing::debug;

use crate::{
core::manage::download,
error::{Result, ThermiteError},
};
const BASE_URL: &str = "https://github.com/cyrv6737/NorthstarProton/releases/";
const BASE_URL: &str = "https://github.com/R2NorthstarTools/NorthstarProton/releases/";

/// Returns the latest tag from the NorthstarProton repo
///
/// # Errors
/// * Network error
/// * Unexpected URL format
pub fn latest_release() -> Result<String> {
let url = format!("{}latest", BASE_URL);
let res = ureq::get(&url).call()?;
debug!("{:#?}", res);
let location = res.get_url();
debug!("{url} redirected to {location}");

Ok(location
.split('/')
.last()
.ok_or_else(|| ThermiteError::UnknownError("Malformed location URL".into()))?
.to_owned())
}
/// Convinience function for downloading a given tag from the NorthstarProton repo

/// Convinience function for downloading a given tag from the NorthstarProton repo.
/// If you have a URL already, just use `thermite::manage::download`
pub fn download_ns_proton(tag: impl AsRef<str>, output: impl Write) -> Result<u64> {
let url = format!(
"{}download/{}/NorthstarProton-{}.tar.gz",
"{}download/{}/NorthstarProton{}.tar.gz",
BASE_URL,
tag.as_ref(),
tag.as_ref().trim_matches('v')
);
download(output, url)
}

/// Extract the NorthstarProton tarball into a given directory
pub fn install_ns_proton(archive: &File, dest: impl AsRef<Path>) -> Result<()> {
/// Extract the NorthstarProton tarball into a given directory.
/// Only supports extracting to a filesystem path.
///
/// # Errors
/// * IO errors
pub fn install_ns_proton(archive: impl Read, dest: impl AsRef<Path>) -> Result<()> {
let mut tarball = Archive::new(GzDecoder::new(archive));
tarball.unpack(dest)?;

Ok(())
}

#[cfg(test)]
mod test {
use std::io::Cursor;

use crate::core::utils::TempDir;

use super::latest_release;


#[test]
fn get_latest_proton_version() {
let res = latest_release();
assert!(res.is_ok());

}

#[test]
fn extract_proton() {
let dir = TempDir::create(std::env::temp_dir().join("NSPROTON_TEST")).expect("temp dir");
let archive = include_bytes!("test_media/NorthstarProton8-28.tar.gz");
let cursor = Cursor::new(archive);
let res = super::install_ns_proton(cursor, &dir);
assert!(res.is_ok());

let extracted = dir.join("NorthstarProton8-28.txt");
assert!(extracted.exists());
assert_eq!(std::fs::read_to_string(extracted).expect("read file"), "The real proton was too big to use as test media\n");
}
}
}

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ pub mod core;
pub mod error;
pub mod model;

/// The names of the Northstar core mods as found in their `mod.json` files, all lowercase
pub const CORE_MODS: [&str; 3] = [
"northstar.custom",
"northstar.customservers",
"northstar.client",
];

/// Titanfall 2's Steam appid
pub const TITANFALL2_STEAM_ID: u32 = 1237970;
/// Titanfall 2's Origin/EA App ids
pub const TITANFALL2_ORIGIN_IDS: [&str; 2] = ["Origin.OFR.50.0001452", "Origin.OFR.50.0001456"];

// Important functions and structs
Expand All @@ -35,8 +38,6 @@ pub mod prelude {
download, download_with_progress, install_mod, install_northstar, install_with_sanity,
};

#[allow(deprecated)]
pub use crate::core::manage::uninstall;
pub use crate::core::utils::{find_mods, get_enabled_mods, resolve_deps};
#[cfg(all(target_os = "linux", feature = "proton"))]
pub use crate::core::{download_ns_proton, install_ns_proton, latest_release};
Expand Down

0 comments on commit 5247a6a

Please sign in to comment.