Rust
Rust
Create Self-Extracting Executable (Windows-only)
Demonstrates how to create a Windows self-extracting EXE.Chilkat Rust Downloads
struct ZipEvents;
impl chilkat::EventHandler for ZipEvents {
// Called periodically while a Chilkat method is running
// (frequency controlled by the HeartbeatMs property).
fn abort_check(&mut self) -> bool {
false // return true to abort the method in progress
}
fn percent_done(&mut self, percent_done: i32) -> bool {
println!("Percent Done: {}", percent_done);
// Explicitly abort at 25% or greater.
// Remove this to allow for the HTTP download to run to completion.
if percent_done > 25 {
return true; // abort the Chilkat method in progress
}
false // return true to abort the method in progress
}
fn progress_info(&mut self, name: &str, value: &str) {
println!("{}: {}", name, value);
}
}
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let zip = chilkat::Zip::new();
zip.set_event_handler(ZipEvents);
// Initialize the zip object. Because we're creating
// a self-extracting EXE in this example, the filename
// passed to NewZip will never actually be created.
if zip.new_zip("notUsed.zip").is_err() {
println!("{}", zip.last_error_text());
return;
}
// Append a directory tree. The AppendFiles does
// not read the file contents or append them to the zip
// object in memory. It simply appends references
// to the files so that when WriteExe (or WriteZipAndClose,
// or WriteZip, etc.) is called, the files are compressed
// and added to the archive.
let recurse = true;
let _ = zip.append_files("c:/temp/a/*", recurse);
// Write "sfx.exe"
if zip.write_exe("c:/temp/sfx.exe").is_err() {
println!("{}", zip.last_error_text());
return;
}