安装文件名可以从可执行文件版本号中得出吗?

发布于 2024-08-22 10:23:43 字数 90 浏览 4 评论 0原文

是否可以让 Inno Setup 读取主可执行文件的文件版本并将创建的安装程序的名称设置为“myapp_setup_1_0_3708_19805.exe”之类的名称?

Is it possible to get Inno Setup to read the file version of the main executable file and set the name of the created setup to something like "myapp_setup_1_0_3708_19805.exe"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゝ偶尔ゞ 2024-08-29 10:23:43

你应该能够这样做:(

我最近没有尝试过这个,但它确实在 2007 年我以这种方式使用 InnoSetup 时起作用。如果 Inno 的语法从那时起发生了变化,它可能需要一些细微的改变。)

#define MainBinaryName  "MyMainFile.exe"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AVF1            Copy(AppVersion, 1, Pos(".", AppVersion) - 1) + "_" + Copy(AppVersion, Pos(".", AppVersion) + 1)
#define AVF2            Copy(AVF1,       1, Pos(".", AVF1      ) - 1) + "_" + Copy(AVF1      , Pos(".", AVF1      ) + 1)
#define AppVersionFile  Copy(AVF2,       1, Pos(".", AVF2      ) - 1) + "_" + Copy(AVF2      , Pos(".", AVF2      ) + 1)

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

如果MyMainFile.exe 的版本是 1.2.3.4,那么应该调用完成的安装程序 setup_mytool_1_2_3_4.exe

AVF1、AVF2 等内容只是用下划线 (_) 替换版本号中的点 (.),以避免导致问题无法处理文件名中的大量点的事情。

You should be able to do it like this:

(I haven't tried this recently but it certainly worked back in 2007 when I was using InnoSetup in this way. It might need some slight changes if Inno's syntax has changed since then.)

#define MainBinaryName  "MyMainFile.exe"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AVF1            Copy(AppVersion, 1, Pos(".", AppVersion) - 1) + "_" + Copy(AppVersion, Pos(".", AppVersion) + 1)
#define AVF2            Copy(AVF1,       1, Pos(".", AVF1      ) - 1) + "_" + Copy(AVF1      , Pos(".", AVF1      ) + 1)
#define AppVersionFile  Copy(AVF2,       1, Pos(".", AVF2      ) - 1) + "_" + Copy(AVF2      , Pos(".", AVF2      ) + 1)

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

If MyMainFile.exe was version 1.2.3.4 then that should call the finished installer setup_mytool_1_2_3_4.exe

The AVF1, AVF2, etc. stuff is just there to replace the dots (.) in the version number with underscores (_) to avoid causing problems with things that can't cope with lots of dots in a filename.

白云不回头 2024-08-29 10:23:43
; Get the App Version from Main Program
; This Is Full App Version Major.Minor.Build.Revision
; Store First 3 Parts of Version in ShortAppVersion to be used for SBS Assembly Installation Major.Minor.Build
#dim Version[4]
#expr ParseVersion("MainProgram.exe", Version[0], Version[1], Version[2], Version[3])
#define AppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2]) + "." + Str(Version[3])
#define ShortAppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2])
; Get the App Version from Main Program
; This Is Full App Version Major.Minor.Build.Revision
; Store First 3 Parts of Version in ShortAppVersion to be used for SBS Assembly Installation Major.Minor.Build
#dim Version[4]
#expr ParseVersion("MainProgram.exe", Version[0], Version[1], Version[2], Version[3])
#define AppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2]) + "." + Str(Version[3])
#define ShortAppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2])
笔芯 2024-08-29 10:23:43

GetFileVersion() (在其他答案中描述)返回“Major.Minor.Rev.Build”形式的字符串。如果您想要访问各个元素以便自己格式化字符串(例如,如果您只需要“Major.Minor”或“Major.Minor.Rev”),则可以使用 jrsoftware.innosetup 邮件列表

#define VerMajor
#define VerMinor
#define VerRev
#define VerBuild
#define FullVersion=ParseVersion('PathTo.exe', VerMajor, VerMinor, VerRev, VerBuild)
#define MyAppVersion = Str(VerMajor) + "." + Str(VerMinor)

GetFileVersion() (described in other answers) returns a string of the form "Major.Minor.Rev.Build." If you want access to the individual elements so that you can format the string yourself (say, if you only want "Major.Minor" or "Major.Minor.Rev"), you can use the following approach from the jrsoftware.innosetup mailing list:

#define VerMajor
#define VerMinor
#define VerRev
#define VerBuild
#define FullVersion=ParseVersion('PathTo.exe', VerMajor, VerMinor, VerRev, VerBuild)
#define MyAppVersion = Str(VerMajor) + "." + Str(VerMinor)
肥爪爪 2024-08-29 10:23:43

一种更简洁的方法是使用 StringChange 函数,该函数允许用其他内容替换点:

#define MainBinaryName  "MyMainFile.exe"
#define SourcePath      "Path/To/File"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AppVersionFile  StringChange(AppVersion, ".", "_")

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

此外,如果您不想显示所有四个版本号(例如,您希望它说1.0.1 而不是 1.0.1.0),您可以将 AppVersion 行替换为以下内容:

#define NumberOfVersionPoints  3
#define AppVersion             Copy(GetFileVersion(AddBackslash(SourcePath) + MainBinaryName), 0, NumberOfVersionPoints * 2 - 1)

A much cleaner way of doing this involves using the StringChange function, which allows replacing the dots with something else:

#define MainBinaryName  "MyMainFile.exe"
#define SourcePath      "Path/To/File"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AppVersionFile  StringChange(AppVersion, ".", "_")

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

Also, if you don't want to show all four version numbers (e.g. you want it to say 1.0.1 instead of 1.0.1.0), you can replace the AppVersion line with the following:

#define NumberOfVersionPoints  3
#define AppVersion             Copy(GetFileVersion(AddBackslash(SourcePath) + MainBinaryName), 0, NumberOfVersionPoints * 2 - 1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文