Delphi self-extracting program

I am writing a updater in Delphi7 that will run once, but you need a lot of files to run.

What I would like to achieve:

  • User runs exe
  • Exe unpacks files, starts updating
  • If the detection and update error is updated, a request is sent to send the log by email
  • After starting the updater, temporary files are deleted (some of these files are DLLs used by the updater, so the updater must be closed before deleting the files)

Can anyone recommend a good solution? I was thinking about using Inno Setup (too complicated for such a simple task) or using a self-extracting zip file (but how to delete files after that)?

Thanks!

+6
delphi extraction
source share
3 answers

I am using the resource for my updater. I compiled the resource using brcc32, than compiling the updater. when the updater launches its check, everything is written or updated with new ones. but about this process you need to write correctly, remove privileges when starting your programs.

I am adding the sample code below.

exe.rc file

newprog RCDATA Application.exe 

makeres.bat file

 brcc32 exe.rc 

updater.dpr file

 {$R exe.res} 

single file and procedures

 procedure ExtractRes(resname,fname,ext:string); var rStream:TResourceStream; fStream:TFileStream; fNamex:string; begin fNamex:=ExtractFilePath(Application.ExeName)+fname+'.'+ext; if not fileExists(fnamex) then begin try rStream:=tresourcestream.Create(hinstance,ResName,RT_rcDATA); fStream := TFileStream.Create(fnamex, fmCreate); fStream.CopyFrom(rStream, 0); finally rStream.Free; fstream.Free; end; end; end; procedure TForm1.Timer1Timer(Sender: TObject); var apath:string; begin if Timer1.Enabled then Timer1.Enabled:=false; apath:=ExtractFilePath(Application.ExeName); lblMesg.Caption:='Backup old version'; Application.ProcessMessages; if FileExists(apath+'Application_old.bak') then DeleteFile(apath+'Application_old.bak') ; while FileExists(apath+'Application.exe') do begin RenameFile(apath + 'Application.exe', apath + 'Application_old.bak'); sleep(1); if FileExists(apath+'Application.exe') then begin lblMesg.Caption:='It seems application still running. Waiting for end'; if FileExists(apath+'Application_old.bak') then DeleteFile(apath+'Application_old.bak'); DeleteFile(apath+'Application.exe'); end; Application.ProcessMessages; end; lblMesg.Caption:='Creating New Version..'; Application.ProcessMessages; ExtractRes('Application','Application','exe'); lblMesg.Caption:='Running New Version...'; Application.ProcessMessages; WinExec(pchar(apath+'Application.exe'),sw_show); Application.ProcessMessages; Halt; end; 

I think this may help your 1,2,3 question. For 4, you can extend the code.

+2
source share

Personally, I would use Inno Setup, as it is very well suited for this type of task. Deleting files is very simple using script events and performing your deletion as part of the installation step after installation.

+12
source share

Maybe not Delphi's answer, but if you purchased a license for WinRAR , you can use the built-in simple settings (you compress the sfx file and the script is stored in the comment file)

Very easy to use, can cleanse itself and compress nicely!

0
source share

All Articles