Dart
Dart
Create Self-Extracting Executable (Windows-only)
Demonstrates how to create a Windows self-extracting EXE.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final zip = CkZip();
// Called periodically while a Chilkat method is running
// (frequency controlled by the heartbeatMs property).
zip.onAbortCheck = () {
return false; // return true to abort the method in progress
};
zip.onPercentDone = (pctDone) {
print('Percent Done: $pctDone');
// Explicitly abort at 25% or greater.
// Remove this to allow for the HTTP download to run to completion.
if (pctDone > 25) {
return true; // abort the Chilkat method in progress
}
return false; // return true to abort the method in progress
};
zip.onProgressInfo = (name, value) {
print('$name: $value');
};
// 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.
try {
zip.newZip('notUsed.zip');
} on ChilkatException catch (e) {
print(e.lastErrorText);
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.
final recurse = true;
zip.appendFiles('c:/temp/a/*', recurse);
// Write "sfx.exe"
try {
zip.writeExe('c:/temp/sfx.exe');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}