decompression - Inno Setup - How to add multiple arc files to decompress? -
i using code: inno setup - how add cancel button decompressing page? (answer of martin prikryl) decompress arc file inno setup.
i want have possibility of decompress more 1 arc file install files components selection (for example). still show on overall progress bar extractions. whole possible?
this modification of answer inno setup - how add cancel button decompressing page?
prerequisities same, refer other answer.
in extractarc
, call addarchive
each archive want extract.
[files] source: unarc.dll; flags: dontcopy source: innocallback.dll; flags: dontcopy [code] type tfreearccallback = function(what: pansichar; int1, int2: integer; str: pansichar): integer; function wrapfreearccallback(callback: tfreearccallback; paramcount: integer): longword; external 'wrapcallback@files:innocallback.dll stdcall'; const arccancelcode = -10; function freearcextract( callback: longword; cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8, cmd9, cmd10: pansichar): integer; external 'freearcextract@files:unarc.dll cdecl'; const cp_utf8 = 65001; function widechartomultibyte(codepage: uint; dwflags: dword; lpwidecharstr: string; cchwidechar: integer; lpmultibytestr: ansistring; cchmultibyte: integer; lpdefaultcharfake: integer; lpuseddefaultcharfake: integer): integer; external 'widechartomultibyte@kernel32.dll stdcall'; function getstringasutf8(s: string): ansistring; var len: integer; begin len := widechartomultibyte(cp_utf8, 0, s, length(s), result, 0, 0, 0); setlength(result, len); widechartomultibyte(cp_utf8, 0, s, length(s), result, len, 0, 0); end; var arctotalsize: integer; arctotalextracted: integer; arcextracted: integer; arccancel: boolean; arcprogresspage: toutputprogresswizardpage; function freearccallback(awhat: pansichar; int1, int2: integer; str: pansichar): integer; var what: string; begin := awhat; if = 'origsize' begin log(format('adding archive files total size %d mb', [int1])); arctotalsize := arctotalsize + int1; end else if = 'write' begin if arctotalsize > 0 begin arcprogresspage.setprogress(arctotalextracted + int1, arctotalsize); end; arcextracted := int1; end else begin { pump message queue more (particularly 'read' callbacks), } { more smooth progress bar } if (arcextracted > 0) , (arctotalsize > 0) begin arcprogresspage.setprogress(arctotalextracted + arcextracted, arctotalsize); end; end; if arccancel result := arccancelcode else result := 0; end; procedure freearccmd(cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8, cmd9, cmd10: string); var arcresult: integer; begin arccancel := false; arcresult := freearcextract( wrapfreearccallback(@freearccallback, 4), getstringasutf8(cmd1), getstringasutf8(cmd2), getstringasutf8(cmd3), getstringasutf8(cmd4), getstringasutf8(cmd5), getstringasutf8(cmd6), getstringasutf8(cmd7), getstringasutf8(cmd8), getstringasutf8(cmd9), getstringasutf8(cmd10)); if arccancel begin raiseexception('extraction cancelled'); end else if arcresult <> 0 begin raiseexception(format('extraction failed code %d', [arcresult])); end; end; var arcarchives: array of string; procedure addarchive(archivepath: string); begin setarraylength(arcarchives, getarraylength(arcarchives) + 1); arcarchives[getarraylength(arcarchives) - 1] := archivepath; freearccmd('l', '--', archivepath, '', '', '', '', '', '', ''); end; procedure unpackarchives(destpath: string); var i: integer; archivepath: string; begin log(format('total size of files extracted %d mb', [arctotalsize])); arctotalextracted := 0; := 0 getarraylength(arcarchives) - 1 begin arcextracted := 0; archivepath := arcarchives[i]; log(format('extracting %s', [archivepath])); freearccmd('x', '-o+', '-dp' + destpath, '-w' + destpath, '--', archivepath, '', '', '', ''); arctotalextracted := arctotalextracted + arcextracted; end; end; procedure unpackcancelbuttonclick(sender: tobject); begin arccancel := true; end; procedure extractarc; var prevcancelbuttonclick: tnotifyevent; begin arcprogresspage := createoutputprogresspage('decompression', 'decompressing archive...'); arcprogresspage.setprogress(0, 100); arcprogresspage.show; try wizardform.cancelbutton.visible := true; wizardform.cancelbutton.enabled := true; prevcancelbuttonclick := wizardform.cancelbutton.onclick; wizardform.cancelbutton.onclick := @unpackcancelbuttonclick; try addarchive(expandconstant('{src}\test1.arc')); addarchive(expandconstant('{src}\test2.arc')); log('arc extraction starting'); unpackarchives(expandconstant('{app}')); except msgbox(getexceptionmessage(), mberror, mb_ok); end; log('arc extraction done'); arcprogresspage.hide; wizardform.cancelbutton.onclick := prevcancelbuttonclick; end; end; procedure curstepchanged(curstep: tsetupstep); begin if curstep = sspostinstall begin extractarc; end; end;
Comments
Post a Comment