如何在Inno Setup中为OutputBaseFilename的版本组件填充零 [英] How to pad version components with zeroes for OutputBaseFilename in Inno Setup

查看:185
本文介绍了如何在Inno Setup中为OutputBaseFilename的版本组件填充零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Inno Setup 6.1.2安装脚本,其中的 main.sub.batch 版本是这样形成的:

I have Inno Setup 6.1.2 setup script where the version main.sub.batch is formed like this:

#define AppVerText() \
  GetVersionComponents('..\app\bin\Release\app.exe', \
    Local[0], Local[1], Local[2], Local[3]), \
    Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2])

稍后在安装程序部分中,我将其用作安装程序包的名称:

Later in the setup part, I use it for the name of setup package:

[Setup]
OutputBaseFilename=app.{#AppVerText}.x64

生成的文件名将为 app.1.0.2.x64.exe ,这很好.为了使其完美,我想以带有零填充组件的形式 app.1.00.002.x64.exe 结尾.

The resulting filename will be app.1.0.2.x64.exe, which is mighty fine. To make it perfect, I'd like to end up with form app.1.00.002.x64.exe with zero-padded components.

我在文档中没有找到 PadLeft 之类的东西.不幸的是,我也无法理解如何在这种情况下使用我自己的Pascal函数.我可以在 Code 部分为此定义一个函数吗?

I did not find anything like PadLeft in documentation. Unfortunately I also fail to understand how to use my own Pascal function in this context. Can I define a function in Code section for this?

推荐答案

一种快速而肮脏的解决方案,用于将数字填充到 Inno Setup预处理器:

A quick and dirty solution to pad the numbers in the Inno Setup preprocessor:

#define AppVerText() \
  GetVersionComponents('..\app\bin\Release\app.exe', \
    Local[0], Local[1], Local[2], Local[3]), \
    Str(Local[0]) + "." + \
      (Local[1] < 10 ? "0" : "") + Str(Local[1]) + "." + \
      (Local[2] < 100 ? "0" : "") + (Local[2] < 10 ? "0" : "") + Str(Local[2])


如果您想为填充使用通用函数,请使用以下命令:


If you want a generic function for the padding, use this:

#define PadStr(S, C, L) Len(S) < L ? C + PadStr(S, C, L - 1) : S

使用方式如下:

#define AppVerText() \
  GetVersionComponents('MyProg.exe', \
    Local[0], Local[1], Local[2], Local[3]), \
    Str(Local[0]) + "." + PadStr(Str(Local[1]), "0", 2) + "." + \
      PadStr(Str(Local[1]), "0", 3)


Pascal脚本 Code (例如这一个)在这里无济于事,因为它在安装时运行,而您在编译时需要它.因此,预处理器是唯一的方法.


Pascal Script Code (like this one) won't help here, as it runs on the install-time, while you need this on the compile-time. So the preprocessor is the only way.

这篇关于如何在Inno Setup中为OutputBaseFilename的版本组件填充零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆