Skip to content

Commit 0db492b

Browse files
committed
Cleanup
1 parent df1a333 commit 0db492b

File tree

10 files changed

+414
-309
lines changed

10 files changed

+414
-309
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "arcropolis"
3-
version = "4.0.6"
3+
version = "4.0.7"
44
authors = ["Raytwo <raytwo@arcropolis.com>, blujay <the.blu.dev@gmail.com>, jam1garner <jam@jam1.re>, CoolSonicKirby <alihussain2001@gmail.com>"]
55
edition = "2018"
66

@@ -38,7 +38,7 @@ owo-colors = "3.5.0"
3838
strip-ansi-escapes = "0.1.1"
3939
bincode = "1.3.3"
4040
# To manage mods
41-
orbits = { git = "https://github.com/blu-dev/orbits" }
41+
orbits = { git = "https://github.com/Raytwo/orbits" }
4242
smash-arc = { git = "https://github.com/jam1garner/smash-arc", features = ["smash-runtime", "rust-zstd", "serialize"] }
4343
hash40 = "1.3"
4444
arcropolis-api = { git = "https://github.com/Raytwo/arcropolis_api" }

src/fs.rs

Lines changed: 186 additions & 140 deletions
Large diffs are not rendered by default.

src/fs/discover.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use camino::Utf8Path;
77
use orbits::{ConflictHandler, ConflictKind, FileLoader, LaunchPad, StandardLoader, Tree};
88
use skyline::nn::{self, ro::*};
99
use smash_arc::Hash40;
10-
1110
use crate::{chainloader::*, utils};
1211

1312
pub fn perform_discovery() -> LaunchPad<StandardLoader> {

src/fs/utils.rs

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,87 +11,73 @@ use smash_arc::Hash40;
1111
use super::{ApiCallback, ApiLoader};
1212
use crate::{hashes, PathExtension};
1313

14-
pub fn make_hash_maps<L: FileLoader>(tree: &Tree<L>) -> (HashMap<Hash40, usize>, HashMap<Hash40, PathBuf>)
14+
/// Single tree walk that builds hash maps (size + path) and collects nus3bank dependencies.
15+
///
16+
/// Regional variant priority: if a regional file (containing '+') is found, it takes priority
17+
/// over the non-regional variant. See original comment by blujay for details.
18+
pub fn make_hash_maps_and_nus3bank_deps<L: FileLoader>(
19+
tree: &Tree<L>,
20+
unshare_blacklist: &[hash40::Hash40],
21+
) -> (HashMap<Hash40, usize>, HashMap<Hash40, PathBuf>, HashSet<PathBuf>)
1522
where
1623
<L as FileLoader>::ErrorType: Debug,
1724
{
18-
// This defines the previously undefined behavior of what happens when you have two files that overlap each other due to
19-
// regional things
20-
// I.E.: ui/message/msg_menu.msbt and ui/message/msg_menu+us_en.msbt
21-
// The regional variant should take priority. Since there can only be one regional file, there are only two situations which need to be handled:
22-
// 1.) ui/message/msg_menu.msbt is found and then ui/message/msg_menu+us_en.msbt is found. ui/message/msg_menu+us_en.msbt should overwrite the previous file
23-
// 2.) ui/message/msg_menu+us_en.msbt is found first, and when ui/message/msg_menu.msbt is found it should be discarded
24-
// To solve this I store the hash of every file which has a regional variant which has been found, and then if a non-regional variant is found
25-
// it is ignored
26-
// - blujay
2725
let mut regional_overrides = HashSet::new();
2826
let mut size_map = HashMap::new();
2927
let mut path_map = HashMap::new();
28+
let mut nus3audio_deps = HashSet::new();
29+
let mut nus3banks_found = HashSet::new();
30+
3031
tree.walk_paths(|node, ty| {
3132
if !ty.is_file() {
3233
return;
3334
}
3435

35-
if let Some(size) = tree.query_filesize(node.get_local()) {
36-
match node.get_local().smash_hash() {
36+
let local = node.get_local();
37+
38+
// Collect nus3bank dependency info for non-stream files
39+
if !local.is_stream() {
40+
if local.has_extension("nus3audio") {
41+
if let Ok(hash) = local.smash_hash() {
42+
if !unshare_blacklist.contains(&hash.to_external()) {
43+
nus3audio_deps.insert(local.with_extension("nus3bank"));
44+
}
45+
}
46+
} else if local.has_extension("nus3bank") {
47+
nus3banks_found.insert(local.to_path_buf());
48+
}
49+
}
50+
51+
// Use cached size from discovery (falls back to loader if not cached)
52+
if let Some(size) = tree.query_filesize(local) {
53+
match local.smash_hash() {
3754
Ok(hash) => {
3855
if regional_overrides.contains(&hash) {
3956
return;
4057
}
4158

42-
let is_regional_variant = if let Some(node) = node.get_local().to_str() { node.contains('+') } else { false };
59+
let is_regional_variant = if let Some(node) = local.to_str() { node.contains('+') } else { false };
4360

4461
size_map.insert(hash, size);
45-
path_map.insert(hash, node.get_local().to_path_buf());
62+
path_map.insert(hash, local.to_path_buf());
4663

4764
if is_regional_variant {
4865
regional_overrides.insert(hash);
4966
}
5067
},
51-
Err(e) => error!("Failed to get hash for {}. Reason: {:?}", node.get_local().display(), e),
68+
Err(e) => error!("Failed to get hash for {}. Reason: {:?}", local.display(), e),
5269
}
5370
} else {
5471
error!("Failed to stat file {}. This file may have issues.", node.full_path().display());
5572
}
5673
});
5774

58-
(size_map, path_map)
59-
}
60-
61-
pub fn get_required_nus3banks<L: FileLoader>(tree: &Tree<L>, unshare_blacklist: &[hash40::Hash40]) -> HashSet<PathBuf>
62-
where
63-
<L as FileLoader>::ErrorType: Debug,
64-
{
65-
let mut nus3audio_deps = HashSet::new();
66-
let mut nus3banks_found = HashSet::new();
67-
tree.walk_paths(|node, ty| {
68-
if !ty.is_file() {
69-
return;
70-
}
71-
72-
let local = node.get_local();
73-
if local.is_stream() {
74-
return;
75-
}
76-
77-
if local.has_extension("nus3audio") {
78-
match local.smash_hash() {
79-
Ok(hash) if !unshare_blacklist.contains(&hash.to_external()) => {
80-
nus3audio_deps.insert(local.with_extension("nus3bank"));
81-
},
82-
Err(e) => error!("Failed to get hash for path {}. Reason: {:?}", local.display(), e),
83-
_ => {},
84-
}
85-
} else if local.has_extension("nus3bank") {
86-
nus3banks_found.insert(local.to_path_buf());
87-
}
88-
});
89-
75+
// Remove nus3bank deps that have actual nus3bank files present
9076
for bank in nus3banks_found.into_iter() {
9177
nus3audio_deps.remove(&bank);
9278
}
9379

94-
nus3audio_deps
80+
(size_map, path_map, nus3audio_deps)
9581
}
9682

9783
pub fn add_file_to_api_tree<P: AsRef<Path>, Q: AsRef<Path>>(

src/hashes.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ pub fn add<S: AsRef<str>>(new_hash: S) {
4646
let _ = hashes.try_insert(Hash40::from(new_hash), string_to_static_str(new_hash.to_string()));
4747
}
4848

49+
pub fn add_all<I, S>(items: I)
50+
where
51+
I: IntoIterator<Item = S>,
52+
S: AsRef<str>,
53+
{
54+
let mut hashes = HASHES.write().unwrap();
55+
for item in items {
56+
let s = item.as_ref();
57+
let _ = hashes.try_insert(Hash40::from(s), string_to_static_str(s.to_string()));
58+
}
59+
}
60+
4961
pub fn init() {
5062
LazyLock::force(&HASHES);
5163
}

src/replacement/addition.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use arc_config::{
66
};
77
use smash_arc::*;
88

9-
use super::{lookup, AdditionContext, FromPathExt, FromSearchableFile, FromSearchableFolder, InterDir, SearchContext};
9+
use super::{lookup, AdditionContext, FromPathExt, FromSearchableFile, FromSearchableFolder, InterDir, SearchContext, NO_CHILD};
1010
use crate::{
1111
hashes,
1212
replacement::FileInfoFlagsExt,
@@ -43,7 +43,7 @@ pub fn add_file(ctx: &mut AdditionContext, path: &Path) {
4343

4444
// Create a new FileInfoIndex with the created file_info_idx above and a dir offset index of
4545
let new_info_indice_idx = FileInfoIndex {
46-
dir_offset_index: 0xFF_FFFF,
46+
dir_offset_index: NO_CHILD,
4747
file_info_index: file_info_idx,
4848
};
4949

@@ -99,7 +99,7 @@ pub fn add_file(ctx: &mut AdditionContext, path: &Path) {
9999
info!("Added file '{}' ({:#x})", path.display(), file_path.path.hash40().0);
100100
}
101101

102-
pub fn add_shared_file(ctx: &mut AdditionContext, new_file: &File, shared_to: Hash40) {
102+
pub fn add_shared_file(ctx: &mut AdditionContext, new_file: &File, shared_to: Hash40, share_lut: &mut lookup::ShareLookup) {
103103
// Get the target shared FileInfoIndice index
104104
let info_indice_idx = if let Ok(info) = ctx.get_file_info_from_hash(shared_to) {
105105
info.file_info_indice_index.0
@@ -138,7 +138,7 @@ pub fn add_shared_file(ctx: &mut AdditionContext, new_file: &File, shared_to: Ha
138138
.hash40();
139139

140140
// Add the shared file to the lookup
141-
lookup::add_shared_file(
141+
share_lut.add_shared_file(
142142
new_file.full_path.to_smash_arc(), // we can unwrap because of FilePath::from_path being successful
143143
shared_to.to_smash_arc(),
144144
);
@@ -149,7 +149,7 @@ pub fn add_searchable_folder_recursive(ctx: &mut SearchContext, path: &Path) {
149149
Some(parent) if parent == Path::new("") => {
150150
if let Some(mut new_folder_path) = FolderPathListEntry::from_path(path) {
151151
let new_path = new_folder_path.as_path_entry();
152-
new_folder_path.set_first_child_index(0xFF_FFFF);
152+
new_folder_path.set_first_child_index(NO_CHILD);
153153
ctx.new_folder_paths.insert(new_folder_path.path.hash40(), ctx.folder_paths.len());
154154
ctx.new_paths.insert(new_path.path.hash40(), ctx.path_list_indices.len());
155155
ctx.path_list_indices.push(ctx.paths.len() as u32);
@@ -192,7 +192,7 @@ pub fn add_searchable_folder_recursive(ctx: &mut SearchContext, path: &Path) {
192192

193193
if let Some(mut new_folder) = FolderPathListEntry::from_path(path) {
194194
// Create a new directory that does not have child directories
195-
new_folder.set_first_child_index(0xFF_FFFF);
195+
new_folder.set_first_child_index(NO_CHILD);
196196
// Create a new search path
197197
let mut new_path = new_folder.as_path_entry();
198198
// Set the previous head of the linked list as the child of the new path
@@ -242,7 +242,7 @@ fn add_searchable_folder_by_folder(ctx: &mut SearchContext, folder: &Folder) ->
242242

243243
let mut new_folder = FolderPathListEntry::from_folder(folder);
244244
// Create a new directory that does not have child directories
245-
new_folder.set_first_child_index(0xFF_FFFF);
245+
new_folder.set_first_child_index(NO_CHILD);
246246
// Create a new search path
247247
let mut new_path = new_folder.as_path_entry();
248248
// Set the previous head of the linked list as the child of the new path
@@ -599,15 +599,17 @@ pub fn add_dir_info(ctx: &mut AdditionContext, path: &Path) {
599599
size: 0,
600600
file_start_index: dir_info.file_info_start_index,
601601
file_count: dir_info.file_count,
602-
directory_index: 0xFF_FFFF,
602+
directory_index: NO_CHILD,
603603
};
604604

605605
dir_info.path.set_index(ctx.folder_offsets_vec.len() as u32);
606606
// --------------------- END FOLDER OFFSETS --------------------- //
607607

608608
// --------------------- PUSH TO CONTEXT DONE HERE --------------------- //
609+
let dir_hash = dir_hash_to_info_idx.hash40();
609610
ctx.dir_infos_vec.push(dir_info);
610611
ctx.dir_hash_to_info_idx.push(dir_hash_to_info_idx);
612+
ctx.cache_dir_info(dir_hash);
611613
ctx.folder_offsets_vec.push(new_dir_offset);
612614
ctx.loaded_directories.push(LoadedDirectory::default());
613615
// --------------------- END PUSH TO CONTEXT --------------------- //

0 commit comments

Comments
 (0)