有时候我们需要这样的一个软件包:

  • 他是一个单文件
  • 他解压后可以直接启动软件
  • 他在关闭后可以自动删除临时文件

制作这样的软件包有很多种方法,下面分享的是使用 inno setup 打包工具制作这样的软件包的脚本。

; 功能: 制作用于临时使用的便携版本的软件包
; 说明:
; 一般情况下,只需要修改“define”开头的行的引号内的部分即可
; 生成的文件在当前文件夹内,文件名为: “软件名称_软件版本.exe”
; 作者: 杨永全
; 网址: https://www.qt06.com/

#define MyAppName "nvda远程被控端"
#define MyAppExeName "nvda.exe"
#define MyAppVersion "2022.3"
#define MyFileDir "nvda"
#define MyAppPublisher "我的公司"
#define MyAppURL "https://www.example.com/"

[Setup]
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DisableWelcomePage=yes
DisableReadyPage=yes
DisableDirPage = yes
DisableProgramGroupPage = yes
DisableFinishedPage=yes
CloseApplications=no
;DefaultDirName={%tmp}\nvda{code:GenTempDir}
CreateAppDir=no
Uninstallable=no
;ArchitecturesInstallIn64BitMode=x64 ia64
; 如果不需要以管理员运行,请删除下一行开头的分号
;PrivilegesRequired=lowest
OutputDir=.
OutputBaseFilename={#MyAppName}_{#MyAppVersion}
; 为了加快解压速度,使用 zip方式压缩
; 如果想要更小的安装包体积,请把下一行末尾的“zip”替换为“lzma”
Compression=zip
; 如果想要更小的体积,请删除下一行开头的分号,但这会需要更多的解压时间
;SolidCompression=yes
WizardStyle=modern

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

[Messages]
SetupAppTitle=
SetupWindowTitle=%1
WizardInstalling=正在启动
InstallingLabel=正在启动 [name] 请稍后。

[Files]
Source: "{#MyFileDir}\*"; DestDir: "{tmp}"; Flags: ignoreversion recursesubdirs createallsubdirs

[Run]
FileName: "{tmp}\{#MyAppExeName}"; Description: "nvda"; Flags: shellexec hidewizard waituntilterminated

[Code]
const
WM_LBUTTONDOWN = 513;
WM_LBUTTONUP = 514;

Procedure RestartDeleteDir(path: String);
var FindRec:TFindRec;
begin
if FindFirst(path+'\*',findrec) then
    try
          repeat
          if (not (findrec.name='.') and not (findrec.name='..')) then
                    if not findrec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
                              RestartDeleteDir(path+'\'+findrec.name)
          else
   RestartReplace(path+'\'+findrec.name,'');
                                until not FindNext(FindRec);
                    finally
                    RestartReplace(path,'')
                          FindClose(FindRec);
                              end;
end;

function GenTempDir(Param: String): String;
begin
  Result := GetDateTimeString('yyyymmddhhnnss', '-', '-');
end;

procedure InitializeWizard();
begin
  PostMessage(WizardForm.NextButton.Handle,WM_LBUTTONDOWN,0,0);
  PostMessage(WizardForm.NextButton.Handle,WM_LBUTTONUP,0,0);
end;

procedure CurStepChanged(CurStep: TSetupStep);
var dataPath:string;
      begin
      dataPath:=ExpandConstant('{tmp}')
      if CurStep = ssDone then
begin
RestartDeleteDir(datapath)
end;                                          
end;

标签:无

你的评论