DSP

自己写了一个打包程序

2019-07-13 12:47发布

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "yxz"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "麻州信息技术(上海)有限公司"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "yxz.exe"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{E04370E9-182D-43DF-AD60-A6B500E950AB}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile=D:Demoyxz eadme.txt
InfoBeforeFile=D:Demoyxz eadme.txt
InfoAfterFile=D:Demoyxz eadme.txt
OutputDir=D:新建文件夹 (4)
OutputBaseFilename=yxz
SetupIconFile=D:Demoyxz520.ico
Compression=lzma
SolidCompression=yes
[code]
var
ErrorCode: Integer;
IsRunning: Integer;
function InitializeSetup: Boolean;

 
var Path:string ;
 
     ResultCode: Integer;
 
     dotNetV4RegPath:string;
 
     dotNetV4DownUrl:string;
 
     dotNetV4PackFile:string;
 
     wic:string;
 
begin
      //安装程序是否
     //Result :=true; //安装程序继续
//IsRunning:=FindWindowByWindowName('yxz');
//while IsRunning<>0 do
//begin
//if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then
//begin
//Result :=false; //安装程序退出
//IsRunning :=0;
//end else begin
//Result :=true; //安装程序继续
//IsRunning:=FindWindowByWindowName('yxz');
//end;
//end;


 
dotNetV4RegPath:='SOFTWAREMicrosoft.NETFrameworkpolicyv4.0';
 
dotNetV4DownUrl:='http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe';
 
dotNetV4PackFile:='{src}updatedotNetFx40_Full_x86_x64.exe';
 
wic:='{src}updatewic_x86_chs.exe';
 
   if RegKeyExists(HKLM, dotNetV4RegPath) then
 
   begin
    Result := true;
 
   end
 
 else
 
   begin
 
     Exec(ExpandConstant(wic), '/q /norestart', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
 
     if MsgBox('系统检测到您没有安装.Net Framework4.0运行环境,是否立即安装?', mbConfirmation, MB_YESNO) = idYes then
 
     begin
 
 
 
       Path := ExpandConstant(dotNetV4PackFile);
 
       if(FileOrDirExists(Path)) then
 
       begin
 
         Exec(Path, '/q /norestart', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
 
         if RegKeyExists(HKLM, dotNetV4RegPath) then
 
         begin
 
            Result := true;
 
         end
 
         else
 
         begin
 
            MsgBox('未能成功安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
 
         end
 
       end
 
       else
 
       begin
 
         if MsgBox('软件安装目录中没有包含.Net Framework的安装程序,是否立即下载后安装?', mbConfirmation, MB_YESNO) = idYes then
 
         begin
 
           Path := ExpandConstant('{pf}Internet Exploreriexplore.exe');
 
           Exec(Path, dotNetV4DownUrl , '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
 
           MsgBox('请安装好.Net Framework4.0环境后,再运行本安装包程序!',mbInformation,MB_OK);
 
           Result := false;
 
         end
 
         else
 
         begin
 
           MsgBox('不下载安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
 
           Result := false;
 
         end
 
       end
 
     end
 
     else
 
     begin
 
       MsgBox('没有安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
 
       Result := false;
 
     end;
 
   end;
 
end;
//11、在运行卸载程序前显示弹出式消息
//[code]
//function InitializeUninstall(): Boolean;
//begin
//if MsgBox('请重启计算机', mbConfirmation, MB_YESNO) = IDYES then
//result:=true
//else
//result:=false;
//end;
[code]
 var
  EnableFolderPage: Boolean;
  lblBlobFileFolder: TLabel;
  lblBlobFileWarning1: TLabel;
  lblBlobFileWarning2: TLabel;
  tbBlobFileFolder: TEdit;
  btnBlobFileFolder: TButton;
       path:String;



function GetBlobFolder(param: String): String;
begin
  Result := Trim(tbBlobFileFolder.Text);
end;


{ BlobFileForm_Activate }
procedure BlobFileForm_Activate(Page: TWizardPage);
var
  s: string;
begin
  s := Trim(tbBlobFileFolder.Text);
  if (s = '') then
  begin
    tbBlobFileFolder.Text := ExpandConstant('D:yxz');
  end;
end;
{ BlobFileForm_NextButtonClick }
function BlobFileForm_NextButtonClick(Page: TWizardPage): Boolean;
var
  s: string;
begin
  s := Trim(tbBlobFileFolder.Text);
  if (s = '') then
  begin
    MsgBox(ExpandConstant('{cm:BlobFileForm_NoFolder}'), mbError, MB_OK);
    Result := false;
  end else
  begin
   path:= ExpandConstant('{app}');
    if not DirExists(s) then
    begin
      //MsgBox(ExpandConstant('{cm:BlobFileForm_DirDoesntExist}'), mbError, MB_OK);
     
     if CreateDir(s) then
     begin
      if SaveStringToFile(path+'file.txt',tbBlobFileFolder.Text, false) then
      begin
      Result := true;
      end
      else
      begin
        MsgBox(ExpandConstant('同步盘路径保存失败!'), mbError, MB_OK);
      end
      end
      else
      begin
       MsgBox(ExpandConstant('当前D盘不存在!请选择其他盘符'), mbError, MB_OK);
      end
    end
     else
    begin
  //  path:= ExpandConstant('{app}');
 if SaveStringToFile(path+'file.ini',tbBlobFileFolder.Text, false) then
    begin
    // SaveStringToFile(const FileName: String; const S: AnsiString; const Append: Boolean): Boolean;
      Result := true;
      end
      else
      begin
      MsgBox(ExpandConstant('同步盘路径保存失败!'), mbError, MB_OK);
      end
    end;
  end;
end;
procedure btnBlobFileFolder_Click(sender: TObject);
var
  directory: string;
begin
  if BrowseForFolder('', directory, true) then
  begin
   //dir:=directory;
    tbBlobFileFolder.Text := directory;
  end;
end;
{ BlobFileForm_CreatePage }
function BlobFileForm_CreatePage(PreviousPageId: Integer): Integer;
var
  Page: TWizardPage;
begin
  Page := CreateCustomPage(
    PreviousPageId,
    ExpandConstant('自定义安装目录'),
    ExpandConstant('云协作同步 {MOD}')
  )
{ lblBlobFileFolder }
  lblBlobFileFolder := TLabel.Create(Page);
  with lblBlobFileFolder do
  begin
    Parent := Page.Surface;
    Caption := ExpandConstant('请选择同步路径:');
    Left := ScaleX(8);
    Top := ScaleY(8);
    Width := ScaleX(167);
    Height := ScaleY(13);
  end;

  { lblBlobFileWarning1 }
  lblBlobFileWarning1 := TLabel.Create(Page);
  with lblBlobFileWarning1 do
  begin
    Parent := Page.Surface;
    Caption := ExpandConstant('文件浏览');
    Left := ScaleX(8);
    Top := ScaleY(80);
    Width := ScaleX(500);
    Height := ScaleY(350);
    Font.Color := -16777208;
    Font.Height := ScaleY(-11);
    Font.Name := 'Tahoma';
    Font.Style := [fsBold];
  end;

  { lblBlobFileWarning2 }
  lblBlobFileWarning2 := TLabel.Create(Page);
  with lblBlobFileWarning2 do
  begin
    Parent := Page.Surface;
    Caption :=
      ExpandConstant('这是同步盘目录,默认安装在D:yxz,您可以自己选择安装目录!')
     
    Left := ScaleX(8);
    Top := ScaleY(96);
    Width := ScaleX(500);
    Height := ScaleY(300);
    AutoSize := False;
    WordWrap := True;
  end;                                                                 

  { tbBlobFileFolder }
  tbBlobFileFolder := TEdit.Create(Page);
  with tbBlobFileFolder do
  begin
    Parent := Page.Surface;
    Left := ScaleX(8);
    Top := ScaleY(24);
    Width := ScaleX(300);
    Height := ScaleY(21);
    TabOrder := 0;
  end;
  { btnBlobFileFolder }
  btnBlobFileFolder := TButton.Create(Page);
  with btnBlobFileFolder do
  begin
    Parent := Page.Surface;
    Caption := ExpandConstant('浏览');
    Left := ScaleX(320);
    Top := ScaleY(24);
    Width := ScaleX(91);
    Height := ScaleY(23);
    TabOrder := 1;
  end;

  with Page do
  begin
    OnActivate := @BlobFileForm_Activate;
    OnNextButtonClick := @BlobFileForm_NextButtonClick;
  end;

  with btnBlobFileFolder do
  begin
    OnClick := @btnBlobFileFolder_Click;
  end;

  Result := Page.ID;
end;



//让许可默认选中
[code]
procedure InitializeWizard();
begin
WizardForm.LICENSEACCEPTEDRADIO.Checked := true;
//CreateAddonPage;
  BlobFileForm_CreatePage( wpInfoAfter);
end;
 

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:Demoyxzyxz.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxz520.ico"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzHelper.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzHelper.dll.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzNewtonsoft.Json.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzOverlayIcon.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzOverlayIcon.dll.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxz eadme.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzRegAsm.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxz egasm.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzShellExtContextMenuHandler.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzShellExtContextMenuHandler.dll.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzSystem.Data.SQLite.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzSystem.Data.SQLite.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxzyxz.db3"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxzyxz.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:Demoyxzyxz.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:DemoyxzImage*"; DestDir: "{app}Image"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]
Name: "{group}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"
Name: "{group}{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}MicrosoftInternet ExplorerQuick Launch{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: quicklaunchicon
Name: "{userdesktop}{#MyAppName}";Filename: "{app}{#MyAppExeName}";WorkingDir: "{app}";IconFilename:"{app}520.ico";Comment:"云协作"
[Run]
Filename: "{app}{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
Filename:"{dotnet4064}RegAsm.exe"; Parameters: /codebase ShellExtContextMenuHandler.dll;WorkingDir: {app}; StatusMsg: "正在注册ShellExtContextMenuHandler.dll"; Flags: runhidden 64bit runascurrentuser
Filename:"{dotnet4064}RegAsm.exe"; Parameters: /codebase OverlayIcon.dll;WorkingDir: {app};  StatusMsg: "正在注册OverlayIcon.dll"; Flags: runhidden 64bit runascurrentuser
[UninstallRun]
Filename:"{dotnet4064}RegAsm.exe"; Parameters: /unregister OverlayIcon.dll;WorkingDir: {app}; StatusMsg: "正在卸载OverlayIcon.dll"; Flags: runhidden 64bit runascurrentuser
Filename:"{dotnet4064}RegAsm.exe"; Parameters: /unregister ShellExtContextMenuHandler.dll;WorkingDir: {app}; StatusMsg: "正在卸载ShellExtContextMenuHandler.dll"; Flags: runhidden 64bit runascurrentuser