Skip to content

Commit

Permalink
Some cleanup, enable LTO
Browse files Browse the repository at this point in the history
  • Loading branch information
zCubed3 committed Jan 18, 2024
1 parent a07ba55 commit 482082d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "asset_migrator"
version = "1.0.0"
edition = "2021"
description = "A tool to migrate Unity assets from one project to another; Assuming exporting a package is not possible!"

license = "BSD-3"

Expand All @@ -10,4 +11,11 @@ authors = [
"notnotnotswipez"
]

[profile.release]
lto = true

[profile.rel-with-debug]
inherits = "release"
debug = true

[dependencies]
4 changes: 3 additions & 1 deletion src/dropwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ===================================================================================

#![allow(dead_code)]

use std::time;

/// Measures time from the creation of this watch to when it exists scope
Expand All @@ -52,7 +54,7 @@ impl Dropwatch {
pub fn new_begin(id: &str) -> Self {
let mut s = Self::new(id);
s.begin();
return s;
s
}
}

Expand Down
57 changes: 28 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use std::env;
use std::fs::*;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::thread::sleep;
use std::time::Duration;

use crate::meta_file::*;

Expand All @@ -48,7 +50,7 @@ struct AssetConversion {

impl PartialEq<AssetConversion> for AssetConversion {
fn eq(&self, other: &AssetConversion) -> bool {
return self.path == other.path;
self.path == other.path
}
}

Expand All @@ -61,25 +63,23 @@ fn print_help() {
}

fn main() {
sleep(Duration::from_millis(10000u64));

// Handle arguments
let args: Vec<String> = env::args().collect();

let mut src_assets = String::new();
let mut dst_assets = String::new();

if args.len() > 1 {
let (src_assets, dst_assets) = if args.len() > 1 {
// Minimum is 4
if args.len() < 3 {
print_help();
return;
}

src_assets = args[1].clone();
dst_assets = args[2].clone();
(args[1].clone(), args[2].clone())
} else {
print_help();
return;
}
};

// Before we export, create the temp folder
let _ = create_dir("ConversionOutput");
Expand Down Expand Up @@ -186,8 +186,8 @@ fn main() {

let mut convert_queue = Vec::<AssetConversion>::new();

for a in 3..args.len() {
let prefab_dir = PathBuf::from(&args[a]);
for prefab in args.iter().skip(3) {
let prefab_dir = PathBuf::from(prefab);
let mut relative_export_path = PathBuf::from(&export_path);

let sanitized = {
Expand All @@ -201,18 +201,17 @@ fn main() {
relative_export_path.push(sanitized);
relative_export_path.pop();

let mut import = PathBuf::from(&args[a]);
let mut import = PathBuf::from(prefab);

if !import.starts_with(&src_assets) {
import = PathBuf::from(&src_assets);
import.push(&args[a]);
import.push(prefab);
}

let mut convert = AssetConversion::default();
convert.path = import.display().to_string();
convert.output_path = relative_export_path.display().to_string();

convert_queue.push(convert);
convert_queue.push(AssetConversion {
path: import.display().to_string(),
output_path: relative_export_path.display().to_string(),
});
}

while let Some(convert) = convert_queue.pop() {
Expand Down Expand Up @@ -273,16 +272,18 @@ fn main() {
// If this is a prefab, push it to the list of queued conversions
// If it hasn't been pushed already!
for ext in &convert_extensions {
if missing_meta.base_name.ends_with(ext.as_str()) {
let mut convert = AssetConversion::default();
convert.path = asset_src_path.clone();

if !convert_queue.contains(&convert) {
println!("Converting referenced asset {:?}", asset_src_path);

convert.output_path = relative_export_path.display().to_string();
convert_queue.push(convert);
}
if missing_meta.base_name.ends_with(ext.as_str())
&& !convert_queue.iter().any(|e| e.path == asset_src_path)
{
println!(
"[Conversion]: Enqueuing referenced asset {:?}",
asset_src_path
);

convert_queue.push(AssetConversion {
path: asset_src_path.clone(),
output_path: relative_export_path.display().to_string(),
});

break;
}
Expand All @@ -292,8 +293,6 @@ fn main() {
// This prevents prefab duplication / overwriting
need_delete = true;
break;

//println!("MATCH: {} = {:?}", guid, missing_meta)
}

delete += 1;
Expand Down
12 changes: 5 additions & 7 deletions src/meta_file/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use super::meta_file::MetaFile;
/// Spawns threads and collects meta files from an internal worklist
pub struct MetaFileCollector {
threads: Vec<JoinHandle<()>>,
work_paths: Arc<Mutex<Vec<PathBuf>>>,
meta_files: Arc<Mutex<Vec<MetaFile>>>,
condvar: Arc<(Mutex<bool>, Condvar)>,
}
Expand Down Expand Up @@ -69,19 +68,18 @@ impl MetaFileCollector {
}));
}

return Self {
Self {
threads,
work_paths,
meta_files,
condvar,
};
}
}

pub fn wait(&self) {
{
let (lock, cvar) = &*self.condvar;
let mut notified = lock.lock().unwrap();

let mut notified = lock.lock().unwrap();
notified = cvar.wait(notified).unwrap();
}
}
Expand Down Expand Up @@ -114,8 +112,8 @@ impl MetaFileCollector {
meta_files: Arc<Mutex<Vec<MetaFile>>>,
) {
loop {
let mut path: Option<PathBuf> = None;
let mut notify: bool = false;
let path: Option<PathBuf>;
let notify: bool;

{
let mut lock = work_paths.lock().unwrap();
Expand Down

0 comments on commit 482082d

Please sign in to comment.