Skip to content

Commit

Permalink
Reluctantly allow spaced filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyuuhachi committed Aug 17, 2023
1 parent 29f7005 commit 35c1f65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Unfortunately, several other tools, including SoraVoice and ED6Unpacker, expose
these raw names, and so the filenames need to be converted to the proper format
for use with LB-ARK.

To help with compatibility with such tools, LB-ARK accepts the
`$LB_ARK_SPACED_FILENAMES` environment variable. If this is nonempty, LB-ARK
will load 8.3 filenames as well. However, this is only intended for local
development; please do not release any mods requiring this to be set.

## Usage

To substitute a file inside an archive, place the substitute in
Expand Down
29 changes: 26 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ mod hooks {
}
}

lazy_static::lazy_static! {
static ref SPACED_FILENAMES: bool = std::env::var("LB_DIR_SPACED_FILENAMES").is_ok_and(|a| !a.is_empty());
}

#[instrument(skip_all)]
fn init() {
tracing::info!(
exe = %EXE_PATH.file_stem().unwrap().to_string_lossy(),
data = %DATA_DIR.display(),
"init",
);

if *SPACED_FILENAMES {
tracing::warn!("spaced filenames enabled");
}

if !DATA_DIR.exists() {
tracing::warn!("data dir does not exist, creating");
std::fs::create_dir_all(&*DATA_DIR).unwrap();
}

catch(plugin::init());
catch(init_lb_dir());
}
Expand Down Expand Up @@ -138,10 +148,23 @@ fn get_redirect_file(fileid: u32, entry: &Entry) -> Option<PathBuf> {
}
}

let dirnr = fileid >> 16;
let path = DATA_DIR.join(format!("ED6_DT{dirnr:02X}")).join(entry.name());
let dir = DATA_DIR.join(format!("ED6_DT{:02X}", fileid >> 16));

let path = dir.join(entry.name());
tracing::debug!(path = %rel(&path), exists = path.exists(), "checking implicit override");
path.exists().then_some(path)
if path.exists() {
return Some(path)
}

if *SPACED_FILENAMES {
let path = dir.join(&*String::from_utf8_lossy(&entry.stored_name));
tracing::debug!(path = %rel(&path), exists = path.exists(), "checking spaced implicit override");
if path.exists() {
return Some(path)
}
}

None
}

/// Reads a file into memory, compressing it if necessary.
Expand Down

0 comments on commit 35c1f65

Please sign in to comment.