简体   繁体   English

如何在编译脚本时在NSIS中调用一个函数?

[英]How do I have a function in NSIS called just while compiling the script?

I want to call a function (which calculates my version number) when my NSIS script is compiling, but not while it's executing. 我想在编译NSIS脚本时调用一个函数(该函数会计算我的版本号),而不是在执行时调用。 Is this possible? 这可能吗? It uses nsExec and basic string manipulation functions. 它使用nsExec和基本的字符串操作功能。

You could do this: 您可以这样做:

!system '"calculate_version.exe" "tempfile.tmp"'
!searchparse /file "tempfile.tmp" `APP_VERSION=` APPVERSION

What this does: calls calculate_version.exe (this could be a simple NSIS script which calls your function). 它的作用是:调用calculate_version.exe(这可能是一个简单的NSIS脚本,它会调用您的函数)。 This executable should output the version number to tempfile.tmp. 该可执行文件应将版本号输出到tempfile.tmp。 The format of the version doesn't matter; 版本的格式无关紧要; in this example I've chosen "APP_VERSION=something" (this could be written using WriteINIStr ). 在此示例中,我选择了“ APP_VERSION = something”(可以使用WriteINIStr编写)。

In the next line, we open the temp file and search it for the line we wrote; 在下一行中,我们打开临时文件,并在其中搜索所写的行; then we set ${APPVERSION} to whatever we find there. 然后将$ {APPVERSION}设置为在此找到的任何内容。

Sweet! 甜! It's possible: see http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time 有可能:请参阅http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time

The basic idea is: 基本思想是:

  1. Compile a separate script that generates an executable 编译一个单独的脚本,生成可执行文件
  2. Run the executable (via !system , at compile time) in your main script - and this generates a text file (which !define s whatever you need) 在您的主脚本中运行可执行文件(在编译时通过!system )-这将生成一个文本文件( !define您的需要)
  3. !include the text file in your main script !include在主脚本中!include文本文件

and presto! 和presto! You've got some stuff generated at compile time in your script. 脚本编译时会生成一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用NSIS以管理员身份打开文件 - How do I open a file as an admin using NSIS 如何要求用户使用NSIS卸载以前的版本 - How do I require user to uninstall previous version with NSIS 如何在开发人员之间划分NSIS脚本? - How to divide an NSIS script among developers? NSIS - 如何在排除文件的同时递归复制? - NSIS - How to copy recursively while excluding files? 如何在安装时通过NSIS安装程序将用户给定的数据存储在注册表项中? - How do I store user given data in registry keys at install time from NSIS installer? 在nsis中安装时从文件读取,但不要在目标PC上将其复制 - read from a file while installation in nsis but do no copy it on the destination pc 您如何使用NSIS制作更新安装程序? - How do you make an update installer with NSIS? NSIS:如果更改了程序名,如何在安装新版本之前卸载以前的版本? - NSIS: How do I uninstall previous version before install new version if programm name is changed? 我们是否有任何常量可以获取NSIS中的“当前用户”路径 - Do we have any constant to get the Current User path in NSIS 如何在NSIS安装程序脚本中捕获没有gotos / labels的YESNOCANCEL MessageBox的结果? - How do I capture the results of a YESNOCANCEL MessageBox without gotos/labels in NSIS installer scripting?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM