Skip to content

Commit 9fc18ac

Browse files
committed
Fix local 7za/7z (from download) not being found by main.rs
- Gave "Warning: '7za' not found - trying '7z' instead" error and then panic
1 parent 2684c93 commit 9fc18ac

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ use inflector::Inflector;
88
use log::*;
99
use simplelog::{TermLogger, TerminalMode, ColorChoice,Config};
1010

11+
fn try_absolute_exe_path(exe_name: &str) -> std::ffi::OsString
12+
{
13+
if let Ok(maybe_path) = fs::canonicalize(format!("{}.exe", exe_name))
14+
{
15+
if maybe_path.exists()
16+
{
17+
println!("Successfully found abs path of [{}] at [{}]", exe_name, maybe_path.to_string_lossy());
18+
return maybe_path.into_os_string();
19+
}
20+
}
21+
22+
return std::ffi::OsString::from(exe_name);
23+
}
24+
1125
fn main() -> ExitCode {
1226
TermLogger::init(
1327
LevelFilter::Trace,
@@ -253,14 +267,14 @@ fn main() -> ExitCode {
253267
let cwd = "output".to_string();
254268
let files_to_archive = format!("{}/sharedassets0.assets", higu_ep_folder_name);
255269

256-
let result_7za = pack_7zip("7za", &archive, &cwd, &files_to_archive);
270+
let result_7za = pack_7zip(&try_absolute_exe_path("7za"), &archive, &cwd, &files_to_archive);
257271

258272
let status: std::io::Result<process::ExitStatus> = match result_7za {
259273
Ok(ok) => Ok(ok),
260274
Err(err) => match err.kind() {
261275
std::io::ErrorKind::NotFound => {
262276
println!("Warning: '7za' not found - trying '7z' instead");
263-
pack_7zip("7z", &archive, &cwd, &files_to_archive)
277+
pack_7zip(&try_absolute_exe_path("7z"), &archive, &cwd, &files_to_archive)
264278
},
265279
_ => Err(err),
266280
}
@@ -278,8 +292,8 @@ fn format_checksum(checksum: Option<&String>, sep: &str) -> String
278292
return checksum.map_or("".to_string(), |c| format!("{}{}", sep, c));
279293
}
280294

281-
fn pack_7zip(command: &str, archive: &String, cwd: &String, path: &String) -> std::io::Result<process::ExitStatus> {
282-
println!("[7-Zip] Running {} in working directory: [{}] and path: [{}]...", command, cwd, path);
295+
fn pack_7zip<S: AsRef<std::ffi::OsStr>>(command: &S, archive: &String, cwd: &String, path: &String) -> std::io::Result<process::ExitStatus> {
296+
println!("[7-Zip] Running {} in working directory: [{}] and path: [{}]...", command.as_ref().to_string_lossy(), cwd, path);
283297

284298
Command::new(command)
285299
.current_dir(cwd)

0 commit comments

Comments
 (0)