; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define SysDrive  GetEnv('SystemDrive')
#define ProdName  "crwdaq"
#define ExecFile  "crwdaq.exe"
#define ExecName  "\crwdaq\crwdaq.exe"
#define Name      "CRW-DAQ"
#define Product   "CRW-DAQ for Windows"
#define ProdDir   "\opt\daqgroup\suite"
#define OutputID  "install-daqgroup-crwdaq"
#define OutputDir "\opt\daqgroup"
#define Publisher "DaqGroupTeam"
#define Contact   "mailto:daqgroup@mail.ru"
#define ProdURL   "http://www.crw-daq.su/"
#define Version   GetDateTimeString('yyyymmdd', '', '')
#define Comments  "Data acquisition, process control and analysis system for Windows"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D41386CF-0675-4283-A20F-6BAF66690267}
AppName={#ProdName}
AppVersion={#Version}
; AppVerName={#ProdName} {#Version}
AppComments={#Comments}
AppPublisher={#Publisher}
AppPublisherURL={#Contact}
AppSupportURL={#Contact}
AppUpdatesURL={#ProdURL}
DefaultDirName={sd}{#ProdDir}
DisableDirPage=yes
DefaultGroupName={#ProdName}
DisableProgramGroupPage=yes
LicenseFile={#SysDrive}{#ProdDir}\crwdaq\license.md
OutputDir={#SysDrive}{#OutputDir}
OutputBaseFilename={#OutputID}
SetupIconFile={#SysDrive}{#ProdDir}\crwdaq\crwdaq.ico
Compression=lzma
SolidCompression=yes

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

[Tasks]
Name: "deleteoldversion"; Description: "Удалить старую версию"

[Files]
Source: "{#SysDrive}{#ProdDir}\crwdaq\*"; DestDir: "{app}\crwdaq"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#SysDrive}{#ProdDir}\crwkit\*"; DestDir: "{app}\crwkit"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#SysDrive}{#ProdDir}\crwlib\*"; DestDir: "{app}\crwlib"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#SysDrive}{#ProdDir}\crwdaq\resource\launch\crwlnk\*"; DestDir: "{group}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#Name}}"; Filename: "{#ProdURL}"

[Messages]
BeveledLabel= CRW-DAQ Setup

; Delete old version before installing
[InstallDelete]
; Type: filesandordirs; Name: "{app}.old\*"; Tasks: delprevver
; Type: filesandordirs; Name: "{app}.old"; Tasks: delprevver

[Run]
Filename: "{app}\crwdaq\resource\shell\grun.exe"; Parameters: "-cwh rmdir /S /Q {app}.old"; WorkingDir: "{app}"; Flags: skipifdoesntexist runhidden; Description: "Удалить старую версию"; StatusMsg: "Удаление старой версии..."; Tasks: deleteoldversion; Check: IsInstalled

[Code]
{
Program is installed detected
}
function IsInstalled:Boolean;
begin
  Result:=False;
//   if FileExists('{#SysDrive}{#ProdDir}{#ExecName}') then Result:=True;
  if DirExists('{#SysDrive}{#ProdDir}') then Result:=True;
end;

{
Main setup initialization
}
function InitializeSetup(): Boolean;
var
  OldName: String;
  NewName: String;
begin
  OldName:='{#SysDrive}{#ProdDir}';
  NewName:=OldName+'.old';
  if IsInstalled then RenameFile(OldName, NewName);
  Result:=True;
end;
