[Setup]
AppName=Demo
AppVerName=Demo 1.0
AppPublisher=Gerich
AppPublisherURL=http://w4tweaks.ucoz.ru/
AppSupportURL=http://w4tweaks.ucoz.ru/
AppUpdatesURL=http://w4tweaks.ucoz.ru/
DisableDirPage=yes
DisableProgramGroupPage=yes
DefaultDirName={pf}\W4MapPackLauncher\installed\Demo
DefaultGroupName=W4MapPackLauncher\Maplists\Demo
OutputDir=C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects
OutputBaseFilename=Demo
SetupIconFile=C:\Program Files\Borland\Delphi7\Projects\W4MapPackEditor1.0\iscc\setup.ico
Compression=lzma
SolidCompression=yes

[Languages]
Name: "russian"; MessagesFile: "compiler:Languages\russian.isl"
Name: "english"; MessagesFile: "compiler:Default.isl"

[CustomMessages]
CopyingFiles = Copying files to Worms 4 Mayhem directory
CopyingFilesLong = All needed files will be copyed to Worms 4 Mayhem directory and to W4MapPackLauncher.
Backup = Select files to copy and backup
BackupLong = If you have some changed files, you should select to replace these files with standart files. You can also backup them
WormsNotFound = Worms 4 Mayhem not found
LauncherNotFound = W4MapPackLauncher not found. Visit http://w4tweaks.ucoz.ru/index/0-6
Progress = Copying file

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,Demo}"; Filename: "http://w4tweaks.ucoz.ru/"
Name: "{group}\{cm:UninstallProgram,Demo}"; Filename: "{uninstallexe}"

[Files]
Source: "C:\Program Files\Borland\Delphi7\Projects\W4MapPackEditor1.0\iscc\maplists\Demo.mpl"; DestName:"1.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demo\demo.htm"; DestName:"3.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demo\demo rus.htm"; DestName:"4.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demo\logo.jpg"; DestName:"5.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\black black.xan"; DestName:"7.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\Cubos3.xan"; DestName:"8.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\rcdd basketball.xan"; DestName:"9.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\black black.hmp"; DestName:"11.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\Cubos3.hmp"; DestName:"12.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\rcdd basketball.hmp"; DestName:"13.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\black black.tga"; DestName:"15.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\Cubos3.tga"; DestName:"16.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\rcdd basketball.tga"; DestName:"17.tmp"; Flags: dontcopy
Source: "C:\Program Files\Codemasters\Worms 4 Mayhem\mappackprojects\demofiles\cubos3.txt"; DestName:"19.tmp"; Flags: dontcopy

[UninstallDelete]
Type: filesandordirs; Name: "{code:getLauncherDir}\maplists\Demo.mpl"

[Code]
var
  CountToCopy:integer;
  LauncherDir,WormsDir: String;
  CopyingFiles: TOutputProgressWizardPage;
  FilesCopyed:integer;

procedure InitializeWizard();
begin
  CopyingFiles:=CreateOutputProgressPage(ExpandConstant('{cm:CopyingFiles}'), ExpandConstant('{cm:CopyingFilesLong}'));
end;

function InitializeUninstall(): Boolean;
begin
  RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Gerich\W4MapPackLauncher','AppDir', LauncherDir);
  RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Gerich\W4MapPackLauncher', 'WormsDir', WormsDir);
  result:=true;
end;

function getLauncherDir(Param: String): String;
begin
  result:=LauncherDir;
end;

procedure CopyToWorms(FileToExtract:string;Where:string;realname:string);
var
  Dest:string;
begin
  CopyingFiles.SetText(ExpandConstant('{cm:Progress}'),FileToExtract);
  Dest:=WormsDir+Where+realname;
  ExtractTemporaryFile(FileToExtract);
  if FileExists(Dest) then
  begin
    if not DirExists(WormsDir+Where+'backup\') then
      CreateDir(WormsDir+Where+'backup\');
    FileCopy(Dest,WormsDir+Where+'backup\'+FileToExtract,true);
  end;
  FileCopy(ExpandConstant('{tmp}\')+FileToExtract,Dest,false);
  FilesCopyed:=FilesCopyed+1;
  CopyingFiles.SetProgress(FilesCopyed,CountToCopy);
end;

procedure CopyToMaplists(FileToExtract:string;Where:string;realname:string);
var
  Dest:string;
begin
  CopyingFiles.SetText(ExpandConstant('{cm:Progress}'),FileToExtract);
  Dest:=LauncherDir+'maplists\'+Where+realname;
  ExtractTemporaryFile(FileToExtract);
  if FileExists(Dest) then
  begin
    if not DirExists(LauncherDir+'maplists\'+Where+'backup\') then
      CreateDir(LauncherDir+'maplists\'+Where+'backup\');
    FileCopy(Dest,LauncherDir+'maplists\'+Where+'backup\'+realname,true);
  end;
  FileCopy(ExpandConstant('{tmp}\')+FileToExtract,Dest,false);
  FilesCopyed:=FilesCopyed+1;
  CopyingFiles.SetProgress(FilesCopyed,CountToCopy);
end;

procedure CreateSubDir(dir:string;Where:string);
begin
  if DirExists(LauncherDir+'maplists\'+Where) then
    CreateDir(LauncherDir+'maplists\'+Where+dir);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result:=True;
  case CurPageID of
    wpReady:
    begin
      if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Gerich\W4MapPackLauncher','AppDir', LauncherDir) then
      begin
        if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Gerich\W4MapPackLauncher', 'WormsDir', WormsDir) then
        begin
          if not DirExists(LauncherDir+'maplists\') then
            CreateDir(LauncherDir+'maplists\')
        end
        else
        begin
          MsgBox(ExpandConstant('{cm:WormsNotFound}'), mbInformation, MB_OK);
          Result := False;
          exit;
        end;
      end
      else
      begin
        MsgBox(ExpandConstant('{cm:LauncherNotFound}'), mbInformation, MB_OK);
        Result := False;
        exit;
      end;
      try
        begin
          FilesCopyed:=0;
          CountToCopy:=15;
          CopyingFiles.Show;
          CreateSubDir('Demo\','');
          CopyToMaplists('1.tmp','','Demo.mpl');
          CopyToMaplists('3.tmp','Demo\','demo.htm');
          CopyToMaplists('4.tmp','Demo\','demo rus.htm');
          CopyToMaplists('5.tmp','Demo\','logo.jpg');
          CopyToWorms('7.tmp','data\maps\','black black.xan');
          CopyToWorms('8.tmp','data\maps\','Cubos3.xan');
          CopyToWorms('9.tmp','data\maps\','rcdd basketball.xan');
          CopyToWorms('11.tmp','data\maps\','black black.hmp');
          CopyToWorms('12.tmp','data\maps\','Cubos3.hmp');
          CopyToWorms('13.tmp','data\maps\','rcdd basketball.hmp');
          CopyToWorms('19.tmp','data\maps\','cubos3.txt');
          CopyToWorms('15.tmp','data\frontend\levels\','black black.tga');
          CopyToWorms('16.tmp','data\frontend\levels\','Cubos3.tga');
          CopyToWorms('17.tmp','data\frontend\levels\','rcdd basketball.tga');
        end;
      finally
        CopyingFiles.Hide;
      end;
    end;
  end;
end;
