Skip to main content

supreme_cleaner/
lib.rs

1mod case_normalizer;
2mod consolidator;
3mod object_cleaner;
4mod object_fixer;
5mod patcher;
6mod path_utils;
7mod texture_optimizer;
8pub mod txt_processor;
9
10use std::io;
11use std::sync::mpsc::Sender;
12
13use supreme_fs::{DiscoverMode, GameStorage};
14
15pub enum CleanerEvent {
16    Log(String),
17    SetStatus(String),
18    InitProgress(usize),
19    IncrementProgress,
20    Perf(String, String, u128), // Operation, Target, Duration_ms
21}
22
23/// Normalize the case of all files and folders by lowercasing them.
24///
25/// This should be run first to ensure all subsequent operations can work with case-sensitive paths.
26pub fn normalize_case(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
27    case_normalizer::normalize_case(storage, tx)
28}
29
30/// Free up textures by keeping only the best resolution file and moving it to the base directory.
31///
32/// This function scans the filesystem once and passes the results to the implementation.
33pub fn free_up_textures(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
34    let all_files = storage.discover(DiscoverMode::Files)?;
35    texture_optimizer::free_up_textures(storage, &all_files, tx)
36}
37
38/// Fix specific broken object references and data files.
39///
40/// This function scans the filesystem once and passes the results to the implementation.
41pub fn fix_object_references(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
42    let all_files = storage.discover(DiscoverMode::Files)?;
43    object_fixer::fix_object_references(storage, &all_files, tx)
44}
45
46/// Remove files in object directories that are not referenced.
47///
48/// This function scans the filesystem once and passes the results to the implementation.
49pub fn clean_unused_objects(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
50    let all_files = storage.discover(DiscoverMode::Files)?;
51    object_cleaner::clean_unused_objects(storage, &all_files, tx)
52}
53
54/// Consolidate resources by ensuring they are local to the referring file.
55///
56/// This function scans the filesystem once and passes the results to the implementation.
57pub fn consolidate_resources(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
58    let all_files = storage.discover(DiscoverMode::Files)?;
59    consolidator::consolidate_resources(storage, &all_files, tx)
60}
61
62/// Patch hardcoded paths in game binaries and migrate referenced resources.
63pub fn patch_game_binaries(storage: &GameStorage, tx: Sender<CleanerEvent>) -> io::Result<()> {
64    patcher::patch_game_binaries(storage, tx)
65}
66
67pub mod dependency_walker;
68use std::path::PathBuf;
69
70pub fn walk_dependencies(
71    storage: &GameStorage,
72    all_files: &[PathBuf],
73    roots: &[PathBuf],
74    ignored_extensions: &[&str],
75) -> io::Result<Vec<PathBuf>> {
76    dependency_walker::walk_dependencies(storage, all_files, roots, ignored_extensions)
77}