Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-extracting Delphi program

I'm writing an updater program in Delphi7 which will be run once, but needs many files to run.

What I'd like the achieve:

  1. User runs exe
  2. Exe unpacks files, runs updater
  3. If updater detects and error, prompts the user to send log in e-mail
  4. After the updater is run, temporary files are deleted (some of these files are dlls used by the updater program, so the updater has to be closed before the files can be deleted)

Can anyone recommend a good solution? I've thought about using Inno Setup (too complicated for such an easy task) or using a self-extracting zip file (but how to delete the files afterwards)?

Thanks!

like image 854
Steve Avatar asked Apr 26 '10 19:04

Steve


2 Answers

Personally I would use Inno Setup, as it is very well suited for this type of task. Deleting files is very easy using scripting events, and performing your delete as part of the post installer step.

like image 103
skamradt Avatar answered Nov 13 '22 03:11

skamradt


I am using resource for my update program. i was compile resource with brcc32 than compile updater program. when updater program run its self check everything and write or update with new ones. but about this process you have to right write,delete privileges at where your programs run.

i am adding a sample code to below.

file exe.rc

newprog RCDATA Application.exe

file makeres.bat

brcc32 exe.rc

file updater.dpr

{$R exe.res}

unit 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 can help your 1,2,3 question. For 4 you can extend code.

like image 44
sabri.arslan Avatar answered Nov 13 '22 03:11

sabri.arslan