Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compress a directory in inno setup
function MakeBackup(indir, outfile: String): Boolean;
var
res: Boolean;
fso: Variant;
winShell: Variant;
f: Variant;
inObj: Variant;
outObj: Variant;
begin
res := FALSE;
try
fso := CreateOleObject('Scripting.FileSystemObject');
winShell := CreateOleObject('shell.application');
// create a new clean zip archive
f := fso.CreateTextFile(outfile, TRUE);
f.write('PK' + Chr(5) + Chr(6) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0));
f.close;
inObj := winShell.NameSpace(indir);
outObj := winShell.NameSpace(outfile);
outObj.CopyHere(inObj.Items);
repeat
Sleep(1000);
until outObj.Items.Count = inObj.Items.Count;
res := TRUE;
except
end;
Result := res;
end;
// Sample usage
procedure CurStepChanged(CurStep: TSetupStep);
var
timestamp: String;
bkprc: Boolean;
begin
if CurStep = ssInstall then begin
timestamp := GetDateTimeString('yyyymmdd_hhnnss', #0, #0);
bkprc := MakeBackup(ExpandConstant('{app}'), ExpandConstant('{app}') + '\..\' + timestamp + '.zip');
if bkprc = FALSE then begin
if MsgBox('Backup failed. Are you sure you want to continue?', mbConfirmation, MB_YESNO) = IDNO then
Abort();
end;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.