Last active
June 8, 2018 19:21
-
-
Save fvicente/c18387adf86654cfdc80 to your computer and use it in GitHub Desktop.
Compress a directory in inno setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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