Skip to content

Commit

Permalink
headers -> properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 19, 2023
1 parent 58c7777 commit 060e2bd
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 53 deletions.
1 change: 0 additions & 1 deletion bin/app/src/modules/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn scope(ctx: &Context, vfs: bool) -> Result<Scope, Error> {
}
scope.push_constant("HEMTT_PROJECT_NAME", ctx.config().name().to_string());
scope.push_constant("HEMTT_PROJECT_PREFIX", ctx.config().prefix().to_string());
scope.push_constant("HEMTT_PROJECT_HEADERS", ctx.config().headers().clone());
scope.push_constant("HEMTT_ADDONS", ctx.addons().to_vec());
if vfs {
scope.push_constant("HEMTT_VFS", ctx.vfs().clone());
Expand Down
4 changes: 2 additions & 2 deletions bin/app/src/modules/pbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ pub fn build(ctx: &Context, collapse: Collapse) -> Result<(), Error> {
pbo.add_file(file, entry.open_file().unwrap()).unwrap();
}
}
for header in ctx.config().headers() {
for header in ctx.config().properties() {
pbo.add_extension(header.0, header.1.clone());
}
if let Some(config) = addon.config() {
for header in config.headers() {
for header in config.properties() {
pbo.add_extension(header.0, header.1.clone());
}
}
Expand Down
10 changes: 5 additions & 5 deletions bin/libs/config/src/addon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct Configuration {
no_bin: Vec<String>,

#[serde(default)]
/// Headers to add to the pbo
headers: HashMap<String, String>,
/// Properties to add to the pbo
properties: HashMap<String, String>,

#[serde(default)]
/// Files to exclude from the pbo
Expand Down Expand Up @@ -65,9 +65,9 @@ impl Configuration {
}

#[must_use]
/// Headers to be added to the built PBO
pub const fn headers(&self) -> &HashMap<String, String> {
&self.headers
/// Properties to be added to the built PBO
pub const fn properties(&self) -> &HashMap<String, String> {
&self.properties
}

#[must_use]
Expand Down
10 changes: 5 additions & 5 deletions bin/libs/config/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct Configuration {
version: version::Options,

#[serde(default)]
/// Headers to be added to built PBOs
headers: HashMap<String, String>,
/// Properties to be added to built PBOs
properties: HashMap<String, String>,

#[serde(default)]
/// Files to be included in the root of the project, supports glob patterns
Expand Down Expand Up @@ -62,9 +62,9 @@ impl Configuration {
}

#[must_use]
/// Headers to be added to built PBOs
pub const fn headers(&self) -> &HashMap<String, String> {
&self.headers
/// Properties to be added to built PBOs
pub const fn properties(&self) -> &HashMap<String, String> {
&self.properties
}

#[must_use]
Expand Down
8 changes: 4 additions & 4 deletions book/configuration-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = [
"data/*.psd",
]

[headers]
[properties]
iso = "14001"
```

Expand Down Expand Up @@ -57,13 +57,13 @@ exclude = [
]
```

## headers
## properties

Much like the `headers` key in `.hemtt/project.toml`, the `headers` key in `addon.toml` allows you to add custom headers to the PBO.
Much like the `properties` key in `.hemtt/project.toml`, the `properties` key in `addon.toml` allows you to add custom properties to the PBO.

***/addons/banana/addon.toml***

```toml
[headers]
[properties]
iso = "14001"
```
10 changes: 5 additions & 5 deletions book/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exclude = [
]
```

#### Include
#### include

By default, those 5 files are included in the build directory if they exist in the root of your project. You do not need to add them to your list. Additon files or [glob path](https://en.wikipedia.org/wiki/Glob_(programming)) can be added to the list.

Expand All @@ -81,7 +81,7 @@ include = [
]
```

#### Exclude
#### exclude

By default, no files are excluded from PBOs. You can add files or [glob path](https://en.wikipedia.org/wiki/Glob_(programming)) to the list.

Expand All @@ -95,14 +95,14 @@ exclude = [
]
```

### Headers
### properties

You can add a list of headers to be added to every PBO.
You can add a list of properties to be added to every PBO.

**.hemtt/project.toml**

```toml
[headers]
[properties]
author = "ABE Team"
url = "https://github.com/ABE-Mod/ABE"
```
1 change: 0 additions & 1 deletion book/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Several constants are available to the hook scripts. These are:
| `HEMTT_PROJECT_VERSION_HASBUILD` | Whether the project has a build, ex: true |
| `HEMTT_PROJECT_NAME` | The name of the project |
| `HEMTT_PROJECT_PREFIX` | The prefix of the project |
| `HEMTT_PROJECT_HEADERS` | The headers of the project |
| `HEMTT_PROJECT_ADDONS` | The addons of the project |

## File System
Expand Down
2 changes: 1 addition & 1 deletion libs/pbo/src/model/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ReadPbo;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
/// A checksum found at the end of a PBO
///
/// The checksum is a SHA1 hash of the PBO's extensions & files
/// The checksum is a SHA1 hash of the PBO's properties & files
pub struct Checksum([u8; 20]);

impl Checksum {
Expand Down
2 changes: 1 addition & 1 deletion libs/pbo/src/model/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Mime {
/// A compressed entry used by VBS
Enco,
#[default]
/// A blank entry, use to denote the end of the extensions section
/// A blank entry, use to denote the end of the properties section
Blank,
}

Expand Down
2 changes: 1 addition & 1 deletion libs/pbo/src/prefix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A prefix file for a PBO
//!
//! It can be a single line defining the prefix, or a key-value pair defining the prefix and extra headers
//! It can be a single line defining the prefix, or a key-value pair defining the prefix and extra properties
//!
//! # Examples
//!
Expand Down
18 changes: 9 additions & 9 deletions libs/pbo/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{

/// An existing PBO file that can be read from
pub struct ReadablePbo<I: Seek + Read> {
extensions: IndexMap<String, String>,
properties: IndexMap<String, String>,
headers: Vec<Header>,
checksum: Checksum,
input: I,
Expand All @@ -27,7 +27,7 @@ impl<I: Seek + Read> ReadablePbo<I> {
/// # Errors
/// if the file cannot be read
pub fn from(mut input: I) -> Result<Self, Error> {
let mut extensions = IndexMap::new();
let mut properties = IndexMap::new();
let mut headers = Vec::new();
let mut blob_start = 0;
loop {
Expand All @@ -42,7 +42,7 @@ impl<I: Seek + Read> ReadablePbo<I> {
}
let value = input.read_cstring()?;
blob_start += value.len() as u64 + 1;
extensions.insert(key, value);
properties.insert(key, value);
}
} else if header.filename().is_empty() {
break;
Expand All @@ -61,7 +61,7 @@ impl<I: Seek + Read> ReadablePbo<I> {
return Err(Error::UnexpectedDataAfterChecksum);
}
Ok(Self {
extensions,
properties,
headers,
checksum,
input,
Expand All @@ -76,9 +76,9 @@ impl<I: Seek + Read> ReadablePbo<I> {
.find(|h| h.filename() == name.replace('/', "\\"))
}

/// Get the PBO's extensions
pub const fn extensions(&self) -> &IndexMap<String, String> {
&self.extensions
/// Get the PBO's properties
pub const fn properties(&self) -> &IndexMap<String, String> {
&self.properties
}

/// Get the PBO's stored checksum
Expand Down Expand Up @@ -156,12 +156,12 @@ impl<I: Seek + Read> ReadablePbo<I> {
let mut headers: Cursor<Vec<u8>> = Cursor::new(Vec::new());
Header::ext().write_pbo(&mut headers)?;

if let Some(prefix) = self.extensions.get("prefix") {
if let Some(prefix) = self.properties.get("prefix") {
headers.write_cstring(b"prefix")?;
headers.write_cstring(prefix)?;
}

for (key, value) in &self.extensions {
for (key, value) in &self.properties {
if key == "prefix" {
continue;
}
Expand Down
22 changes: 11 additions & 11 deletions libs/pbo/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{error::Error, model::Header, WritePbo};
#[derive(Default)]
/// A PBO file that can be written to
pub struct WritablePbo<I: Seek + Read> {
extensions: IndexMap<String, String>,
properties: IndexMap<String, String>,
files: HashMap<String, (I, Header)>,
}

Expand All @@ -21,7 +21,7 @@ impl<I: Seek + Read> WritablePbo<I> {
/// Create a new PBO
pub fn new() -> Self {
Self {
extensions: IndexMap::new(),
properties: IndexMap::new(),
files: HashMap::new(),
}
}
Expand Down Expand Up @@ -99,25 +99,25 @@ impl<I: Seek + Read> WritablePbo<I> {
key: K,
value: V,
) -> Option<String> {
self.extensions
self.properties
.insert(key.into(), value.into().trim_matches('\\').to_string())
}

/// Remove an extension from the PBO
pub fn remove_extension(&mut self, key: &str) -> Option<String> {
self.extensions.remove(key)
self.properties.remove(key)
}

#[must_use]
/// Get an extension from the PBO
pub fn extension(&self, key: &str) -> Option<&String> {
self.extensions.get(key)
self.properties.get(key)
}

#[must_use]
/// Get all extensions from the PBO
pub const fn extensions(&self) -> &IndexMap<String, String> {
&self.extensions
/// Get all properties from the PBO
pub const fn properties(&self) -> &IndexMap<String, String> {
&self.properties
}

/// Write the PBO to a file
Expand All @@ -127,17 +127,17 @@ impl<I: Seek + Read> WritablePbo<I> {
///
/// # Panics
/// if a file does not exist but a header is present
pub fn write<O: Write>(&mut self, output: &mut O, extensions: bool) -> Result<(), Error> {
pub fn write<O: Write>(&mut self, output: &mut O, properties: bool) -> Result<(), Error> {
let mut headers: Cursor<Vec<u8>> = Cursor::new(Vec::new());
if extensions {
if properties {
Header::ext().write_pbo(&mut headers)?;

if let Some(prefix) = self.extension("prefix") {
headers.write_cstring(b"prefix")?;
headers.write_cstring(prefix)?;
}

for (key, value) in &self.extensions {
for (key, value) in &self.properties {
if key == "prefix" {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/pbo/tests/ace_weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn ace_weather_cba6f72c() {
)
.unwrap();
}
for ext in pbo.extensions() {
for ext in pbo.properties() {
new_pbo.add_extension(ext.0, ext.1);
}
let mut new_pbo_bin = std::io::Cursor::new(Vec::new());
Expand Down
8 changes: 4 additions & 4 deletions libs/pbo/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub fn pbo(
) -> ReadablePbo<File> {
let mut pbo = ReadablePbo::from(file).unwrap();
assert_eq!(pbo.files().len(), file_count);
assert_eq!(pbo.extensions().len(), extension_count);
assert_eq!(pbo.properties().len(), extension_count);
assert_eq!(pbo.is_sorted().is_ok(), sorted);
assert_eq!(pbo.extensions().get("version"), Some(&version.to_string()));
assert_eq!(pbo.extensions().get("prefix"), Some(&prefix.to_string()));
assert_eq!(pbo.properties().get("version"), Some(&version.to_string()));
assert_eq!(pbo.properties().get("prefix"), Some(&prefix.to_string()));
assert!(pbo.file("not_real").unwrap().is_none());
assert!(pbo.header("not_real").is_none());
if sorted {
Expand All @@ -33,7 +33,7 @@ pub fn pbo(
// let original = ReadablePbo::from(file).unwrap();

// assert_eq!(original.files(), writeable.files_sorted().unwrap());
// assert_eq!(original.extensions(), writeable.extensions());
// assert_eq!(original.properties(), writeable.properties());
// assert_eq!(original.checksum(), writeable.checksum().unwrap());
// }

Expand Down
4 changes: 2 additions & 2 deletions libs/signing/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn generate_hashes<I: Seek + Read>(

hasher.update(hash1.as_bytes());
hasher.update(pbo.hash_filenames()?);
if let Some(prefix) = pbo.extensions().get("prefix") {
if let Some(prefix) = pbo.properties().get("prefix") {
hasher.update(prefix.as_bytes());
if !prefix.ends_with('\\') {
hasher.update(b"\\");
Expand All @@ -227,7 +227,7 @@ fn generate_hashes<I: Seek + Read>(
let mut hasher = Sha1::new();
hasher.update(pbo.hash_files(version)?);
hasher.update(pbo.hash_filenames()?);
if let Some(prefix) = pbo.extensions().get("prefix") {
if let Some(prefix) = pbo.properties().get("prefix") {
hasher.update(prefix.as_bytes());
if !prefix.ends_with('\\') {
hasher.update(b"\\");
Expand Down

0 comments on commit 060e2bd

Please sign in to comment.