Skip to content

Commit

Permalink
per addon config
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 7, 2023
1 parent 3addaa3 commit 15757f8
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 72 deletions.
86 changes: 38 additions & 48 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[workspace]
members = [
"bin/app",
"bin/libs/config",
"bin/libs/error",
"bin/libs/internal",
"bin/libs/project",

"libs/config",
"libs/error",
Expand All @@ -16,8 +16,8 @@ members = [
]

[workspace.dependencies]
pest = "2.5.1"
pest_derive = "2.5.1"
pest = "2.5.2"
pest_derive = "2.5.2"
clap = "4.0.32"
serde = { version = "1.0.151", features = ["derive"] }
serde = { version = "1.0.152", features = ["derive"] }
sha-1 = "0.10.1"
4 changes: 2 additions & 2 deletions bin/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hemtt-error = { path = "../../libs/error" }
hemtt-bin-error = { path = "../libs/error"}

hemtt-bin-internal = { path = "../libs/internal" }
hemtt-bin-project = { path = "../libs/project" }
hemtt-bin-config = { path = "../libs/config" }

hemtt-config = { path = "../../libs/config" }
hemtt-pbo = { path = "../../libs/pbo" }
Expand All @@ -23,7 +23,7 @@ clap = { workspace = true }
dialoguer = "0.10.2"
fs_extra = "1.2.0"
git2 = "0.15.0"
glob = "0.3.0"
glob = "0.3.1"
lazy_static = "1.4.0"
peekmore = "1.0.0"
rayon = "1.6.1"
Expand Down
24 changes: 21 additions & 3 deletions bin/app/src/addons.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
use std::{fs::DirEntry, path::PathBuf, str::FromStr};

use hemtt_bin_config::addon::Configuration;
use hemtt_bin_error::Error;

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone)]
pub struct Addon {
name: String,
location: Location,
config: Option<Configuration>,
}

impl Addon {
pub const fn new(name: String, location: Location) -> Self {
Self { name, location }
pub fn new(name: String, location: Location) -> Self {
Self {
config: {
let path =
PathBuf::from(format!("{}/{}", location.to_string(), name)).join("hemtt.toml");
if path.exists() {
Some(Configuration::from_file(&path).unwrap())
} else {
None
}
},
location,
name,
}
}

pub fn name(&self) -> &str {
Expand All @@ -29,6 +43,10 @@ impl Addon {
format!("{}/{}", self.location.to_string(), self.name)
}

pub const fn config(&self) -> Option<&Configuration> {
self.config.as_ref()
}

pub fn scan() -> Result<Vec<Self>, Error> {
let mut addons = Vec::new();
for location in [Location::Addons, Location::Optionals] {
Expand Down
2 changes: 1 addition & 1 deletion bin/app/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{ArgMatches, Command, ArgAction};
use clap::{ArgAction, ArgMatches, Command};
use hemtt_bin_error::Error;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion bin/app/src/commands/launch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::Path;

use clap::{ArgMatches, Command};
use hemtt_bin_config::project::Configuration;
use hemtt_bin_error::Error;
use hemtt_bin_project::config::Configuration;
use steamlocate::SteamDir;

use crate::utils::create_link;
Expand Down
2 changes: 1 addition & 1 deletion bin/app/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
path::{Path, PathBuf},
};

use hemtt_bin_config::project::Configuration;
use hemtt_bin_error::Error;
use hemtt_bin_project::config::Configuration;
use vfs::{AltrootFS, MemoryFS, OverlayFS, PhysicalFS, VfsPath};

use crate::addons::Addon;
Expand Down
17 changes: 17 additions & 0 deletions bin/app/src/modules/binarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ impl Module for Binarize {
if entry.metadata().unwrap().file_type == VfsFileType::File
&& ["rtm", "p3d"].contains(&entry.extension().unwrap_or_default().as_str())
{
if let Some(config) = addon.config() {
if config
.no_bin(&addon.folder())?
.contains(&PathBuf::from(entry.as_str().trim_start_matches('/')))
{
println!("skipping binarization of {}", entry.as_str());
continue;
}
}

// skip OLOD & BMTR files as they are already binarized
let mut buf = [0; 4];
entry.open_file().unwrap().read_exact(&mut buf).unwrap();
if buf == [0x4F, 0x4C, 0x4F, 0x44] || buf == [0x42, 0x4D, 0x54, 0x52] {
continue;
}

let addon_root = PathBuf::from(entry.as_str())
.components()
.take(3)
Expand Down
11 changes: 9 additions & 2 deletions bin/app/src/modules/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ impl Module for Preprocessor {
fn pre_build(&self, ctx: &Context) -> Result<(), Error> {
let resolver = VfsResolver::new(ctx)?;
// TODO map to extra error
// TODO ^ remember what that means
ctx.addons()
.par_iter()
.map(|addon| {
// TODO fix error in vfs
for entry in ctx.vfs().join(addon.folder())?.walk_dir()? {
let entry = entry?;
if entry.metadata()?.file_type == VfsFileType::File
&& can_preprocess(entry.as_str())
{
if entry.filename() == "config.cpp" {
if let Some(config) = addon.config() {
if !config.preprocess() {
println!("skiping {}", entry.as_str());
continue;
}
}
}
println!("preprocessing {}", entry.as_str());
preprocess(entry.clone(), ctx, &resolver)?;
println!("done {}", entry.as_str());
}
}
Ok(())
Expand Down
Loading

0 comments on commit 15757f8

Please sign in to comment.