From 9d3cbd989420ac77b936b452b0ae0a6a412c7e4f Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Mon, 30 May 2022 03:18:01 +0100 Subject: [PATCH 01/11] Custom bundle support --- resources/scc.toml | 11 +++++++++ scc/src/main.rs | 58 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 resources/scc.toml diff --git a/resources/scc.toml b/resources/scc.toml new file mode 100644 index 00000000..f211ceaf --- /dev/null +++ b/resources/scc.toml @@ -0,0 +1,11 @@ +[args] +scriptsBlobPath = "{game_dir}/r6/cache/final.redscripts.modded" + +[[tasks]] +command = "{game_dir}/engine/tools/scc.exe" +args = [ + "-compile", + "{game_dir}/r6/scripts", + "-customPath", + "{game_dir}/r6/cache/final.redscripts.modded", +] diff --git a/scc/src/main.rs b/scc/src/main.rs index 76b8c8f2..5da04355 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -20,9 +20,9 @@ use time::OffsetDateTime; fn main() -> Result<(), Error> { // the way cyberpunk passes CLI args is broken, this is a workaround - let args: Vec = std::env::args().skip(1).collect(); - match &args[..] { - [cmd, path_str, ..] if cmd == "-compile" => { + let mut iter = std::env::args().skip(1); + match (iter.next().as_deref(), iter.next()) { + (Some("-compile"), Some(path_str)) => { let script_dir = PathBuf::from(path_str.split('"').next().unwrap()); let cache_dir = script_dir.parent().unwrap().join("cache"); @@ -50,7 +50,14 @@ fn main() -> Result<(), Error> { let files = Files::from_dir(&script_dir, manifest.source_filter())?; - match load_scripts(&cache_dir, &files) { + let result = match (iter.next().as_deref(), iter.next()) { + (Some("-customPath"), Some(custom_path)) => { + log::info!("Custom path provided: {}", custom_path); + compile_custom_bundle(&cache_dir, custom_path.as_ref(), &files) + } + _ => compile_default_bundle(&cache_dir, &files), + }; + match result { Ok(_) => { log::info!("Output successfully saved in {}", cache_dir.display()); } @@ -100,20 +107,35 @@ fn setup_logger(cache_dir: &Path, include_date_in_filename: bool) -> Result<(), Ok(()) } -fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { +fn compile_custom_bundle(cache_dir: &Path, custom_path: &Path, files: &Files) -> Result<(), Error> { + let bundle_path = cache_dir.join("final.redscripts"); + let backup_path = cache_dir.join("final.redscripts.bk"); + let input_path = if backup_path.is_file() { + backup_path + } else { + bundle_path + }; + + let mut output_file = RwLock::new(File::create(&custom_path)?); + compile_scripts(&input_path, files, output_file.write()?.deref_mut())?; + Ok(()) +} + +fn compile_default_bundle(cache_dir: &Path, files: &Files) -> Result<(), Error> { let bundle_path = cache_dir.join("final.redscripts"); let backup_path = cache_dir.join("final.redscripts.bk"); let timestamp_path = cache_dir.join("redscript.ts"); - let mut ts_lock = RwLock::new( + + let mut ts_file = RwLock::new( OpenOptions::new() .read(true) .write(true) .create(true) .open(×tamp_path)?, ); - let mut ts_file = ts_lock.write()?; + let mut ts_lock = ts_file.write()?; let write_timestamp = CompileTimestamp::of_cache_file(&File::open(&bundle_path)?)?; - let saved_timestamp = CompileTimestamp::read(ts_file.deref_mut()).ok(); + let saved_timestamp = CompileTimestamp::read(ts_lock.deref_mut()).ok(); match saved_timestamp { None if backup_path.exists() => { @@ -132,6 +154,17 @@ fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { _ => {} } + let mut file = File::create(&bundle_path)?; + compile_scripts(&backup_path, files, &mut file)?; + file.sync_all()?; + + CompileTimestamp::of_cache_file(&file)?.write(ts_lock.deref_mut()) +} + +fn compile_scripts(input_path: &Path, files: &Files, output: W) -> Result<(), Error> +where + W: io::Write + io::Seek, +{ #[cfg(feature = "mmap")] let mut bundle = { let (map, _) = vmap::Map::with_options() @@ -140,16 +173,11 @@ fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { ScriptBundle::load(&mut io::Cursor::new(map.as_ref()))? }; #[cfg(not(feature = "mmap"))] - let mut bundle = ScriptBundle::load(&mut io::BufReader::new(File::open(backup_path)?))?; + let mut bundle = ScriptBundle::load(&mut io::BufReader::new(File::open(input_path)?))?; CompilationUnit::new(&mut bundle.pool, vec![])?.compile_and_report(files)?; - let mut file = File::create(&bundle_path)?; - bundle.save(&mut io::BufWriter::new(&mut file))?; - file.sync_all()?; - - CompileTimestamp::of_cache_file(&file)?.write(ts_file.deref_mut())?; - + bundle.save(&mut io::BufWriter::new(output))?; Ok(()) } From 9b98209ff55497aabf9d9f34677465479a41244d Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Mon, 30 May 2022 03:26:01 +0100 Subject: [PATCH 02/11] Fixes --- resources/scc.toml | 10 +++------- scc/src/main.rs | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/resources/scc.toml b/resources/scc.toml index f211ceaf..17887cb6 100644 --- a/resources/scc.toml +++ b/resources/scc.toml @@ -2,10 +2,6 @@ scriptsBlobPath = "{game_dir}/r6/cache/final.redscripts.modded" [[tasks]] -command = "{game_dir}/engine/tools/scc.exe" -args = [ - "-compile", - "{game_dir}/r6/scripts", - "-customPath", - "{game_dir}/r6/cache/final.redscripts.modded", -] +command = "InvokeScc" +path = "{game_dir}/r6/scripts" +custom_bundle = "{game_dir}/r6/cache/final.redscripts.modded" diff --git a/scc/src/main.rs b/scc/src/main.rs index 5da04355..7eec9ece 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -167,8 +167,8 @@ where { #[cfg(feature = "mmap")] let mut bundle = { - let (map, _) = vmap::Map::with_options() - .open(backup_path) + let (map, _) = Map::with_options() + .open(input_path) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; ScriptBundle::load(&mut io::Cursor::new(map.as_ref()))? }; From eb8abe27e4b3add69db19840d5d24d322d8cd5d0 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:04:35 +0100 Subject: [PATCH 03/11] Cleanup --- .github/workflows/release.yml | 1 + resources/engine/config/cybercmd/scc.toml | 7 +++++++ resources/scc.toml | 7 ------- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 resources/engine/config/cybercmd/scc.toml delete mode 100644 resources/scc.toml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4da99eb7..4202eb0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,7 @@ jobs: mkdir -p ./engine/tools mkdir -p ./r6/scripts cp ../resources/engine/config/base/scripts.ini ./engine/config/base/ + cp ../resources/engine/config/cybercmd/cmd.toml ./engine/config/cybercmd/ cp ../target/release/scc.exe ./engine/tools/ cp ../resources/r6/scripts/redscript.toml ./r6/scripts/ 7z a -mx=9 -r ./redscript.zip * diff --git a/resources/engine/config/cybercmd/scc.toml b/resources/engine/config/cybercmd/scc.toml new file mode 100644 index 00000000..eddf52c2 --- /dev/null +++ b/resources/engine/config/cybercmd/scc.toml @@ -0,0 +1,7 @@ +[args] +scriptsBlobPath = "{game_dir}\\r6\\cache\\modded\\final.redscripts" + +[[tasks]] +command = "InvokeScc" +path = "{game_dir}\\r6\\scripts" +custom_bundle = "{game_dir}\\r6\\cache\\modded\\final.redscripts" diff --git a/resources/scc.toml b/resources/scc.toml deleted file mode 100644 index 17887cb6..00000000 --- a/resources/scc.toml +++ /dev/null @@ -1,7 +0,0 @@ -[args] -scriptsBlobPath = "{game_dir}/r6/cache/final.redscripts.modded" - -[[tasks]] -command = "InvokeScc" -path = "{game_dir}/r6/scripts" -custom_bundle = "{game_dir}/r6/cache/final.redscripts.modded" From 82685e802f549dc463c5368872c4f8d46e39ae91 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:07:35 +0100 Subject: [PATCH 04/11] Fix file name --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4202eb0e..e02c89d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: mkdir -p ./engine/tools mkdir -p ./r6/scripts cp ../resources/engine/config/base/scripts.ini ./engine/config/base/ - cp ../resources/engine/config/cybercmd/cmd.toml ./engine/config/cybercmd/ + cp ../resources/engine/config/cybercmd/scc.toml ./engine/config/cybercmd/ cp ../target/release/scc.exe ./engine/tools/ cp ../resources/r6/scripts/redscript.toml ./r6/scripts/ 7z a -mx=9 -r ./redscript.zip * From 381167c05695e90090d7297884e3896ff0596d11 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:14:08 +0100 Subject: [PATCH 05/11] Fix mmap feature --- scc/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scc/src/main.rs b/scc/src/main.rs index 7eec9ece..9f36b2c1 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -167,7 +167,7 @@ where { #[cfg(feature = "mmap")] let mut bundle = { - let (map, _) = Map::with_options() + let (map, _) = vmap::Map::with_options() .open(input_path) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; ScriptBundle::load(&mut io::Cursor::new(map.as_ref()))? From 12b1ea62a28a3528898153602e1c23cd4d4f26a3 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:20:51 +0100 Subject: [PATCH 06/11] Create mod archive in CI --- .github/workflows/ci.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2102e42a..29ff2dcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,21 @@ jobs: uses: actions-rs/cargo@v1 with: command: test + - run: mkdir staging + - name: Create the mod archive + working-directory: staging + run: | + mkdir -p ./engine/config/base + mkdir -p ./engine/tools + mkdir -p ./r6/scripts + cp ../resources/engine/config/base/scripts.ini ./engine/config/base/ + cp ../resources/engine/config/cybercmd/scc.toml ./engine/config/cybercmd/ + cp ../target/release/scc.exe ./engine/tools/ + cp ../resources/r6/scripts/redscript.toml ./r6/scripts/ + 7z a -mx=9 -r ./redscript.zip * - name: Archive artifacts uses: actions/upload-artifact@v2 with: path: | - target/release/scc.exe target/release/redscript-cli.exe + ./staging/redscript.zip From 6c8b13811fcb48e017be4d572fb7e43996017790 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:27:01 +0100 Subject: [PATCH 07/11] CI fixes --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29ff2dcd..620f8baa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [push, pull_request] +on: [push] env: CARGO_TERM_COLOR: always @@ -31,6 +31,7 @@ jobs: working-directory: staging run: | mkdir -p ./engine/config/base + mkdir -p ./engine/config/cybercmd mkdir -p ./engine/tools mkdir -p ./r6/scripts cp ../resources/engine/config/base/scripts.ini ./engine/config/base/ From 9723c892be0d58bd43386aa09a7ecbe78f65b0e0 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 21:03:28 +0100 Subject: [PATCH 08/11] Pick up cache dir path --- cli/src/main.rs | 2 +- resources/engine/config/cybercmd/scc.toml | 2 +- scc/src/main.rs | 75 +++++++++-------------- 3 files changed, 30 insertions(+), 49 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 413235a7..af8923b6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -137,7 +137,7 @@ fn decompile(opts: DecompileOpts) -> Result<(), redscript_decompiler::error::Err if opts.dump_files { for entry in FileIndex::from_pool(pool).iter() { - let path = opts.output.as_path().join(&entry.path); + let path = opts.output.as_path().join(entry.path); std::fs::create_dir_all(path.parent().unwrap())?; let mut output = io::BufWriter::new(File::create(path)?); diff --git a/resources/engine/config/cybercmd/scc.toml b/resources/engine/config/cybercmd/scc.toml index eddf52c2..7ad3e129 100644 --- a/resources/engine/config/cybercmd/scc.toml +++ b/resources/engine/config/cybercmd/scc.toml @@ -4,4 +4,4 @@ scriptsBlobPath = "{game_dir}\\r6\\cache\\modded\\final.redscripts" [[tasks]] command = "InvokeScc" path = "{game_dir}\\r6\\scripts" -custom_bundle = "{game_dir}\\r6\\cache\\modded\\final.redscripts" +custom_cache_dir = "{game_dir}\\r6\\cache\\modded" diff --git a/scc/src/main.rs b/scc/src/main.rs index 9f36b2c1..c58edc63 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -24,14 +24,25 @@ fn main() -> Result<(), Error> { match (iter.next().as_deref(), iter.next()) { (Some("-compile"), Some(path_str)) => { let script_dir = PathBuf::from(path_str.split('"').next().unwrap()); - let cache_dir = script_dir.parent().unwrap().join("cache"); + let r6_dir = script_dir.parent().unwrap(); + let cache_dir = match (iter.next().as_deref(), iter.next()) { + (Some("-customCacheDir"), Some(custom_path)) => { + log::info!("Custom cache directory provided: {}", custom_path); + let path = PathBuf::from(custom_path); + if !path.exists() { + std::fs::create_dir_all(&path)?; + } + path + } + _ => r6_dir.join("cache"), + }; // load manifest without fallback let manifest = ScriptManifest::load(&script_dir); // set up logger with an optional manifest setup_logger( - &cache_dir, + r6_dir, manifest .as_ref() .ok() @@ -50,14 +61,7 @@ fn main() -> Result<(), Error> { let files = Files::from_dir(&script_dir, manifest.source_filter())?; - let result = match (iter.next().as_deref(), iter.next()) { - (Some("-customPath"), Some(custom_path)) => { - log::info!("Custom path provided: {}", custom_path); - compile_custom_bundle(&cache_dir, custom_path.as_ref(), &files) - } - _ => compile_default_bundle(&cache_dir, &files), - }; - match result { + match load_scripts(&cache_dir, &files) { Ok(_) => { log::info!("Output successfully saved in {}", cache_dir.display()); } @@ -77,9 +81,7 @@ fn main() -> Result<(), Error> { Ok(()) } -fn setup_logger(cache_dir: &Path, include_date_in_filename: bool) -> Result<(), Error> { - let parent_dir = cache_dir.parent().unwrap(); - +fn setup_logger(r6_dir: &Path, include_date_in_filename: bool) -> Result<(), Error> { let log_file_name = if include_date_in_filename { const DATE_FORMAT: &[FormatItem] = format_description!("[year].[month].[day]_[hour]-[minute]-[second]"); let date = OffsetDateTime::now_utc().format(&DATE_FORMAT).unwrap(); @@ -88,7 +90,7 @@ fn setup_logger(cache_dir: &Path, include_date_in_filename: bool) -> Result<(), "redscript.log".to_owned() }; - let log_dir = &parent_dir.join("logs"); + let log_dir = &r6_dir.join("logs"); if !log_dir.exists() { fs::create_dir(log_dir)?; @@ -107,35 +109,20 @@ fn setup_logger(cache_dir: &Path, include_date_in_filename: bool) -> Result<(), Ok(()) } -fn compile_custom_bundle(cache_dir: &Path, custom_path: &Path, files: &Files) -> Result<(), Error> { - let bundle_path = cache_dir.join("final.redscripts"); - let backup_path = cache_dir.join("final.redscripts.bk"); - let input_path = if backup_path.is_file() { - backup_path - } else { - bundle_path - }; - - let mut output_file = RwLock::new(File::create(&custom_path)?); - compile_scripts(&input_path, files, output_file.write()?.deref_mut())?; - Ok(()) -} - -fn compile_default_bundle(cache_dir: &Path, files: &Files) -> Result<(), Error> { +fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { let bundle_path = cache_dir.join("final.redscripts"); let backup_path = cache_dir.join("final.redscripts.bk"); let timestamp_path = cache_dir.join("redscript.ts"); - - let mut ts_file = RwLock::new( + let mut ts_lock = RwLock::new( OpenOptions::new() .read(true) .write(true) .create(true) .open(×tamp_path)?, ); - let mut ts_lock = ts_file.write()?; + let mut ts_file = ts_lock.write()?; let write_timestamp = CompileTimestamp::of_cache_file(&File::open(&bundle_path)?)?; - let saved_timestamp = CompileTimestamp::read(ts_lock.deref_mut()).ok(); + let saved_timestamp = CompileTimestamp::read(ts_file.deref_mut()).ok(); match saved_timestamp { None if backup_path.exists() => { @@ -154,30 +141,24 @@ fn compile_default_bundle(cache_dir: &Path, files: &Files) -> Result<(), Error> _ => {} } - let mut file = File::create(&bundle_path)?; - compile_scripts(&backup_path, files, &mut file)?; - file.sync_all()?; - - CompileTimestamp::of_cache_file(&file)?.write(ts_lock.deref_mut()) -} - -fn compile_scripts(input_path: &Path, files: &Files, output: W) -> Result<(), Error> -where - W: io::Write + io::Seek, -{ #[cfg(feature = "mmap")] let mut bundle = { let (map, _) = vmap::Map::with_options() - .open(input_path) + .open(backup_path) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; ScriptBundle::load(&mut io::Cursor::new(map.as_ref()))? }; #[cfg(not(feature = "mmap"))] - let mut bundle = ScriptBundle::load(&mut io::BufReader::new(File::open(input_path)?))?; + let mut bundle = ScriptBundle::load(&mut io::BufReader::new(File::open(backup_path)?))?; CompilationUnit::new(&mut bundle.pool, vec![])?.compile_and_report(files)?; - bundle.save(&mut io::BufWriter::new(output))?; + let mut file = File::create(&bundle_path)?; + bundle.save(&mut io::BufWriter::new(&mut file))?; + file.sync_all()?; + + CompileTimestamp::of_cache_file(&file)?.write(ts_file.deref_mut())?; + Ok(()) } From 3d3a6043242c94e9f3ebfbbbe59ed69ae3d93000 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 21:10:42 +0100 Subject: [PATCH 09/11] Rearrange to fix log --- scc/src/main.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scc/src/main.rs b/scc/src/main.rs index c58edc63..5e71eb2d 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -25,17 +25,6 @@ fn main() -> Result<(), Error> { (Some("-compile"), Some(path_str)) => { let script_dir = PathBuf::from(path_str.split('"').next().unwrap()); let r6_dir = script_dir.parent().unwrap(); - let cache_dir = match (iter.next().as_deref(), iter.next()) { - (Some("-customCacheDir"), Some(custom_path)) => { - log::info!("Custom cache directory provided: {}", custom_path); - let path = PathBuf::from(custom_path); - if !path.exists() { - std::fs::create_dir_all(&path)?; - } - path - } - _ => r6_dir.join("cache"), - }; // load manifest without fallback let manifest = ScriptManifest::load(&script_dir); @@ -59,6 +48,18 @@ fn main() -> Result<(), Error> { ScriptManifest::default() }); + let cache_dir = match (iter.next().as_deref(), iter.next()) { + (Some("-customCacheDir"), Some(custom_path)) => { + log::info!("Custom cache directory provided: {}", custom_path); + let path = PathBuf::from(custom_path); + if !path.exists() { + std::fs::create_dir_all(&path)?; + } + path + } + _ => r6_dir.join("cache"), + }; + let files = Files::from_dir(&script_dir, manifest.source_filter())?; match load_scripts(&cache_dir, &files) { From 12da0c40890a8372e3734070004bda27d2644cda Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 21:57:29 +0100 Subject: [PATCH 10/11] Default to non-modded input bundle path --- scc/src/main.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scc/src/main.rs b/scc/src/main.rs index 5e71eb2d..00521a61 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -48,21 +48,23 @@ fn main() -> Result<(), Error> { ScriptManifest::default() }); - let cache_dir = match (iter.next().as_deref(), iter.next()) { + let (cache_dir, bundle_dir_override) = match (iter.next().as_deref(), iter.next()) { (Some("-customCacheDir"), Some(custom_path)) => { log::info!("Custom cache directory provided: {}", custom_path); - let path = PathBuf::from(custom_path); - if !path.exists() { - std::fs::create_dir_all(&path)?; + let cache_dir = PathBuf::from(custom_path); + if !cache_dir.exists() { + std::fs::create_dir_all(&cache_dir)?; + (cache_dir, Some(r6_dir.join("cache"))) + } else { + (cache_dir, None) } - path } - _ => r6_dir.join("cache"), + _ => (r6_dir.join("cache"), None), }; let files = Files::from_dir(&script_dir, manifest.source_filter())?; - match load_scripts(&cache_dir, &files) { + match load_scripts(&cache_dir, bundle_dir_override.as_deref(), &files) { Ok(_) => { log::info!("Output successfully saved in {}", cache_dir.display()); } @@ -110,8 +112,9 @@ fn setup_logger(r6_dir: &Path, include_date_in_filename: bool) -> Result<(), Err Ok(()) } -fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { - let bundle_path = cache_dir.join("final.redscripts"); +fn load_scripts(cache_dir: &Path, bundle_dir_override: Option<&Path>, files: &Files) -> Result<(), Error> { + let bundle_input_path = bundle_dir_override.unwrap_or(cache_dir).join("final.redscripts"); + let bundle_output_path = cache_dir.join("final.redscripts"); let backup_path = cache_dir.join("final.redscripts.bk"); let timestamp_path = cache_dir.join("redscript.ts"); let mut ts_lock = RwLock::new( @@ -122,7 +125,7 @@ fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { .open(×tamp_path)?, ); let mut ts_file = ts_lock.write()?; - let write_timestamp = CompileTimestamp::of_cache_file(&File::open(&bundle_path)?)?; + let write_timestamp = CompileTimestamp::of_cache_file(&File::open(&bundle_input_path)?)?; let saved_timestamp = CompileTimestamp::read(ts_file.deref_mut()).ok(); match saved_timestamp { @@ -134,7 +137,7 @@ fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { "Redscript cache file is not ours, copying it to {}", backup_path.display() ); - fs::copy(&bundle_path, &backup_path)?; + fs::copy(&bundle_input_path, &backup_path)?; } Some(_) if !backup_path.exists() => { log::warn!("A compiler timestamp was found but not the backup file, your installation might be corrupted, try removing redscript.ts and verifying game files"); @@ -154,7 +157,7 @@ fn load_scripts(cache_dir: &Path, files: &Files) -> Result<(), Error> { CompilationUnit::new(&mut bundle.pool, vec![])?.compile_and_report(files)?; - let mut file = File::create(&bundle_path)?; + let mut file = File::create(&bundle_output_path)?; bundle.save(&mut io::BufWriter::new(&mut file))?; file.sync_all()?; From 191c65a6bed933fe4b7d1c4bdf46ade5cbec9d19 Mon Sep 17 00:00:00 2001 From: jekky <11986158+jac3km4@users.noreply.github.com> Date: Sat, 10 Sep 2022 22:08:51 +0100 Subject: [PATCH 11/11] Align input paths --- scc/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scc/src/main.rs b/scc/src/main.rs index 00521a61..2e998e90 100644 --- a/scc/src/main.rs +++ b/scc/src/main.rs @@ -113,10 +113,11 @@ fn setup_logger(r6_dir: &Path, include_date_in_filename: bool) -> Result<(), Err } fn load_scripts(cache_dir: &Path, bundle_dir_override: Option<&Path>, files: &Files) -> Result<(), Error> { - let bundle_input_path = bundle_dir_override.unwrap_or(cache_dir).join("final.redscripts"); + let input_dir = bundle_dir_override.unwrap_or(cache_dir); + let bundle_input_path = input_dir.join("final.redscripts"); let bundle_output_path = cache_dir.join("final.redscripts"); - let backup_path = cache_dir.join("final.redscripts.bk"); - let timestamp_path = cache_dir.join("redscript.ts"); + let backup_path = input_dir.join("final.redscripts.bk"); + let timestamp_path = input_dir.join("redscript.ts"); let mut ts_lock = RwLock::new( OpenOptions::new() .read(true)