Skip to content

Commit

Permalink
Check if XMSBT's region is current region (#556)
Browse files Browse the repository at this point in the history
* Check if XMSBT's region is current region

* Update utils.rs

---------

Co-authored-by: Raytwo <[email protected]>
  • Loading branch information
zrksyd and Raytwo authored Dec 12, 2023
1 parent 6f1b8e2 commit 854cb79
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/fs/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use orbits::{FileLoader, Tree};
use smash_arc::Hash40;

use super::{ApiCallback, ApiLoader};
use crate::{hashes, PathExtension};
use crate::{config, hashes, PathExtension};

pub fn make_hash_maps<L: FileLoader>(tree: &Tree<L>) -> (HashMap<Hash40, usize>, HashMap<Hash40, PathBuf>)
where
Expand Down Expand Up @@ -165,8 +165,11 @@ pub fn add_prc_patch<P: AsRef<Path>, Q: AsRef<Path>>(tree: &mut Tree<ApiLoader>,
pub fn add_msbt_patch<P: AsRef<Path>, Q: AsRef<Path>>(tree: &mut Tree<ApiLoader>, phys_root: P, local: Q) -> Option<Hash40> {
let local = local.as_ref();
let base_local = local.with_extension("msbt"); // patch files have different extensions
let mut is_current_region = true;

let base_local = if let Some(name) = base_local.file_name().and_then(|os_str| os_str.to_str()) {
if let Some(idx) = name.find('+') {
current_region = (&name[idx + 1..idx + 6] == format!("{}", config::region())); //Check if XMSBT's region is current region
let mut new_name = name.to_string();
new_name.replace_range(idx..idx + 6, "");
base_local.with_file_name(new_name)
Expand All @@ -187,7 +190,9 @@ pub fn add_msbt_patch<P: AsRef<Path>, Q: AsRef<Path>>(tree: &mut Tree<ApiLoader>
hashes::add(local);
}
if let Some(base_local) = base_local.to_str() {
hashes::add(base_local);
if is_current_region {
hashes::add(base_local);
}
}
Some(hash)
},
Expand Down

0 comments on commit 854cb79

Please sign in to comment.