Lua
Lua
Create Self-Extracting Executable (Windows-only)
Demonstrates how to create a Windows self-extracting EXE.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local zip = chilkat.Zip.new()
zip:set_event_handler({
-- Called periodically while a method runs (every heartbeat_ms milliseconds).
abort_check = function()
return false -- return true to abort the method in progress
end,
percent_done = function(percentDone)
print("Percent Done: " .. percentDone)
-- Explicitly abort at 25% or greater.
-- Remove this to allow for the HTTP download to run to completion.
if percentDone > 25 then
return true -- abort the method in progress
end
return false -- return true to abort the method in progress
end,
progress_info = function(name, value)
print(name .. ": " .. value)
end,
})
-- 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.
local success = zip:new_zip("notUsed.zip")
if not success then
print(zip.last_error_text)
return
end
-- 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.
local recurse = true
zip:append_files("c:/temp/a/*", recurse)
-- Write "sfx.exe"
success = zip:write_exe("c:/temp/sfx.exe")
if not success then
print(zip.last_error_text)
return
end