#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
DiskSpanning=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: extra\VinnoApp\*; DestDir: "C:\VinnoApp"; Flags: recursesubdirs createallsubdirs ignoreversion onlyifdoesntexist;
Source: extra\MATLAB_Runtime_R2020b_Update_8_win64\*; DestDir: "{app}\MATLAB_Runtime_R2020b_Update_8_win64"; Flags: recursesubdirs createallsubdirs ignoreversion 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: flyinsono.ico; DestDir: "{app}"; Flags: ignoreversion;
Source: flyinsonolab.ico; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\flyinsono_Web.ico; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\updateVersions_All.bat; DestDir: "{app}"; Flags: ignoreversion;
Source: extra\FlyinsonoLabServer\*; DestDir: "C:\FlyinsonoLabServer"; Flags: ignoreversion recursesubdirs createallsubdirs;

//桌面快捷方式
[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";
Name: "{commondesktop}\杏聆荟科研工作站-管理后台"; Filename: "http://127.0.0.1:9302"; IconFilename: "{app}\flyinsono_Web.ico";

[Run]
Filename: "{app}\updateVersions_All.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
Filename: "{app}\MATLAB_Runtime_R2020b_Update_8_win64\setup.exe"; Parameters: "-mode silent -agreeToLicense yes"; Flags: runascurrentuser waituntilterminated; Check:not IsMatlabInstalled

[UninstallDelete]
Type: filesandordirs; Name: "C:\FlyinsonoLabServer"

[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
Filename: "C:\FlyinsonoLabServer\close.bat"; Parameters: ""; Flags: runhidden skipifdoesntexist


[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'

procedure CurStepChanged(CurStep: TSetupStep);
var
  ResultCode: Integer;
begin
  if CurStep = ssInstall then
  begin
    // 调用批处理文件
    Exec(ExpandConstant('C:\FlyinsonoLabServer\close.bat'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
  end;
end;

function IsMatlabInstalled(): Boolean;
var
  MatlabKey: string;
begin
  // MATLAB 注册表项的典型位置
  MatlabKey := 'SOFTWARE\MathWorks\MATLAB Runtime';

  // 初始化结果为 false
  Result := False;

  // 尝试读取 64 位视图下的注册表键
  if RegKeyExists(HKEY_LOCAL_MACHINE_64, MatlabKey) then
  begin
    Result := True;
    Log('MATLAB Runtime is installed at ' + MatlabKey);
  end
  else
  begin
    Log('MATLAB Runtime is not installed at ' + MatlabKey);
  end;
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 ExecuteBatchIfPresent();
var
  BatchFilePath: String;
  ResultCode: Integer;
begin
  BatchFilePath := ExpandConstant('C:\FlyinsonoLabServer\close.bat');
  if FileExists(BatchFilePath) then
  begin
      Exec(BatchFilePath, '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) 
  end;
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');
TaskKill('nginx.exe');
TaskKill('cmd.exe');
ExecuteBatchIfPresent();
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,474,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,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,421,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;