Skip to content

Commit 6210077

Browse files
committed
Add workaround for "Access Denied" error on meakashi when trying to remove temp files
- For some reason you get an "Accees Denied" when trying to delete individual files, only when when compiling Meakashi. Also, deleting manually via file explorer has no issue, it's only when you try to remove a file from the rust program - Instead of removing all temp files besides the .assets file, we now archive only the .assets file via 7z and leave the temp files alone - Temp files are cleaned up the next time the script runs (so we don't accidentally reuse them) - For some reason removing the entire folder when the program is first called works, perhaps because file locks are released when the rust program finishes.
1 parent c36d671 commit 6210077

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/main.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ fn main() -> ExitCode {
6464
let assets = format!("{}/{}", assets_containing_folder, "sharedassets0.assets");
6565
println!("Looking for vanilla assets at [{}]", assets);
6666
let directory_assets = "output/assets";
67-
let directory_data = format!("output/HigurashiEp{:02}_Data", arc_number);
67+
68+
// Example 'HigurashiEp05_Data' for Chapter 5
69+
let higu_ep_folder_name = format!("HigurashiEp{:02}_Data", arc_number);
70+
71+
// Example 'output/HigurashiEp05_Data'
72+
let directory_data = format!("output/{}", higu_ep_folder_name);
73+
74+
// Example 'output/HigurashiEp05_Data/meakashi_5.5.3p1_unix.emip'
6875
let emip = format!("{}/{}_{}_{}.emip", &directory_data, &chapter, &unity, &system);
76+
77+
// Example 'Meakashi-UI_5.5.3p1_unix.7z'
6978
//to_title_case() replaces hyphens and underscores with spaces. If this happens, revert it by replacing spaces with hyphens.
7079
let archive = format!("{}-UI_{}_{}{}.7z", &chapter.to_title_case().replace(" ", "-"), &unity, &system, &format_checksum(checksum, "_"));
7180

@@ -224,22 +233,20 @@ fn main() -> ExitCode {
224233

225234
assert!(status.success());
226235

227-
fs::remove_file(format!("{}/sharedassets0.assets.bak0000", &directory_data)).expect("Failed to remove file");
228-
let res_file = format!("{}/sharedassets0.assets.resS", &directory_data);
229-
if Path::new(&res_file).exists() {
230-
fs::remove_file(&res_file).expect("Failed to remove file");
231-
}
232-
fs::remove_file(&emip).expect("Failed to remove file");
233-
234236
// 7. pack with 7zip
235-
let result_7za = pack_7zip("7za", &archive, &directory_data);
237+
// Note: We run 7zip from inside the "output" folder so the final archive just contains
238+
// 'HigurashiEp05_Data/sharedassets0.assets' (otherwise it would be 'output/HigurashiEp05_Data/sharedassets0.assets')
239+
let cwd = "output".to_string();
240+
let files_to_archive = format!("{}/sharedassets0.assets", higu_ep_folder_name);
241+
242+
let result_7za = pack_7zip("7za", &archive, &cwd, &files_to_archive);
236243

237244
let status: std::io::Result<process::ExitStatus> = match result_7za {
238245
Ok(ok) => Ok(ok),
239246
Err(err) => match err.kind() {
240247
std::io::ErrorKind::NotFound => {
241248
println!("Warning: '7za' not found - trying '7z' instead");
242-
pack_7zip("7z", &archive, &directory_data)
249+
pack_7zip("7z", &archive, &cwd, &files_to_archive)
243250
},
244251
_ => Err(err),
245252
}
@@ -257,13 +264,15 @@ fn format_checksum(checksum: Option<&String>, sep: &str) -> String
257264
return checksum.map_or("".to_string(), |c| format!("{}{}", sep, c));
258265
}
259266

260-
fn pack_7zip(command: &str, archive: &String, directory_data: &String) -> std::io::Result<process::ExitStatus> {
267+
fn pack_7zip(command: &str, archive: &String, cwd: &String, path: &String) -> std::io::Result<process::ExitStatus> {
268+
println!("[7-Zip] Running {} in working directory: [{}] and path: [{}]...", command, cwd, path);
269+
261270
Command::new(command)
262-
.current_dir("output")
271+
.current_dir(cwd)
263272
.arg("a")
264273
.arg("-t7z")
265274
.arg(archive)
266-
.arg(format!("../{}", directory_data))
275+
.arg(path)
267276
.status()
268277
}
269278

0 commit comments

Comments
 (0)