1. 程式人生 > >innosetup打包程式指令碼

innosetup打包程式指令碼

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


;安裝包exe的輸出路徑
#define OutPutDirectory ".\"  


;檔案路徑
#define MyFileDirectory "..\..\install\release\config"


;版本
#define version "1.2.1.2"


;程式名稱
#define appname "Tools"


;執行exe名稱
#define MyAppExeName "Tools.exe"


;公司網站
#define MyAppURL "http://www.www.com"


;reg path
#define REGPATH "Software\MKT\Config"


;app name
#define APPNAME_CH "設定工具"
#define APPNAME_EN "Tools"


;RUN msg
#define RUNNINGMSG_CH " 正在執行,請先退出!"
#define RUNNINGMSG_EN " is running,please quit first!"


;installed msg
#define INSTALLED_CH "系統檢測到其它盤已安裝過,請先解除安裝,或覆蓋,位於:"
#define INSTALLED_EN "Detect you have installed in other disk,please uninstall it first or cover it,disk path:"




[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same App{8CF49867-889C-4534-A2A9-370A362A8DB4}Id value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{53F3A61D-B40C-42DA-B52C-576F27B1864E}
AppName={code:GetAppName}
AppVersion={#version}
AppVerName={#appname} {#version}
DefaultDirName={sd}\{#appname}
DefaultGroupName={#appname}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}


;使用最低的許可權開啟
;PrivilegesRequired=lowest


;不用上次安裝的路徑
UsePreviousAppDir=no
UsePreviousGroup=no
UsePreviousLanguage=no


;輸出目錄
OutputDir={#OutPutDirectory}


;輸出檔名
OutputBaseFilename={#appname} {#version}
Compression=lzma
SolidCompression=yes


VersionInfoVersion={#version}


;提示是否覆蓋
DirExistsWarning = yes


;許可證說明
;LicenseFile=compiler:license.txt


;很重要,將顯示所有語言
ShowUndisplayableLanguages=yes


[Languages]
Name: "Chinese"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
Name: "English"; MessagesFile: "compiler:Default.isl"
   
[Messages]
Chinese.BeveledLabel=Chinese
English.BeveledLabel=English
 
[Tasks]
;建立桌面快捷方式,預設選中
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}";


[Files]
;拷貝資料夾及子資料夾的所有檔案
Source: {#MyFileDirectory}\*.*; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs


[Icons]
Name: "{group}\{#appname}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#appname}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppExeName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon


;解除安裝前刪除安裝目錄
[UninstallDelete]
;Type: filesandordirs; Name: "{app}"
Type: filesandordirs; Name: "{app}\temp"


;安裝前先刪除
[InstallDelete]
;Type: filesandordirs; Name: "{app}"
Type: filesandordirs; Name: "{app}\temp"
Type: filesandordirs; Name: "{app}\unins000.dat"
Type: filesandordirs; Name: "{app}\unins000.exe"


;刪除快捷方式
Type: filesandordirs; Name:"{group}\*"


[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#appname}}"; Flags: nowait postinstall skipifsilent runascurrentuser


[INI]  
Filename: "{app}\config.ini"; Section: "SERVER_SET"; Key: "language"; String: "{code:MyLangName|{app}}"; Flags: uninsdeletesection


[Registry]
Root: HKLM; Subkey: "{#REGPATH}"; ValueType: string; ValueName: path; ValueData: {app}; Flags: createvalueifdoesntexist uninsdeletevalue


[Code]
//預設選擇同意(安裝的協議)
procedure InitializeWizard();
begin
  WizardForm.LICENSEACCEPTEDRADIO.Checked := true;
end;


// 根據選擇的語言載入相應的配置檔案
function MyLangName(Param : String): String;
        
begin              
  Result := ActiveLanguage(); 
end;


// 獲取視窗名稱
function GetAppName(Param: String):String;
var
softlan:String;


begin   
  softlan := MyLangName('');
  
  if (softlan = 'English') then  
    Result := '{#APPNAME_EN}'
  else
    Result := '{#APPNAME_CH}';
end;


// 獲取警告資訊
function GetRunningNotice(Param: String):String;
var
lan:String;
appName:String;


begin
  lan := MyLangName('');
  appName := GetAppName('');
  if (lan = 'English') then
    Result := appName + '{#RUNNINGMSG_EN}'
  else
    Result := appName + '{#RUNNINGMSG_CH}';
end;


// 是否安裝過在其它路徑下
function IsAppInstallInOtherDisk() : Boolean;
var
res : Boolean;
installpath : String;
softlan : String;
msg : String;


begin
res := True;
if RegQueryStringValue(HKEY_LOCAL_MACHINE, '{#REGPATH}', 'path', installpath) then
  if (Uppercase(installpath) <> Uppercase(ExpandConstant('{app}'))) then // 轉換為大寫比較
    begin
      res := False;
      softlan := MyLangName('');
      if (softlan = 'English') then
        msg := '{#INSTALLED_EN}'
      else
        msg := '{#INSTALLED_CH}';


      Msgbox(msg + installpath, mbConfirmation, MB_OK);
    end;


Result := res;
end;


function NextButtonClick(CurPageID: Integer): Boolean;
var
res : Boolean;


begin
  res := True;
  case CurPageID of wpSelectDir:
      res := IsAppInstallInOtherDisk();
  end;
  Result := res;
end;


// 安裝時判斷客戶端是否正在執行
function InitializeSetup(): Boolean;
var 
  IsRunning: Integer;
  name:String;
  notice:String;


begin
  Result :=true; //安裝程式繼續
  name := GetAppName('');
  IsRunning:=FindWindowByWindowName(name);
  if IsRunning <> 0 then
  begin
    notice := GetRunningNotice('');
    Msgbox(notice, mbConfirmation, MB_OK);
    Result :=false; //安裝程式退出
  end;
end;


// 解除安裝時判斷客戶端是否正在執行
function InitializeUninstall(): Boolean;
var 
  IsRunning: Integer;
  name:String;
  notice:String;


begin
  Result :=true; //安裝程式繼續
  name := GetAppName('');
  IsRunning:=FindWindowByWindowName(name);
  if IsRunning <> 0 then
  begin
    notice := GetRunningNotice('');
    Msgbox(notice, mbConfirmation, MB_OK);
    Result :=false; //安裝程式退出
  end;
end;