How to pad version components with zeroes for OutputBaseFilename in Inno Setup

风流意气都作罢 提交于 2020-12-30 00:54:28

问题


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

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.

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?


回答1:


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

Use it like:

#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 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.



来源:https://stackoverflow.com/questions/65345534/how-to-pad-version-components-with-zeroes-for-outputbasefilename-in-inno-setup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!