inno setup腳本,涵蓋了自定義安裝界面,調用dll等等應用


; Script generated by the Inno Setup 腳本向導.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

; 為1的時候表示定義成試用版本
#define VERSION_TYPE ReadIni('Setup.ini', 'SetupType', 'type', '0')

#if VERSION_TYPE == "2"
    #define LIVE_VERSION
    #define MyAppName "流媒體系統(PMS)"
    #define MyAppId "1954A698-2322-46F1-B732-8DDF96693DA5"
    #define MyOutputBaseFilename "live_server_setup"
#elif VERSION_TYPE == "1"
    #define VOD_VERSION
    #define MyAppName "流媒體系統(PMS)"
    #define MyAppId "DA255679-F103-4170-8B75-B9A7EF4CBC1B"
    #define MyOutputBaseFilename "vod_server_setup"
#else
    #define FULL_VERSION
    #define MyAppName "流媒體系統(PMS)"
    #define MyAppId "4AC618B5-8C69-4D47-918A-261AA895B6D7"
    #define MyOutputBaseFilename "full_server_setup"
#endif

#define RegUrl "http://www.xxx.net"
#define MyAppVersion "1.0"
#define MyAppPublisher "XXX科技有限公司"
#define MyAppURL "http://www.xxx.net"
#define MyAppExeName "InstanceConfig.exe"

[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={{{#MyAppId}}
AppMutex={{{#MyAppId}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\xxx\media server
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile=license.txt
OutputDir=output
OutputBaseFilename={#MyOutputBaseFilename}
SetupIconFile=setup.ico
Compression=lzma
SolidCompression=yes

VersionInfoVersion={#MyAppVersion}
VersionInfoCompany={#MyAppPublisher}
VersionInfoCopyright=Copyright (C) 2010-2013
VersionInfoProductName={#MyAppName}
VersionInfoProductVersion={#MyAppVersion}

[Languages]
Name: cn; MessagesFile: compiler:Languages\chinese.isl

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
; 用來檢測安裝程序中輸入的注冊碼是否有效
Source: ..\build\register_help.dll; Flags: dontcopy
Source: ..\build\libeay32.dll; Flags: dontcopy
Source: ..\build\vcredist2008_x86.exe; Flags: dontcopy

#ifdef FULL_VERSION
Source: ..\build\server.conf; DestDir: {app}
Source: ..\build\media_service.exe; DestDir: {app}
Source: ..\build\libmysql.dll; DestDir: {app}
Source: ..\build\libeay32.dll; DestDir: {app}
Source: ..\build\zlib1.dll; DestDir: {app}
Source: ..\build\register_check.exe; DestDir: {app}
Source: ..\build\QtCore4.dll; DestDir: {app}
Source: ..\build\QtGui4.dll; DestDir: {app}
Source: ..\build\mglobal.dll; DestDir: {app}
Source: ..\build\msvcp100.dll; DestDir: {app}
Source: ..\build\msvcr100.dll; DestDir: {app}
Source: ..\build\initconfig.exe; DestDir: {app}
Source: ..\build\InstanceConfig.exe; DestDir: {app}
;Source: ..\build\php-fpm.exe; DestDir: {app}
Source: ..\build\管理統計頁面.url; DestDir: {app}
Source: ..\build\示例頁面.url; DestDir: {app}

Source: ..\build\launchlist; DestDir: {app}
;Source: ..\build\phpcgi; DestDir: {app}

Source: ..\build\lighttpd.conf; DestDir: {app}\lmp\lighttpd\conf; Flags: ignoreversion
Source: ..\build\my.ini; DestDir: {app}\lmp\mysql; Flags: ignoreversion

; web服務器整套目錄
Source: ..\build\lmp\*; DestDir: {app}\lmp; Flags: recursesubdirs createallsubdirs
; doc文檔目錄
Source: ..\doc\*; DestDir: {app}\help; Flags: recursesubdirs createallsubdirs
; 播放器相關目錄
Source: ..\build\swfs\*; DestDir: {app}\swfs; Flags: recursesubdirs createallsubdirs
; 播放器SDK相關目錄
Source: ..\build\scriptlib\*; DestDir: {app}\scriptlib; Flags: recursesubdirs createallsubdirs

#endif

[Dirs]
Name: {app}\videos

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}

[Icons]
Name: {group}\sample\示例頁面; Filename: {app}\示例頁面.url

Name: {group}\help\安裝說明; Filename: {app}\help\安裝說明.pdf
Name: {group}\help\功能說明; Filename: {app}\help\功能說明.pdf
Name: {group}\help\開發說明; Filename: {app}\help\開發說明.pdf
Name: {group}\help\配置說明; Filename: {app}\help\配置說明.pdf
Name: {group}\help\統計模塊; Filename: {app}\help\統計模塊.pdf

Name: {group}\流媒體系統(PMS)系統配置; Filename: {app}\{#MyAppExeName}
Name: {group}\{cm:UninstallProgram, PMS系統配置}; Filename: {uninstallexe}
Name: {group}\流媒體系統(PMS)統計管理; Filename: {app}\管理統計頁面.url; IconFilename: {app}\{#MyAppExeName};
Name: {commondesktop}\流媒體系統(PMS)統計管理; Filename: {app}\管理統計頁面.url; Tasks: desktopicon; IconFilename: {app}\{#MyAppExeName};
Name: {commondesktop}\流媒體系統(PMS)系統配置; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon
Name: {commondesktop}\開啟PMS服務; Filename: {app}\media_service.exe; Parameters: -r; IconFilename: {app}\{#MyAppExeName}; Tasks: desktopicon
Name: {commondesktop}\停止PMS服務; Filename: {app}\media_service.exe; Parameters: -s; IconFilename: {app}\{#MyAppExeName}; Tasks: desktopicon

[Run]
; 刪除服務
Filename: {app}\media_service.exe; Parameters: -u; Flags: runhidden
; 安裝服務
Filename: {app}\media_service.exe; Parameters: -i; Flags: runhidden

[UninstallRun]
; 停止服務
Filename: {app}\media_service.exe; Parameters: -s; Flags: runhidden
; 刪除服務
Filename: {app}\media_service.exe; Parameters: -u; Flags: runhidden

[CustomMessages]
Key_Form_Caption=注冊向導
Key_Form_Description=將序列號提交給xxx以獲取注冊碼
Key_Form_codeLabel_Caption0=序列號:
Key_Form_keyLabel_Caption0=注冊碼:

Domain_Form_Caption=域名設置
Domain_Form_Description=配置當前服務器域名

[Messages]
BeveledLabel=xxx網絡科技

[Code]
var
    codeLabel: TLabel;
    keyLabel: TLabel;
    key: TMemo;
    code: TMemo;
  keyPage: TWizardPage;
  domainEdit: TNewEdit;
  domainPage: TWizardPage;

// 獲取序列號
function getCode(szCode: PChar; inLen: Integer): Integer;
external 'getCode@files:register_help.dll,libeay32.dll,msvcr100.dll stdcall setuponly delayload loadwithalteredsearchpath';

// 進行檢查
function regCheck(const regKey: PChar): Boolean;
external 'regCheck@files:register_help.dll,libeay32.dll,msvcr100.dll stdcall setuponly delayload loadwithalteredsearchpath';

// 進行注冊
function regSave(const regKey, regPath: PChar): Boolean;
external 'regSave@files:register_help.dll,libeay32.dll,msvcr100.dll stdcall setuponly delayload loadwithalteredsearchpath';

// 清理注冊
procedure regClear(const regPath: PChar);
external 'regClear@files:register_help.dll,libeay32.dll,msvcr100.dll stdcall setuponly delayload loadwithalteredsearchpath';

function OpenSCManager(const machine: LongInt; const dbName: LongInt;  access: Dword):LongInt;
external 'OpenSCManagerA@Advapi32.dll stdcall';

function OpenService(svcMgr: LongInt; const svcName: pchar;  access: Dword):LongInt;
external 'OpenServiceA@Advapi32.dll stdcall';

function CloseServiceHandle(svc: LongInt):Boolean;
external 'CloseServiceHandle@Advapi32.dll stdcall';

///判定服務是否存在
function  serviceExists(name: string): boolean;
var
    SvcMgr, Svc: LongInt;
begin
    Result := False;
    SvcMgr := OpenSCManager(0,0,1);
    if SvcMgr = 0 then Exit;
    Svc := OpenService(SvcMgr, PChar(name), 4);
    if Svc = 0 then
    begin
      CloseServiceHandle(SvcMgr);
      Exit;
    end;
    CloseServiceHandle(Svc);
    CloseServiceHandle(SvcMgr);
    Result := true;
end;

///停止服務
procedure stopService;
var
  ResultCode: Integer;
begin
  Exec(ExpandConstant('{tmp}\media_service.exe'), '-s', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;

{ Key_Form_ShouldSkipPage }

function Key_Form_ShouldSkipPage(Page: TWizardPage): Boolean;
var
    codeStr: String;
begin
    SetLength(codeStr, 1024);
    getCode(PChar(codeStr), 1024);
    code.Text := codeStr;
    Result := False;
end;

// 注冊碼編輯框改變事件
procedure Key_Form_KeyChange(Sender: TObject);
begin
// 檢測注冊碼
    if regCheck(PChar(key.Text)) then
        WizardForm.NextButton.Enabled := True
    else
        WizardForm.NextButton.Enabled := False;
end;

procedure RegURLLabelOnClick(Sender: TObject);
var
  ErrorCode: Integer;
begin
  ShellExec('open', ExpandConstant('{#RegURL}'), '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;

{ Key_Form_CreatePage }
function Key_Form_CreatePage(PreviousPageId: Integer): Integer;
var
  URLLabel: TNewStaticText;
begin
    keyPage := CreateCustomPage(
              PreviousPageId,
              ExpandConstant('{cm:Key_Form_Caption}'),
              ExpandConstant('{cm:Key_Form_Description}')
          );

  { codeLabel }
    codeLabel := TLabel.Create(keyPage);
    with codeLabel do
    begin
        Parent := keyPage.Surface;
        Caption := ExpandConstant('{cm:Key_Form_codeLabel_Caption0}');
        Left := ScaleX(0);
        Top := ScaleY(0);
        Width := ScaleX(40);
        Height := ScaleY(13);
    end;

  { keyLabel }
    keyLabel := TLabel.Create(keyPage);
    with keyLabel do
    begin
        Parent := keyPage.Surface;
        Caption := ExpandConstant('{cm:Key_Form_keyLabel_Caption0}');
        Left := ScaleX(0);
        Top := ScaleY(82);
        Width := ScaleX(40);
        Height := ScaleY(13);
    end;

  { key }
    key := TMemo.Create(keyPage);
    with key do
    begin
        Parent := keyPage.Surface;
        Left := ScaleX(0);
        Top := ScaleY(98);
        Width := ScaleX(410);
        Height := ScaleY(106);
        ScrollBars := ssVertical;
        TabOrder := 0;
    OnChange := @Key_Form_KeyChange;
    end;

  { code }
    code := TMemo.Create(keyPage);
    with code do
    begin
        Parent := keyPage.Surface;
        Left := ScaleX(0);
        Top := ScaleY(16);
        Width := ScaleX(410);
        Height := ScaleY(60);
        ReadOnly := True;
        ScrollBars := ssVertical;
        TabOrder := 1;
    end;

    with keyPage do
    begin
        OnShouldSkipPage := @Key_Form_ShouldSkipPage;
    end;

    Result := keyPage.ID;

  URLLabel := TNewStaticText.Create(keyPage);
  with URLLabel do
  begin
    Caption := '獲取注冊碼';
    Cursor := crHand;
    OnClick := @RegURLLabelOnClick;
    Parent := keyPage.Surface;
    Font.Style := URLLabel.Font.Style + [fsUnderline];
    Font.Color := clBlue;
    Left := ScaleX(350);
    Top := ScaleY(210);
  end;
end;

{ 設置域名頁面相關代碼 }
procedure Domain_Form_EditChange(sender: TObject);
begin
  if domainEdit.Text = '' then
    WizardForm.NextButton.Enabled := False
  else
    WizardForm.NextButton.Enabled := True;
end;

function Domain_Form_CreatePage(PreviousPageId: Integer): Integer;
var
  domainLabel: TNewStaticText;
begin
    domainPage := CreateCustomPage(
              PreviousPageId,
              ExpandConstant('{cm:Domain_Form_Caption}'),
              ExpandConstant('{cm:Domain_Form_Description}')
          );

  domainLabel := TNewStaticText.Create(domainPage);
  with domainLabel do
  begin
    Parent := domainPage.Surface;
    Caption := '請確保輸入的域名是有效的,並指向當前服務器IP,否則可以直接填寫本機' + #13#10 + 'IP地址,或者保持默認值不變';
        Left := ScaleX(0);
        Top := ScaleY(60);
        Width := ScaleX(400);
        Height := ScaleY(28);
  end;
  
  domainEdit := TNewEdit.Create(domainPage);
  with domainEdit do
  begin
    Parent := domainPage.Surface;
    Text := GetComputerNameString;
        Left := ScaleX(0);
        Top := ScaleY(90);
        Width := ScaleX(400);
        Height := ScaleY(13);
    OnChange := @Domain_Form_EditChange;
  end; 
end;

procedure URLLabelOnClick(Sender: TObject);
var
  ErrorCode: Integer;
begin
  ShellExec('open', ExpandConstant('{#MyAppURL}'), '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;

// 安裝初始化
function InitializeSetup(): Boolean;
begin
  if serviceExists('MediaSrv') then
  begin //服務存在,先停止它
    if MsgBox('服務已經存在,要繼續嗎?', mbConfirmation, MB_YESNO) = IDNO then
    begin
      Result := False;
      Exit;
    end;
    ExtractTemporaryFile('media_service.exe');
    ExtractTemporaryFile('msvcr100.dll');
    ExtractTemporaryFile('msvcp100.dll');
    stopService;
  end;
    result := True;
end;

procedure InitializeWizard();
var
  URLLabel: TNewStaticText;
begin
    Key_Form_CreatePage(wpSelectDir);
  Domain_Form_CreatePage(keyPage.ID);

  URLLabel := TNewStaticText.Create(WizardForm);
  with URLLabel do
  begin
    Caption := ExpandConstant('{#MyAppURL}');
    Cursor := crHand;
    OnClick := @URLLabelOnClick;
    Parent := WizardForm;
    Font.Style := URLLabel.Font.Style + [fsUnderline];
    Font.Color := clBlue;
    Left := ScaleX(20);
    Top := WizardForm.ClientHeight - ScaleY(30);
  end;
end;

// 頁面切換事件
procedure CurPageChanged(CurPageID: Integer);
var
  ResultCode: Integer;
  file: String;
  buf: String;
begin
  WizardForm.BackButton.Enabled := True;

  if CurPageID = keyPage.ID then
    WizardForm.NextButton.Enabled := False
  else if CurPageID = wpFinished then
  begin
    ///////////////////////////////////////////////////////////
    // 幫助設置HOST_NAME為用戶設置的域名
    file := ExpandConstant('{app}\lmp\htdocs\sample\config.php');
    if LoadStringFromFile(file, buf) then
    begin
      StringChangeEx(buf, '%HOST_NAME%', domainEdit.Text, False);
      SaveStringToFile(file, buf, False);
    end;

    file := ExpandConstant('{app}\管理統計頁面.url');
    if LoadStringFromFile(file, buf) then
    begin
      StringChangeEx(buf, '%HOST_NAME%', domainEdit.Text, False);
      SaveStringToFile(file, buf, False);
    end;

    file := ExpandConstant('{app}\示例頁面.url');
    if LoadStringFromFile(file, buf) then
    begin
      StringChangeEx(buf, '%HOST_NAME%', domainEdit.Text, False);
      SaveStringToFile(file, buf, False);
    end;
    ///////////////////////////////////////////////////////////

    // 禁用完成按鈕
    WizardForm.NextButton.Enabled := False;
    // 正式寫入注冊文件
    regSave(PChar(key.Text), WizardDirValue);
    // 執行自動初始化
    Exec(ExpandConstant('{app}\initconfig.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
    // 執行配置設置
    Exec(ExpandConstant('{app}\InstanceConfig.exe'), '-r', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
    // 啟動服務
    Exec(ExpandConstant('{app}\media_service.exe'), '-r', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
    // 啟用完成按鈕
    WizardForm.NextButton.Enabled := True;
  end
  else if CurPageID = wpInstalling then
  begin
    // 安裝運行時庫
    ExtractTemporaryFile('vcredist2008_x86.exe');
    // 執行2008庫安裝
    Exec(ExpandConstant('{tmp}\vcredist2008_x86.exe'), '/q', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
  end
  else if CurPageID = domainPage.ID then
  begin
    WizardForm.BackButton.Enabled := False;
  end;
end;

// 卸載
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    DeleteFile(ExpandConstant('{app}\lsc'));
  end;
end;

// 檢查重啟邏輯
function UninstallNeedRestart(): Boolean;
begin
  if serviceExists('MediaSrv') then
    result := True
  else
    result := False;
end;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM