如何获取当前Inno Setup脚本文件的文件名?
How to get the file name of the current Inno Setup script file?
我想获取当前Inno Setup 脚本文件的名称,以便以其命名生成的安装包。例如,如果当前的 Inno Setup 脚本文件是 "MyAppSetup.iss",我希望生成的安装文件是 "MyAppSetup.exe".
生成的安装文件的名称由 Inno Setup [Setup]
部分中的 OutputBaseFilename
声明控制,因此如果有一个 Inno Setup 预处理器变量 return当前脚本文件的名称会很棒。类似于:
OutputBaseFilename={#SourceFileName}.exe
不幸的是,没有 Inno Setup 预处理器变量 {#SourceFileName}
。我知道 {#SourcePath}
变量,但它 return 是脚本文件的目录路径,没有文件名。 Here's a list 带有一些预定义的 Inno Setup 预处理器变量,但其中 none 似乎是 return 当前脚本文件的名称。我希望 __FILE__
变量在阅读列表中变量的描述后能够工作,但它 return 是一个空字符串。
我知道这不是你想要的,但你为什么不能这样做:
[ISPP]
#define ScriptFileName "MyAppSetup"
[Setup]
AppPublisher={#AppPublisher}
OutputBaseFilename={#ScriptFileName}Setup
然后您需要做的就是编辑文件顶部的参考文献。
更新
我看到了这个 link,它指出:
You can use:
#expr SetSetupSetting("OutputBaseFilename", sFileName)
However, the difficult part is automatically finding the file name.
You could use the following ISPP functions to do additional
compile-time tasks that can't be done by ISPP built-in functions:
Exec
function: Executes an external program to do the additional
functionality, and writes the result to an INI file. By default Exec
waits for the process to finish.
ReadIni
function: Reads the result
from the INI file, and incorporates it into the script.
How do you determine the file name is up to you. Perhaps you could
enumerate the windows and extract the file name from Inno Setup
window title, but because you may be having multiple Inno Setup
copies open, you must find a reliable way to do it. Inno adds
[Compiling]
to the title during compilation which makes it easier to
find which copy is being used, but there could be multiple copies in
compiling state. You can be absolutely sure about which copy is
running your program by checking the process ID of the parent
process, you can get that by using Process32First
/Process32Next
and
checking the 32ParentProcessID
for your process. Too much work, I
know..
但是还有一个评论:
(If you're doing an automated build, though, you can set the output
filename from the command line -- that might be sufficient for what
you actually want.)
那么您是否考虑过使用批处理文件和命令行?然后您可以在编译中使用批处理行的好处。提供了有关在批处理文件中使用当前文件名的信息here。
个人认为批处理文件编译才是王道
这不可能。有 __FILE__
,但它只有 #include
d 个文件的值。
如果您在一个目录中从来没有超过一个 .iss
文件,您可以使用 FindFirst
来查找它的名称。
#define ScriptFindHandle = FindFirst(SourcePath + "\*.iss", 0)
#if !ScriptFindHandle
#error "No script found"
#endif
#define SourceFileName = FindGetFileName(ScriptFindHandle)
#if FindNext(ScriptFindHandle)
#error "More than one script found"
#endif
#expr FindClose(ScriptFindHandle)
#define SourceBaseName = RemoveFileExt(SourceFileName)
然后要在 [Setup]
部分中的当前脚本文件之后命名安装文件,您应该使用:
[Setup]
OutputBaseFilename={#SourceBaseName}
但是如果您要自动编译大量安装程序,我假设您使用的是命令行编译。那么你可以简单地在父批处理文件(或类似的脚本)中传递一个脚本名称:
set SCRIPT=MyAppSetup
"C:\Program Files (x86)\Inno Setup 5\ISCC.exe" %SCRIPT%.iss /DBaseName=%SCRIPT%
使用 BaseName
如:
[Setup]
OutputBaseFilename={#BaseName}
我想获取当前Inno Setup 脚本文件的名称,以便以其命名生成的安装包。例如,如果当前的 Inno Setup 脚本文件是 "MyAppSetup.iss",我希望生成的安装文件是 "MyAppSetup.exe".
生成的安装文件的名称由 Inno Setup [Setup]
部分中的 OutputBaseFilename
声明控制,因此如果有一个 Inno Setup 预处理器变量 return当前脚本文件的名称会很棒。类似于:
OutputBaseFilename={#SourceFileName}.exe
不幸的是,没有 Inno Setup 预处理器变量 {#SourceFileName}
。我知道 {#SourcePath}
变量,但它 return 是脚本文件的目录路径,没有文件名。 Here's a list 带有一些预定义的 Inno Setup 预处理器变量,但其中 none 似乎是 return 当前脚本文件的名称。我希望 __FILE__
变量在阅读列表中变量的描述后能够工作,但它 return 是一个空字符串。
我知道这不是你想要的,但你为什么不能这样做:
[ISPP]
#define ScriptFileName "MyAppSetup"
[Setup]
AppPublisher={#AppPublisher}
OutputBaseFilename={#ScriptFileName}Setup
然后您需要做的就是编辑文件顶部的参考文献。
更新
我看到了这个 link,它指出:
You can use:
#expr SetSetupSetting("OutputBaseFilename", sFileName)
However, the difficult part is automatically finding the file name. You could use the following ISPP functions to do additional compile-time tasks that can't be done by ISPP built-in functions:
Exec
function: Executes an external program to do the additional functionality, and writes the result to an INI file. By default Exec waits for the process to finish.
ReadIni
function: Reads the result from the INI file, and incorporates it into the script.How do you determine the file name is up to you. Perhaps you could enumerate the windows and extract the file name from Inno Setup window title, but because you may be having multiple Inno Setup copies open, you must find a reliable way to do it. Inno adds
[Compiling]
to the title during compilation which makes it easier to find which copy is being used, but there could be multiple copies in compiling state. You can be absolutely sure about which copy is running your program by checking the process ID of the parent process, you can get that by usingProcess32First
/Process32Next
and checking the32ParentProcessID
for your process. Too much work, I know..
但是还有一个评论:
(If you're doing an automated build, though, you can set the output filename from the command line -- that might be sufficient for what you actually want.)
那么您是否考虑过使用批处理文件和命令行?然后您可以在编译中使用批处理行的好处。提供了有关在批处理文件中使用当前文件名的信息here。
个人认为批处理文件编译才是王道
这不可能。有 __FILE__
,但它只有 #include
d 个文件的值。
如果您在一个目录中从来没有超过一个 .iss
文件,您可以使用 FindFirst
来查找它的名称。
#define ScriptFindHandle = FindFirst(SourcePath + "\*.iss", 0)
#if !ScriptFindHandle
#error "No script found"
#endif
#define SourceFileName = FindGetFileName(ScriptFindHandle)
#if FindNext(ScriptFindHandle)
#error "More than one script found"
#endif
#expr FindClose(ScriptFindHandle)
#define SourceBaseName = RemoveFileExt(SourceFileName)
然后要在 [Setup]
部分中的当前脚本文件之后命名安装文件,您应该使用:
[Setup]
OutputBaseFilename={#SourceBaseName}
但是如果您要自动编译大量安装程序,我假设您使用的是命令行编译。那么你可以简单地在父批处理文件(或类似的脚本)中传递一个脚本名称:
set SCRIPT=MyAppSetup
"C:\Program Files (x86)\Inno Setup 5\ISCC.exe" %SCRIPT%.iss /DBaseName=%SCRIPT%
使用 BaseName
如:
[Setup]
OutputBaseFilename={#BaseName}