Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub actions testing workflow #7

Merged
merged 12 commits into from
Feb 25, 2024
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test
on:
push:
branches:
- main
pull_request:
paths:
- '**.rs'
- '**/Cargo.*'
- '.github/workflows/**.yml'

jobs:
test:
name: Test
runs-on: arc-runner-set
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- run: ls /opt/test-data
- run: cargo fmt --all --check
- run: cargo test --workspace --all-features
- run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/target-*
/.idea
64 changes: 32 additions & 32 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
resolver = "2"
default-members = ["cli", "viewer"]
members = [
"format",
"cli",
Expand All @@ -8,5 +9,9 @@ members = [
"util",
]

[workspace.package]
version = "0.1.0"
license = "MIT AND Apache-2.0"

[workspace.dependencies.thiserror]
version = "1"
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "cli"
version = "0.1.0"
version.workspace = true
license.workspace = true
edition = "2021"

[dependencies]
Expand Down
30 changes: 15 additions & 15 deletions cli/src/bin/bdt-extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::{fs, io::Read, path::PathBuf};

use clap::Parser;
use indicatif::{ParallelProgressIterator, ProgressStyle};
use steamlocate::SteamDir;
use souls_vfs::{FileKeyProvider, Vfs};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use souls_vfs::{FileKeyProvider, Vfs};
use steamlocate::SteamDir;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand All @@ -20,8 +20,7 @@ struct Args {
const ER_APPID: u32 = 1245620;

fn locate_er_dir() -> PathBuf {
let mut steamdir = SteamDir::locate()
.expect("steam installation not found");
let mut steamdir = SteamDir::locate().expect("steam installation not found");

match steamdir.app(&ER_APPID) {
Some(app) => app.path.join("Game"),
Expand All @@ -32,8 +31,7 @@ fn locate_er_dir() -> PathBuf {
fn main() -> Result<(), std::io::Error> {
let args = Args::parse();

let er_path = args.erpath
.unwrap_or_else(locate_er_dir);
let er_path = args.erpath.unwrap_or_else(locate_er_dir);

let keys = FileKeyProvider::new("keys");
let archives = [
Expand All @@ -44,37 +42,39 @@ fn main() -> Result<(), std::io::Error> {
er_path.join("sd/sd"),
];

let vfs = Vfs::create(archives.clone(), &keys)
.expect("unable to create vfs");
let vfs = Vfs::create(archives.clone(), &keys).expect("unable to create vfs");

let dictionary = std::fs::read_to_string(args.dictionary)?;
let lines = dictionary.lines()
.map(|l| std::path::PathBuf::from(l))
let lines = dictionary
.lines()
.map(std::path::PathBuf::from)
.collect::<Vec<_>>();

let style = ProgressStyle::with_template("[{elapsed_precise}] {bar:40} {pos:>7}/{len:7} {msg}")
.expect("Could not create progress bar style");

lines.par_iter()
lines
.par_iter()
.progress_with_style(style)
.filter(|l| !l.to_str().unwrap().starts_with("#") && !l.to_str().unwrap().is_empty())
.filter(|l| !l.to_str().unwrap().starts_with('#') && !l.to_str().unwrap().is_empty())
.for_each(|l| {
let path = l.to_str().unwrap();

match vfs.open(path) {
Ok(mut entry) => {
let mut buffer = Vec::new();
entry.read_to_end(&mut buffer)
entry
.read_to_end(&mut buffer)
.expect("Could not read from vfs to file buffer");

let output_path = std::path::PathBuf::from(format!("./extract/{}", path));
let directory = output_path.parent().unwrap();
fs::create_dir_all(directory).unwrap();
fs::write(output_path, buffer).unwrap();
},
}
Err(_) => {
// println!("Got error while extracting {} - {:?}", path, e);
},
}
}
});

Expand Down
6 changes: 2 additions & 4 deletions cli/src/bin/dcx-extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ fn main() -> Result<(), std::io::Error> {
let path = std::path::PathBuf::from(args.file);

let mut dcx_file = std::fs::File::open(&path)?;
let dcx = DCX::from_reader(&mut dcx_file)
.expect("Could not parse DCX");
let dcx = DCX::from_reader(&mut dcx_file).expect("Could not parse DCX");

let mut cursor = std::io::Cursor::new(dcx.decompressed);
let bnd4 = BND4::from_reader(&mut cursor)?;
Expand All @@ -29,8 +28,7 @@ fn main() -> Result<(), std::io::Error> {

for entry in bnd4.files.iter() {
let trimmed_path = entry.path.replace("N:\\", "").replace('\\', "/");
let output_path = std::path::PathBuf::from(folder.clone())
.join(trimmed_path.as_str());
let output_path = std::path::PathBuf::from(folder.clone()).join(trimmed_path.as_str());

let parent = output_path.parent().unwrap();
std::fs::create_dir_all(parent)?;
Expand Down
3 changes: 2 additions & 1 deletion format/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "format"
version = "0.1.0"
version.workspace = true
license.workspace = true
edition = "2021"
build = "build.rs"

Expand Down
8 changes: 4 additions & 4 deletions format/src/bhd.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{
io::{Cursor, Read, Seek, SeekFrom},
mem::{MaybeUninit, transmute},
mem::{transmute, MaybeUninit},
};

use byteorder::{BigEndian, ByteOrder, LittleEndian, ReadBytesExt};
use rayon::{iter::ParallelIterator, prelude::*};
use rsa::{pkcs1::DecodeRsaPublicKey, RsaPublicKey, traits::PublicKeyParts};
use rug::{Integer, integer::Order};
use rayon::prelude::*;
use rsa::{pkcs1::DecodeRsaPublicKey, traits::PublicKeyParts, RsaPublicKey};
use rug::{integer::Order, Integer};

use crate::io_ext::ReadFormatsExt;

Expand Down
16 changes: 6 additions & 10 deletions format/src/bnd4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{self, Read, Seek, SeekFrom};

use byteorder::{ReadBytesExt, LE};

use crate::io_ext::ReadFormatsExt;
Expand Down Expand Up @@ -86,20 +87,15 @@ impl BND4 {
pub fn file_descriptor_by_stem(&self, path: &str) -> Option<&BND4Entry> {
let lookup = std::path::PathBuf::from(Self::normalize_path(path));

self.files.iter()
.find(|f| {
let path = std::path::PathBuf::from(
Self::normalize_path(&f.path)
);
self.files.iter().find(|f| {
let path = std::path::PathBuf::from(Self::normalize_path(&f.path));

path.file_stem() == lookup.file_stem()
})
path.file_stem() == lookup.file_stem()
})
}

pub fn normalize_path(path: &str) -> String {
path.replace("N:\\", "")
.to_lowercase()
.replace('\\', "/")
path.replace("N:\\", "").to_lowercase().replace('\\', "/")
}
}

Expand Down
Loading