#define SetupAppVersion "2.9.0"
#define SetupOutputDir "output"
#define SetupAppName "FLYINSONO LAB"
#define SetupAppPublisher "VINNO Technology (Suzhou) Co., Ltd ."
#define SetupAppURL "http://www.flyinsono.com"
#define SetupAppExeName "fis.exe"
#define CopyRight "Copyright ?2022 VINNO Corporation. All rights reserved."
#define ProjectFolder "pc_full_client_win"

[setup]
AppId={{708D995C-BDEF-44B0-B162-D480D7180340}
AppName={cm:SetupAppName}
AppVersion={#SetupAppVersion}
AppVerName={cm:SetupAppName} {#SetupAppVersion}
DefaultDirName={userappdata}\{cm:SetupAppName}
OutputBaseFilename=FlyinsonoLab��װ����
VersionInfoDescription={cm:SetupAppName}
VersionInfoProductName={cm:SetupAppName}
VersionInfoCopyright={#CopyRight}
VersionInfoVersion={#SetupAppVersion}
SetupIconFile=flyinsono.ico
UninstallDisplayIcon={app}\flyinsono.ico
OutputDir={#SetupOutputDir}
Compression=lzma2
DisableWelcomePage=yes
DisableReadyPage=yes
DisableProgramGroupPage=yes
DirExistsWarning=no
LanguageDetectionMethod=uilanguage
ShowLanguageDialog=no
ArchitecturesAllowed=x64
ChangesAssociations=yes
PrivilegesRequired=admin



[Languages]
Name: "english"; MessagesFile: "compiler:Languages\English.isl"
Name: "chinese"; MessagesFile: "compiler:Languages\ChineseSimp.isl"

[CustomMessages]
english.SetupAppName=Flyinsono Lab
english.SetupWizarde=Setup Wizard
english.FinishedRestartMessage=To complete the installation of [Flyinsono], Setup must restart your computer.%n%nWould you like to restart now?
english.NotSupportXP=Windows XP is not supported.
english.NotSupportWin7=Windows 7 (without SP1) is not supported. %n%nWould you like to download the Windows 7 SP1 patch now?
chinese.SetupAppName=���������й���վ
chinese.SetupWizarde=��װ��
chinese.FinishedRestartMessage=Ϊ����� [���������й���վ] �İ�װ����װ�򵼱����������ԡ�%n%n��Ҫ����������
chinese.NotSupportXP=���������й���վ�����޷���Windows XPϵͳ�Ͻ��а�װ��
chinese.NotSupportWin7=���������й���վ�����޷���δ��װSP1������Windows 7ϵͳ�Ͻ��а�װ��%n%n��Ҫ����Windows 7 SP1 ������

[Messages]
english.SetupAppTitle=Flyinsono Setup Wizard
english.SetupWindowTitle=Flyinsono Setup Wizard
chinese.SetupAppTitle=���������й���վ��װ��
chinese.SetupWindowTitle=���������й���վ��װ��



[Files]
//onlyifdoesntexist �����ļ������ڵ�ʱ�� ��װ
Source: resource\*; DestDir: {tmp}; Flags: dontcopy solidbreak ; Attribs: hidden system
Source: {#ProjectFolder}\App\*; DestDir: "{app}\App"; Flags: ignoreversion recursesubdirs createallsubdirs; BeforeInstall: BeforeInstallFis
Source: {#ProjectFolder}\CefGlueBrowserProcess\*; DestDir: "{app}\CefGlueBrowserProcess"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: {#ProjectFolder}\SmartPublisher\*; DestDir: "{app}\SmartPublisher"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: {#ProjectFolder}\RtmpServer\*; DestDir: "{app}\RtmpServer"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: {#ProjectFolder}\Resources\*; DestDir: "{app}\Resources"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: {#ProjectFolder}\swiftshader\*; DestDir: "{app}\swiftshader"; Flags: ignoreversion recursesubdirs createallsubdirs;
Source: {#ProjectFolder}\cef.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\FisPrintDrive.exe; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\cef_100_percent.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\cef_200_percent.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\cef_extensions.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\chrome_elf.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\concrt140.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\cvextern.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\d3dcompiler_47.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\devtools_resources.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\fis.exe; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\flyinsono.ico; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\icudtl.dat; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\libcef.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\libEGL.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\libGLESv2.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\libHarfBuzzSharp.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\libSkiaSharp.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\msvcp140.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\msvcp140_1.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\msvcp140_2.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\msvcp140_atomic_wait.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\msvcp140_codecvt_ids.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\snapshot_blob.bin; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\v8_context_snapshot.bin; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\vcruntime140.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\vcruntime140_1.dll; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\resources.pak; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\Versions.txt; DestDir: "{app}"; Flags: ignoreversion;
Source: {#ProjectFolder}\fis.Upgrader.exe; DestDir: "{app}"; Flags: ignoreversion;

Source: extra\en-US.pak; DestDir: "{app}\locales"; Flags: ignoreversion;
Source: extra\zh-CN.pak; DestDir: "{app}\locales"; Flags: ignoreversion;
Source: extra\zh-TW.pak; DestDir: "{app}\locales"; Flags: ignoreversion;
Source: extra\ru.pak; DestDir: "{app}\locales"; Flags: ignoreversion;
Source: extra\dotnet-runtime-6.0.0-win-x64.exe; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\Windows6.1-KB3063858-x64.msu; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\loader.exe; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\updateVersions.bat; DestDir: "{app}"; Flags: ignoreversion;

//�����ݷ�ʽ
[Icons]
Name: "{group}\{cm:SetupAppName}"; Filename: "{app}\loader.exe"; IconFilename: "{app}\flyinsonoLab.ico";
Name: "{commondesktop}\{cm:SetupAppName}"; Filename: "{app}\loader.exe"; IconFilename: "{app}\flyinsonoLab.ico";

[Run]
Filename: "{app}\updateVersions.bat"; Flags: runhidden;
Filename: "{app}\Windows6.1-KB3063858-x64.msu"; Parameters: "/quiet /norestart"; Flags: runascurrentuser shellexec; Check:NeedInstallKB3063858
Filename: "{app}\dotnet-runtime-6.0.0-win-x64.exe"; Parameters: "/quiet"; Flags: runascurrentuser; Check:NeedInstallDotnet6

[UninstallRun]
Filename: "taskkill.exe"; Parameters: "/f /t /im FlyinsonoDaemon.exe"; Flags: runhidden
Filename: "taskkill.exe"; Parameters: "/f /t /im loader.exe"; Flags: runhidden
Filename: "taskkill.exe"; Parameters: "/f /im Xilium.CefGlue.BrowserProcess.exe"; Flags: runhidden
Filename: "taskkill.exe"; Parameters: "/f /t /im fis.exe"; Flags: runhidden

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};C:\VinnoApp\ipp_2018;C:\VinnoApp\HQPostFilter"; Flags: preservestringtype


[code]
#include  'dll.iss'

function IsMatlabInstalled(): Boolean;
var
  MatlabKey: string;
begin
  // MATLAB ע�����ĵ���λ�ã������ʵ�ʰ汾·�����е�����
  MatlabKey := 'SOFTWARE\MathWorks\MATLAB Runtime';

  // �����Ƿ����
  Result := RegKeyExists(HKEY_LOCAL_MACHINE, MatlabKey);
   // ʹ�� Log ������¼���
  if Result then
    Log('MATLAB Runtime is installed.')
  else
    Log('MATLAB Runtime is not installed.');
end;

const
  SHCNE_ASSOCCHANGED = $08000000;
  SHCNF_IDLIST = $00000000;

var
  BackgroundImage, LicenseBackgroundImage, ProgressBarBackgroundImage,ProgressBarImage, MinButton,CloseButton, SetupButton, SelectFolderButton,LicenseCheckBox,LicenseButton, LicenseBackButton, CustomSetupButton:HWND;
  CustomPathEdit:TEdit;
  LicenseRichEditViewer:TRichEditViewer;
  AdPlayerTimer: TTimer;
  ProgressBarMessageHandler:LongInt;
  CustomSetup,NormalSetup:boolean;
  RestartRequired: boolean;



procedure SHChangeNotify(wEventID: integer; uFlags: cardinal; dwItem1, dwItem2: cardinal); external 'SHChangeNotify@shell32.dll stdcall';

procedure SendChangeNotification;
begin
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
end;

procedure TaskKill(FileName: String);
var
  ResultCode: Integer;
begin
    Exec(ExpandConstant('taskkill.exe'),'/f /im ' + '"' + FileName + '"','',SW_HIDE,ewWaitUntilTerminated,ResultCode);
end;

procedure BeforeInstallFis();
begin
TaskKill('FlyinsonoDaemon.exe');
TaskKill('loader.exe');
TaskKill('Xilium.CefGlue.BrowserProcess.exe');
TaskKill('fis.exe');
end;

function IsWindowsXPOr2000: Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);
  if Version.Major = 5 then
  begin
    Result := True;
  end
  else
  begin
    Result := False;
  end;
end;

function IsWindows7:Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);
  if (Version.Major = 6) and (Version.Minor = 1) then
  begin
    if Version.ServicePackMajor = 0 then
    begin
      Result := True;
    end
    else
    begin
      Result := False;
    end;
  end
  else
  begin
    Result := False;
  end;
end;

function IsWindows7SP1:Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);
  if (Version.Major =6) and (Version.Minor = 1) then
  begin
    if Version.ServicePackMajor = 1 then
    begin
      Result := True;
    end
    else
    begin
      Result := False;
    end;
  end
  else
  begin
    Result := False;
  end;
end;

function IsDotnet6Installed: boolean;
begin
  Result := False;
  if FileExists('C:\Program Files\dotnet\host\fxr\6.0.0\hostfxr.dll') then
  begin
    Result := True;
  end
  else
  begin
    Result := False;
  end;
end;


function NeedInstallKB3063858: boolean;
begin
  if (not IsDotnet6Installed) and (IsWindows7SP1) then
  begin
    RestartRequired := true;
    Result := True;
  end
  else
  begin
    RestartRequired := false;
    Result := False;
  end;
end;

function NeedInstallDotnet6: boolean;
begin
  Result := not IsDotnet6Installed;
end;

procedure RestartOS();
var
  Params: string;
  ErrorCode: Integer;
begin
  Params := '-r -t 0';
  //Exec('shutdown', Params, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
  ShellExec('', 'shutdown',Params, '', SW_HIDE, ewNoWait, ErrorCode);
end;


procedure OnCloseButtonClick(HButton:HWND);
begin
 WizardForm.CancelButton.Click;
end;

procedure OnMinButtonClick(HButton:HWND);
begin
 SendMessage(WizardForm.Handle,WM_SYSCOMMAND,61472,0);
end;

procedure OnCustomSetupButtonClick(HButton:HWND);
begin
  if CustomSetup then
  begin
    BtnSetPosition(LicenseCheckBox,22,475,15,15);
    if ExpandConstant('{language}') = 'chinese' then
    begin
      BtnSetPosition(LicenseButton,100,474,108,15);
      BtnSetPosition(CustomSetupButton,560,479,75,15);
    end
    else
    begin
      BtnSetPosition(LicenseButton,100,474,167,15);
      BtnSetPosition(CustomSetupButton,522,479,113,15);
    end;

    CustomPathEdit.Show;
    BtnSetVisibility(SelectFolderButton,true)
    WizardForm.Height:=508
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_custom_setup_{language}.png'),0,0,650,508,true,true);
    CustomSetup := false
  end
  else
  begin
    BtnSetPosition(LicenseCheckBox,22,421,15,15);
    if ExpandConstant('{language}') = 'chinese' then
    begin
      BtnSetPosition(LicenseButton,100,420,108,15);
      BtnSetPosition(CustomSetupButton,560,421,75,15);
    end
    else
    begin
      BtnSetPosition(LicenseButton,100,420,167,15);
      BtnSetPosition(CustomSetupButton,522,421,113,15);
    end;

    CustomPathEdit.Hide;
    BtnSetVisibility(SelectFolderButton,false)
    WizardForm.Height:=450
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_normal_{language}.png'),0,0,650,450,false,true);
    CustomSetup := true
  end;
  ImgApplyChanges(WizardForm.Handle)
end;

procedure OnSelectFolderButtonclick(HButton:HWND);
begin
  WizardForm.DirBrowseButton.Click;
  CustomPathEdit.text := WizardForm.DirEdit.text;
end;

procedure CustomPathEditChange(Sender: TObject);
begin
  if CustomPathEdit.Text <> '' then
  begin
    WizardForm.DirEdit.text:=CustomPathEdit.Text;
  end;
end;

procedure OnLicenseCheckBoxClick(HButton:HWND);
begin
    if BtnGetChecked(LicenseCheckBox)=true then
    begin
       BtnSetEnabled(SetupButton,true)
    end
    else
    begin
       BtnSetEnabled(SetupButton,false)
    end
end;

procedure OnSetupButtonClick(HButton:HWND);
begin
  WizardForm.NextButton.Click;
end;


procedure OnFinishButtonClick(HButton:HWND);
   var
   ErrorCode: Integer;
begin
  SendChangeNotification;
  if RestartRequired then
  begin
    if MsgBox(CustomMessage('FinishedRestartMessage'),mbConfirmation,MB_YESNO)  = IDYES then
    begin
      RestartOS();
    end;
  end;

  ShellExec('open', ExpandConstant('{app}\loader.exe'),'', '', SW_SHOW, ewNoWait, ErrorCode);
  WizardForm.NextButton.Click;
end;


function ProcessProgressBarMessage(h:hWnd;Msg,wParam,lParam:Longint):Longint;
var
  pr,i1,i2 : Extended;
  w : Integer;
begin
  Result:=CallWindowProc(ProgressBarMessageHandler,h,Msg,wParam,lParam);
  if (Msg=$402) and (WizardForm.ProgressGauge.Position>WizardForm.ProgressGauge.Min) then
  begin
    i1:=WizardForm.ProgressGauge.Position-WizardForm.ProgressGauge.Min;
    i2:=WizardForm.ProgressGauge.Max-WizardForm.ProgressGauge.Min;
    pr:=i1*100/i2;
    w:=Round(650*pr/100);
    ImgSetPosition(ProgressBarImage,0,375,w,15);
    ImgSetVisiblePart(ProgressBarImage,0,0,w,15);
    ImgApplyChanges(WizardForm.Handle);
  end;
end;


procedure OnWizardMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(WizardForm.Handle, $0112, $F012, 0);
end;

var
 b1,b2,b3,b4,t1,t2,t3,t4:Longint;
 playStep:Integer;
 playIndex:Integer;
 waitTime:Integer;

procedure OnAdPlayerTimerTimer(Sender: TObject);   //���Ĵ��� ʱ�ӿ��ƶ��� ��Ҫinno5 ��ǿ��
begin
  if playIndex > 5 then
  begin
    playIndex := 1;
    playStep := 0;
  end;

  if waitTime >0 then
  begin
    waitTime := waitTime - 10;
    Exit;
  end;

  playStep := playStep + 10;

  if playStep<=650 then
  begin
      //������ʾͼƬ
    if playIndex=1 then
    begin
     ImgSetPosition(t1,-650+playStep,0,650,374);
     ImgSetVisibility(t2,false);
     ImgSetVisibility(t3,false);
     ImgSetVisibility(t4,false);
     ImgSetVisibility(t1,true);
    end;
    if playIndex=2 then
    begin
      ImgSetPosition(t2,-650+playStep,0,650,374);
      ImgSetVisibility(t1,false);
      ImgSetVisibility(t3,false);
      ImgSetVisibility(t4,false);
      ImgSetVisibility(t2,true);
      ImgSetVisibility(b1,true);
      ImgSetVisibility(b3,false);
      ImgSetVisibility(b4,false);
      ImgSetVisibility(b2,false);
    end;
    if playIndex=3 then
    begin
      ImgSetPosition(t3,-650+playStep,0,650,374);
      ImgSetVisibility(t1,false);
      ImgSetVisibility(t2,false);
      ImgSetVisibility(t4,false);
      ImgSetVisibility(t3,true);
      ImgSetVisibility(b1,false);
      ImgSetVisibility(b3,false);
      ImgSetVisibility(b4,false);
      ImgSetVisibility(b2,true);
    end;
    if playIndex=4 then
    begin
      ImgSetPosition(t4,-650+playStep,0,650,374);
      ImgSetVisibility(t1,false);
      ImgSetVisibility(t2,false);
      ImgSetVisibility(t3,false);
      ImgSetVisibility(t4,true);
      ImgSetVisibility(b1,false);
      ImgSetVisibility(b3,true);
      ImgSetVisibility(b4,false);
      ImgSetVisibility(b2,false);
    end ;
    if playIndex=5 then
    begin
      ImgSetPosition(t1,-650+playStep,0,650,374);
      ImgSetVisibility(t2,false);
      ImgSetVisibility(t3,false);
      ImgSetVisibility(t4,false);
      ImgSetVisibility(t1,true);
      ImgSetVisibility(b1,false);
      ImgSetVisibility(b3,false);
      ImgSetVisibility(b4,true);
      ImgSetVisibility(b2,false);
    end;
  end;

  if playStep >= 650 then
  begin
    waitTime := 2000;
    playIndex := playIndex + 1;
    playStep := 0;
  end;
  ImgApplyChanges(WizardForm.Handle)
end;

procedure OnLicenseBackButtonClick(HButton:HWND);
begin
  if CustomSetup=false then
  begin
    BtnSetPosition(LicenseCheckBox,22,420,15,15);
    if ExpandConstant('{language}') = 'chinese' then
    begin
      BtnSetPosition(LicenseButton,100,420,108,15);
      BtnSetPosition(CustomSetupButton,560,421,75,15);
    end
    else
    begin
      BtnSetPosition(LicenseButton,100,420,167,15);
      BtnSetPosition(CustomSetupButton,522,421,113,15);
    end;

    CustomPathEdit.Hide;
    BtnSetVisibility(SelectFolderButton,false)
    WizardForm.Height:=450
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_normal_{language}.png'),0,0,650,450,false,true);
    CustomSetup := true
  end;
  if NormalSetup=true then
  begin
    LicenseBackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_license_{language}.png'),0,0,650,444,false,false);
    NormalSetup:=false
    LicenseRichEditViewer.Height:=321
    BtnSetVisibility(LicenseCheckBox,false)
    BtnSetVisibility(LicenseButton,false)
    BtnSetVisibility(CustomSetupButton,false)
    BtnSetVisibility(SetupButton,false)
    BtnSetVisibility(LicenseBackButton,true)
  end
  else
  begin
    NormalSetup:=true
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_normal_{language}.png'),0,0,650,450,false,true);
    LicenseRichEditViewer.Height:=0
    BtnSetVisibility(LicenseCheckBox,true)
    BtnSetVisibility(LicenseButton,true)
    BtnSetVisibility(CustomSetupButton,true)
    BtnSetVisibility(SetupButton,true)
    ImgRelease(LicenseBackgroundImage)
    BtnSetVisibility(LicenseBackButton,false)
  end;
    ImgApplyChanges(WizardForm.Handle)
end;

procedure InitializeWizard();
var
  rtfstr:AnsiString;
begin
  WizardForm.OuterNotebook.hide;
  WizardForm.Bevel.Hide;
  WizardForm.BorderStyle:=bsnone;
  WizardForm.Position:=poScreenCenter;
  WizardForm.Width:=650;
  WizardForm.Height:=508;
  WizardForm.Color:=clWhite ;
  NormalSetup:=true;

  WizardForm.OnMouseDown:=@OnWizardMouseDown
  CustomSetup := true;


  ExtractTemporaryFile(ExpandConstant('license_{language}.rtf'));

  ExtractTemporaryFile(ExpandConstant('edit_custom_folder_{language}.png'));

  ExtractTemporaryFile(ExpandConstant('bg_license_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('bg_normal_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('bg_custom_setup_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('bg_finish_{language}.png'));

  ExtractTemporaryFile(ExpandConstant('bg_progress_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('progress_{language}.png'));

  ExtractTemporaryFile(ExpandConstant('license_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('loading_pic_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('loading_pic1_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('loading_pic2_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('loading_pic3_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('loading_pic4_{language}.png'));

  ExtractTemporaryFile(ExpandConstant('checkbox_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('checkboxdeep_{language}.png'));

  ExtractTemporaryFile(ExpandConstant('btn_setup_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_custom_setup_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_select_folder_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_back_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_complete_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_close_{language}.png'));
  ExtractTemporaryFile(ExpandConstant('btn_min_{language}.png'));

  CloseButton:=BtnCreate(WizardForm.Handle,627,8,17,15,ExpandConstant('{tmp}\btn_close_{language}.png'),1,False)
  BtnSetEvent(CloseButton,BtnClickEventID,WrapBtnCallback(@OnCloseButtonClick,1));

  MinButton:=BtnCreate(WizardForm.Handle,603,8,17,15,ExpandConstant('{tmp}\btn_min_{language}.png'),1,False)
  BtnSetEvent(MinButton,BtnClickEventID,WrapBtnCallback(@OnMinButtonClick,1));

  SetupButton:=BtnCreate(WizardForm.Handle,225,308,199,58,ExpandConstant('{tmp}\btn_setup_{language}.png'),1,False)
  BtnSetEvent(SetupButton,BtnClickEventID,WrapBtnCallback(@OnSetupButtonClick,1));

  LicenseBackButton:=BtnCreate(WizardForm.Handle,274,380,102,42,ExpandConstant('{tmp}\btn_back_{language}.png'),1,False)
  BtnSetEvent(LicenseBackButton,BtnClickEventID,WrapBtnCallback(@OnLicenseBackButtonClick,1));
  BtnSetVisibility(LicenseBackButton,false)

  CustomPathEdit:= TEdit.Create(WizardForm);

  with CustomPathEdit do
  begin
    Parent := WizardForm;
    text :=WizardForm.DirEdit.text;
    Font.Name:='Microsoft YaHei'
    BorderStyle:=bsNone;
    SetBounds(60,383,440,24)
    OnChange:=@CustomPathEditChange;
    Color := $00524A49
    TabStop :=false;
  end;
  CustomPathEdit.Hide;
  SelectFolderButton := BtnCreate(WizardForm.Handle,520,375,75,32,ExpandConstant('{tmp}\btn_select_folder_{language}.png'),1,False)
  BtnSetEvent(SelectFolderButton,BtnClickEventID,WrapBtnCallback(@OnSelectFolderButtonclick,1));
  BtnSetVisibility(SelectFolderButton,false)

  if ExpandConstant('{language}') = 'chinese' then
  begin
    CustomSetupButton:=BtnCreate(WizardForm.Handle,560,421,75,15,ExpandConstant('{tmp}\btn_custom_setup_{language}.png'),1,False)
  end
  else
  begin
    CustomSetupButton:=BtnCreate(WizardForm.Handle,522,421,113,15,ExpandConstant('{tmp}\btn_custom_setup_{language}.png'),1,False)
  end;
  BtnSetEvent(CustomSetupButton,BtnClickEventID,WrapBtnCallback(@OnCustomSetupButtonClick,1));

  ProgressBarMessageHandler:=SetWindowLong(WizardForm.ProgressGauge.Handle,-4,PBCallBack(@ProcessProgressBarMessage,4));

  AdPlayerTimer := TTimer.Create(WizardForm);
  with AdPlayerTimer do
  begin
    OnTimer := @OnAdPlayerTimerTimer;
  end;
  playIndex := 1;
  playStep := 0;
  waitTime := 2000;


  LoadStringFromFile(ExpandConstant('{tmp}\license_{language}.rtf'), rtfstr);
  LicenseRichEditViewer:= TRichEditViewer.Create(WizardForm);
  with LicenseRichEditViewer do
  begin
    Parent := WizardForm;
    ReadOnly:= true;
    ScrollBars:= ssVertical;
    Font.Name:='Microsoft YaHei'
    Color:=clWhite;
    BorderStyle:= bsNone;
    SetBounds(42,36,567,187)
    TabStop:=false;
    Height := 0;
    RTFText := rtfstr;
    UseRichEdit := true;
  end;
  ImgApplyChanges(WizardForm.Handle)
end;

function InitializeSetup(): Boolean;
var
  ErrorCode: Integer;
begin
  if IsWindowsXPOr2000 then
  begin
    MsgBox(CustomMessage('NotSupportXP'), mbError, MB_OK);
  end
  else
  if IsWindows7 then
  begin
    // ���ǻ��ѯ���û�����Win7SP1 ����
    if MsgBox(CustomMessage('NotSupportWin7'), mbConfirmation, MB_YESNO) = IDYES then
    begin
      ShellExec('open', 'https://download.fis.plus/windows6.1-KB976932-X64.exe','', '', SW_SHOW, ewNoWait, ErrorCode);
    end;
  end
  else
  begin
    Result := True;
  end;
end;

procedure DeinitializeSetup();
begin
  gdipShutdown;
  if ProgressBarMessageHandler<>0 then
  begin
    SetWindowLong(WizardForm.ProgressGauge.Handle,-4,ProgressBarMessageHandler);
  end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  WizardForm.NextButton.Visible:=false;
  WizardForm.CancelButton.Height:=0;
  WizardForm.BackButton.Height:=0;

  if CurPageID = wpWelcome then
  begin
    WizardForm.NextButton.OnClick(WizardForm);
  end;

  if CurPageID=wpSelectDir then
  begin
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_normal_{language}.png'),0,0,650,450,true,true);
    if ExpandConstant('{language}') = 'chinese' then
    begin
      LicenseButton:=BtnCreate(WizardForm.Handle,102,420,108,16,ExpandConstant('{tmp}\license_{language}.png'),4,false)
    end
    else
    begin
      LicenseButton:=BtnCreate(WizardForm.Handle,100,420,167,15,ExpandConstant('{tmp}\license_{language}.png'),4,false)
    end;
    BtnSetEvent(LicenseButton,BtnClickEventID,WrapBtnCallback(@OnLicenseBackButtonClick,1));
    LicenseCheckBox:=BtnCreate(WizardForm.Handle,22,421,15,15,ExpandConstant('{tmp}\checkboxdeep_{language}.png'),1,true)
    BtnSetEvent(LicenseCheckBox,BtnClickEventID,WrapBtnCallback(@OnLicenseCheckBoxClick,1));
    BtnSetChecked(LicenseCheckBox,true)
    WizardForm.Width:=650;
    WizardForm.Height:=450;
    WizardForm.Show;
  end ;
  if CurPageID = wpInstalling then
  begin
    BtnSetPosition(LicenseCheckBox,560,421,75,15);
    if ExpandConstant('{language}') = 'chinese' then
    begin
      BtnSetPosition(CustomSetupButton,560,421,75,15);
    end
    else
    begin
      BtnSetPosition(CustomSetupButton,522,421,113,15);
    end;
    CustomPathEdit.Hide;
    BtnSetVisibility(SelectFolderButton,false)
    WizardForm.Height:=450
    CustomSetup := true
    BtnSetVisibility(CustomSetupButton,false);
    BtnSetVisibility(LicenseButton,false);
    BtnSetVisibility(LicenseCheckBox,false);
    BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\loading_pic_{language}.png'),0,0,650,450,false,true);

    ProgressBarBackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_progress_{language}.png'),0,375,660,15,true,true);
    ProgressBarImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\progress_{language}.png'),0,375,0,0,True,True);

    t1:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\loading_pic1_{language}.png'),0,0,650,374,true,true);    //����ͼƬ�ر���
    t2:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\loading_pic2_{language}.png'),0,0,650,374,true,true);
    t3:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\loading_pic3_{language}.png'),0,0,650,374,true,true);
    t4:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\loading_pic4_{language}.png'),0,0,650,374,true,true);


    ImgSetVisibility(t1,false)     //���ֶ���ʱ ��һ����ʾ��ͼƬ   ���漸�Ž��õ�
    ImgSetVisibility(t2,false)
    ImgSetVisibility(t3,false)
    ImgSetVisibility(t4,false)

    BtnSetVisibility(SetupButton,false);

    AdPlayerTimer.Interval:= 10;
  end ;

  if CurPageID = wpFinished then
  begin
   AdPlayerTimer.Interval:=0
   ImgSetVisibility(ProgressBarBackgroundImage,false)
   ImgSetVisibility(ProgressBarImage,false)
   SetupButton:=BtnCreate(WizardForm.Handle,245,358,160,50,ExpandConstant('{tmp}\btn_complete_{language}.png'),1,False)
   BtnSetEvent(SetupButton,BtnClickEventID,WrapBtnCallback(@OnFinishButtonClick,1));
   BackgroundImage:=ImgLoad(WizardForm.Handle,ExpandConstant('{tmp}\bg_finish_{language}.png'),0,0,650,450,false,true);
   BtnSetEvent(CloseButton,BtnClickEventID,WrapBtnCallback(@OnSetupButtonClick,1));
  end;
  ImgApplyChanges(WizardForm.Handle)
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  if (PageID=wpSelectComponents) or (PageID=wpSelectTasks) then    //���������װ����
  begin
    result := true;
  end;
end;