NSIS版本号比较-VersionCompare Bug

NSIS学习笔记三-中文测试 NSI从3.0开始终于原生支持中文了。这里的NSI脚本示例代码验证了NSI新版本对中文的支持。 如果你对安装界面没有要求,这段代码可以直接拿来用,因为该有的feature都有了。 阅读详情

问题:

今天发现自己之前写的NSIS脚本中有个BUG,BUG的来源正是NSIS的版本号比较函数:VersionCompare

这个函数在比较"2008.3.15.1"和"2008.05.1.10"返回的不是期待的2,却是1

于是,可怕的事情发生了……

 

 

解决:

同类的几个函数,经过一番测试,采用下面这个函数。

http://nsis.sourceforge.net/Comparing_Two_Version_Numbers

 

不过原来有个小bug,就是没有初始化自己的变量,会导致多次调用时的结果出错。

于是我也修改之后直接在wiki上提交了我的修改,并在这里转载这个函数,以便下次使用。

 

  1. ;  From:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers
  2. ;  Created 1/5/05 by Comperio
  3. ;
  4. ;   Usage:
  5. ;   ${VersionCheck} "Version1" "Version2" "outputVar"
  6. ;       Version1 = 1st version number
  7. ;       Version2 = 2nd version number
  8. ;       outputVar = Variable used to store the ouput
  9. ;
  10. ;   Return values:
  11. ;       0 = both versions are equal
  12. ;       1 = Version 1 is NEWER than version 2
  13. ;       2 = Version1 is OLDER than version 2
  14. ;   Rules for Version Numbers:
  15. ;       Version numbers must always be a string of numbers only.  (A dot
  16. ;       in the name is optional). 
  17. ;
  18. ;   [Variables]
  19. var P1  ; file pointer, used to "remember" the position in the Version1 string
  20. var P2  ; file pointer, used to "remember" the position in the Version2 string
  21. var V1  ;version number from Version1
  22. var V2  ;version number from Version2
  23. Var Reslt   ; holds the return flag
  24. ;   [Macros]
  25. !macro VersionCheck Ver1 Ver2 OutVar
  26.     ;   To make this work, one character must be added to the version string:
  27.     Push "x${Ver2}"
  28.     Push "x${Ver1}"
  29.     Call VersionCheckF
  30.     Pop ${OutVar}
  31. !macroend
  32. ;   [Defines]
  33. !define VersionCheck "!insertmacro VersionCheck"
  34. ;   [Functions]
  35. Function VersionCheckF
  36.     Exch $1 ; $1 contains Version 1
  37.     Exch
  38.     Exch $2 ; $2 contains Version 2
  39.     Exch
  40.     Push $R0
  41.     ;   initialize Variables
  42.     StrCpy $V1 ""
  43.     StrCpy $V2 ""
  44.     StrCpy $P1 ""
  45.     StrCpy $P2 ""
  46.     StrCpy $Reslt ""
  47.     ;   Set the file pointers:
  48.     IntOp $P1 $P1 + 1
  49.     IntOp $P2 $P2 + 1
  50.     ;  ******************* Get 1st version number for Ver1 **********************
  51.     V11:
  52.     ;   I use $1 and $2 to help keep identify "Ver1" vs. "Ver2"
  53.     StrCpy $R0 $1 1 $P1 ;$R0 contains the character at position $P1
  54.     IntOp $P1 $P1 + 1   ;increments the file pointer for the next read
  55.     StrCmp $R0 "" V11end 0  ;check for empty string
  56.     strCmp $R0 "." v11end 0
  57.     strCpy $V1 "$V1$R0"
  58.     Goto V11
  59.     V11End:
  60.     StrCmp $V1 "" 0 +2
  61.     StrCpy $V1 "0"  
  62.     ;  ******************* Get 1st version number for Ver2 **********************
  63.     V12:
  64.     StrCpy $R0 $2 1 $P2 ;$R0 contains the character at position $P1
  65.     IntOp $P2 $P2 + 1   ;increments the file pointer for the next read
  66.     StrCmp $R0 "" V12end 0  ;check for empty string
  67.     strCmp $R0 "." v12end 0
  68.     strCpy $V2 "$V2$R0"
  69.     Goto V12
  70.     V12End:
  71.     StrCmp $V2 "" 0 +2
  72.     StrCpy $V2 "0"  
  73.     ;   At this point, we can compare the results.  If the numbers are not
  74.     ;       equal, then we can exit
  75.     IntCmp $V1 $V2 cont1 older1 newer1
  76.     older1: ; Version 1 is older (less than) than version 2
  77.     StrCpy $Reslt 2
  78.     Goto ExitFunction
  79.     newer1: ; Version 1 is newer (greater than) Version 2
  80.     StrCpy $Reslt 1
  81.     Goto ExitFunction
  82.     Cont1: ;Versions are the same.  Continue searching for differences
  83.     ;   Reset $V1 and $V2
  84.     StrCpy $V1 ""
  85.     StrCpy $V2 ""
  86.     ;  ******************* Get 2nd version number for Ver1 **********************   
  87.     V21:
  88.     StrCpy $R0 $1 1 $P1 ;$R0 contains the character at position $P1
  89.     IntOp $P1 $P1 + 1   ;increments the file pointer for the next read
  90.     StrCmp $R0 "" V21end 0  ;check for empty string
  91.     strCmp $R0 "." v21end 0
  92.     strCpy $V1 "$V1$R0"
  93.     Goto V21
  94.     V21End:
  95.     StrCmp $V1 "" 0 +2
  96.     StrCpy $V1 "0"  
  97.     ;  ******************* Get 2nd version number for Ver2 **********************
  98.     V22:
  99.     StrCpy $R0 $2 1 $P2 ;$R0 contains the character at position $P1
  100.     IntOp $P2 $P2 + 1   ;increments the file pointer for the next read
  101.     StrCmp $R0 "" V22end 0  ;check for empty string
  102.     strCmp $R0 "." V22end 0
  103.     strCpy $V2 "$V2$R0"
  104.     Goto V22
  105.     V22End:
  106.     StrCmp $V2 "" 0 +2
  107.     StrCpy $V2 "0"  
  108.     ;   At this point, we can compare the results.  If the numbers are not
  109.     ;       equal, then we can exit
  110.     IntCmp $V1 $V2 cont2 older2 newer2
  111.     older2: ; Version 1 is older (less than) than version 2
  112.     StrCpy $Reslt 2 
  113.     Goto ExitFunction
  114.     newer2: ; Version 1 is newer (greater than) Version 2
  115.     StrCpy $Reslt 1
  116.     Goto ExitFunction
  117.     Cont2: ;Versions are the same.  Continue searching for differences
  118.     ;   Reset $V1 and $V2
  119.     StrCpy $V1 ""
  120.     StrCpy $V2 ""   
  121.     ;  ******************* Get 3rd version number for Ver1 **********************   
  122.     V31:
  123.     StrCpy $R0 $1 1 $P1 ;$R0 contains the character at position $P1
  124.     IntOp $P1 $P1 + 1   ;increments the file pointer for the next read
  125.     StrCmp $R0 "" V31end 0  ;check for empty string
  126.     strCmp $R0 "." v31end 0
  127.     strCpy $V1 "$V1$R0"
  128.     Goto V31
  129.     V31End:
  130.     StrCmp $V1 "" 0 +2
  131.     StrCpy $V1 "0"  
  132.     ;  ******************* Get 3rd version number for Ver2 **********************
  133.     V32:
  134.     StrCpy $R0 $2 1 $P2 ;$R0 contains the character at position $P1
  135.     IntOp $P2 $P2 + 1   ;increments the file pointer for the next read
  136.     StrCmp $R0 "" V32end 0  ;check for empty string
  137.     strCmp $R0 "." V32end 0
  138.     strCpy $V2 "$V2$R0"
  139.     Goto V32
  140.     V32End:
  141.     StrCmp $V2 "" 0 +2
  142.     StrCpy $V2 "0"  
  143.     ;   At this point, we can compare the results.  If the numbers are not
  144.     ;       equal, then we can exit
  145.     IntCmp $V1 $V2 cont3 older3 newer3
  146.     older3: ; Version 1 is older (less than) than version 2
  147.     StrCpy $Reslt 2
  148.     Goto ExitFunction
  149.     newer3: ; Version 1 is newer (greater than) Version 2
  150.     StrCpy $Reslt 1
  151.     Goto ExitFunction
  152.     Cont3: ;Versions are the same.  Continue searching for differences
  153.     ;   Reset $V1 and $V2
  154.     StrCpy $V1 ""
  155.     StrCpy $V2 ""
  156.     ;  ******************* Get 4th version number for Ver1 **********************   
  157.     V41:
  158.     StrCpy $R0 $1 1 $P1 ;$R0 contains the character at position $P1
  159.     IntOp $P1 $P1 + 1   ;increments the file pointer for the next read
  160.     StrCmp $R0 "" V41end 0  ;check for empty string
  161.     strCmp $R0 "." v41end 0
  162.     strCpy $V1 "$V1$R0"
  163.     Goto V41
  164.     V41End:
  165.     StrCmp $V1 "" 0 +2
  166.     StrCpy $V1 "0"  
  167.     ;  ******************* Get 4th version number for Ver2 **********************
  168.     V42:
  169.     StrCpy $R0 $2 1 $P2 ;$R0 contains the character at position $P1
  170.     IntOp $P2 $P2 + 1   ;increments the file pointer for the next read
  171.     StrCmp $R0 "" V42end 0  ;check for empty string
  172.     strCmp $R0 "." V42end 0
  173.     strCpy $V2 "$V2$R0"
  174.     Goto V42
  175.     V42End:
  176.     StrCmp $V2 "" 0 +2
  177.     StrCpy $V2 "0"  
  178.     ;   At this point, we can compare the results.  If the numbers are not
  179.     ;       equal, then we can exit
  180.     IntCmp $V1 $V2 cont4 older4 newer4
  181.     older4: ; Version 1 is older (less than) than version 2
  182.     StrCpy $Reslt 2
  183.     Goto ExitFunction
  184.     newer4: ; Version 1 is newer (greater than) Version 2
  185.     StrCpy $Reslt 1
  186.     Goto ExitFunction
  187.     Cont4: 
  188.     ;Versions are the same.  We've reached the end of the version
  189.     ;   strings, so set the function to 0 (equal) and exit
  190.     StrCpy $Reslt 0
  191.     ExitFunction:
  192.     Pop $R0
  193.     Pop $1
  194.     Pop $2
  195.     Push $Reslt
  196. FunctionEnd

我的修改

  1. (cur) (last)  12:35, 31 December 2008 219.131.237.209 (Talk) (6,929 bytes) (→if have not initialized the variables, the second call will be not correct.如果不初始化,之后的调用结果将是错误的) (undo)
  2. (→Description)
    Current revision (12:35, 31 December 2008) (edit) (undo)
    (→if have not initialized the variables, the second call will be not correct.如果不初始化,之后的调用结果将是错误的)
     
    Line 55: Line 55:
    Exch
    Exch
    Push $R0
    Push $R0
     +
    ; initialize Variables
     +
    StrCpy $V1 ""
     +
    StrCpy $V2 ""
     +
    StrCpy $P1 ""
     +
    StrCpy $P2 ""
     +
    StrCpy $Reslt ""
    ; Set the file pointers:
    ; Set the file pointers:
    IntOp $P1 $P1 + 1
    IntOp $P1 $P1 + 1

The End.

NSIS学习笔记(二)-使用C++开发NSIS插件 Q 如何使用C++开发插件,示例 环境:VS2013Update4 参考资料[3]来做 S1:新建一个空的C++DLL项目,nsMessageBoxPlugin. S2:复制“C:\Program Files (x86)\NSIS\Unicode\Examples\Plugin\nsis”文件夹到 阅读详情

相关推荐

nsis脚本中的版本检测函数

在nsis打包脚本中使用的版本信息检测函数,简单,实用

NSIS版本号比较

原地址:http://blog.csdn.net/debehe/article/details/3671142 ;  From:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers ;  Created 1/5/05 by Comperio ; ;   Usage: ;   ${VersionCheck} "V

wandering... 2549

25届电信保研经验贴(空天院)

学校:中九专业:电子信息工程加权:92.89绩点:3.91/4.0rank:前五学期rank2/95,综合排名rank1(前六学期和综合排名出的晚,实际上只用到了前五学期)科研竞赛:市级大创、数模省一、数竞省二,其他校奖若干英语:六级462、四级548个人感觉:rank=科研>竞赛>英语总之rank和科研必须得有一项,要么就rank高,很多强com院校入营看rank。我rank比较有优势,因此报的多是强com院校。要么就科研经历丰富,多主动联系老师,特别是弱com院校。冬令营:空天院。

qq_68608661的博客 6381

NSIS打包软件,${VersionCompare}命令报错

用NSIS 打包软件,想在软件安装前检测当前环境是否已经安装过了该软件,若已经有软件安装,比较已经安装软件的版本和待安装软件的版本,若待安装软件版本比较高,则提示用户原有软件版本比较低,请更新程序.    修改scrip.nsi,增加内容如下;   添加头文件 !include "WordFunc.nsh"   添加代码:   Function  .onInit   XXXXXXXX;此

fang20277的专栏 1788

解决 TensorFlow 和 Keras 的 Python 版本兼容问题:详细技术指南

本文提供了TensorFlow和Keras与Python版本不兼容问题的完整解决方案。通过版本对照表指出不同TensorFlow版本对应的Python支持范围,强调2.13.x仅支持Python 3.9-3.11,且不兼容Python 3.12+。给出最佳实践建议:使用虚拟环境管理项目依赖,推荐venv或conda创建独立环境;指导正确安装TensorFlow和Keras版本,建议优先使用tf.keras避免冲突;针对常见报错如DLL加载失败、模块导入错误等提供具体解决方法。最后给出一个在兼容环境中运行的M

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1675

科研绘图必备:Adobe Illustrator 高效排版技巧全解析

本文详细解析了Adobe Illustrator在科研绘图中的高效排版技巧,帮助科研人员提升论文图表质量。从图片预处理、统计图表优化到精准对齐和期刊投稿前的终极检查,全面覆盖AI在科研绘图中的关键应用场景,确保图表符合期刊要求,提升投稿成功率。

weixin_26767391的博客 353

NSIS安装打包程序的版本比较方便做后续逻辑处理

因为当时公司的项目打包卸载前期出现了一些问题,只能做个补丁来弥补,考虑到不影响后期的项目,分隔版本号,以1.0.12为分割线,判断new or old,然后分别做出不同的卸载逻辑。 1.VersionCompare: *比较版本数字 语法: ${VersionCompare} "[Version1]" "[Version2]" $var "[Vers

Android丶Ren 1682

Centos7 yum 报错「Errno 256」No more mirrors to try 解决方法

首先该问题的出现是由于网络的震荡导致,这是重点。(1)将源更换成阿里云的官方源,步骤参考如上(2)同时将zabbix的官方源更换成阿里云里面的zabbix镜像源,因为zabbix官方源根本网络不通,因为国家防火墙的拦截,导致网络不通。这是阿里源的zabbix镜像地址: https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/修改系统中早期生成的zabbix.repo文件,如下:主要是把baseurl替换成阿里云的zabbix镜像地址即可。

专注基础架构领域 3883

2020-10-20

Page for NSIS 2.07 and below users You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it) Function Description VersionCompare v1.0 Thanks Af

qq_42826610的博客 193

HyperLynx仿真(一)LineSim简单介绍

可以选择设置信号线与信号线之间默认的距离和信号线与同平面的平面之间的距离,这些设置根据工程师项目上经常使用的情况而设置,也可以选择不设置,在每次仿真时根据需要再对每一个仿真单独设置。仿真属性的设置对话框包含一般设置、 显示颜色设置、LineSim 设置、BoardSim 设置、 层叠默认设置、焊盘类型设置、仿真示波器默认设置、电路仿真器默认设置、电源完整性设置及高级设置。第一次使用HyperLynx软件时需要设置仿真相关环境,包括仿真软件的基本设置、模型库路径设置、仿真控制器控制、单位等。...

小幽余生不加糖 8965

【嵌入式】AMIC和DMIC(什么是数字麦和模拟麦)

最近在做一个关于MIC的项目,同事不太清楚AMIC和DMIC的区别,又有高手详细解释了其原理,在此整理记录一下,方便后续查阅。

Bigan(安)的博客 8556

实现1个方法以比较两个版本号的不同

高频面试题:实现一个方法比较两个版本号不同

卜卦的博客 977

10、利用智能合约实现公平的私有集合交集

本文探讨了利用智能合约实现公平的私有集合交集(PSI)的多种协议,重点分析了协议 Π 和 Π∗ 的气体成本与性能特点。同时对比了包括 Justitia 和 Anesidora 在内的现有方案,突出了仅使用智能合约实现硬币补偿公平性的优势。文中还介绍了相关密码学基础、安全模型及隐私保障机制,为在不同应用场景下选择高效、安全的 PSI 协议提供了理论支持和实践指导。

linux的博客 100

nsis检测vc2013运行环境vcredist_x86.exe是否已经安装

网上的代码 我修改后的 网上的代码 原始地址 ; 安装VC环境 Function InstallVC Push $R0 ClearErrors ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6...

lanxiaziyi的专栏 4956

深入解析基于Fluent的蒸发冷凝相变UDF程序及其在重力热管液体蒸发冷凝变化计算中的应用

ANSYS Fluent是一款功能强大的CFD软件,广泛应用于流体流动、传热、化学反应和多相流等领域的数值模拟。Fluent提供了丰富的物理模型和求解器,支持用户自定义函数(UDF)以扩展其功能,实现更为复杂和特定的模拟需求。UDF是用C语言编写的程序,允许用户在Fluent中自定义物理模型、边界条件、源项等,以实现特定的模拟需求。在处理复杂的相变过程、非均匀物性参数或特定的热传导机制时,UDF提供了极大的灵活性和扩展性。

qq_38334677的博客 1266

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

NSIS脚本学习:判断版本并安装.NET Framework运行环境

前言 目前开发的程序以基于.net的应用程序为主,程序开发好后,需要进行安装包的生成,及setup文件的生成。 常见的是NSIS工具,之前一直用的单文件打包工具,不适合将运行环境加进去,因此开始使用更高版本的NSIS 3.06。 关于判断.NET Framework运行环境 (离线安装) 首先添加头文件: 用来版本比较 !include "WordFunc.nsh" 添加 GetNetFrameworkVersion 函数,这里给出完整函数代码: Function GetNetFramework

LeonSUST的博客 2429

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

版本号比较[versionCompare]

/*** * 版本号比较 * @param v1 版本号a * @param v2 版本号b * @return -1代表不是合格版本号;0代表一样大、1 代表版本号a大于版本号b、2代表版本号b大于版本号a */ public static Integer versionCompare(String v1,String v2){ ...

:) 2371

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

NSIS文字函数头文件介绍(一)

NSIS文字函数头文件介绍 文字函数,顾名思义就是处理字符串的函数。使用这些字符串函数前,必须先包含头文件WordFunc.nsh。该头文件目前包含如下一些函数:WordFind、WordFind2X、WordFind3X、WordReplace、WordAdd、WordInsert、StrFilter、VersionCompare、VersionConvert等。这些函数的主要作用

「东哥说MES」 专注于MES制造执行系统,为你拆解核心架构、功能模块及与ERP/PLC的集成逻辑。提供从入门到精通的系列干货、精选行业报告与实用工具,构建你的数字化知识体系,关注我,用实战经验照亮你的数字化之路。 4452

VersionCompare

public class VersionCompare{ public static int VersionCompare(String V1,String V2){ //检测版本号是否合法 if (V1==null||V2==null) throw new IllegalArgumentException("Version can not be null"); if (

clarence_88的博客 544

NSIS判断系统版本

Function "GetWinVer" /* ;Push $R0 ;Push $R1 ClearErrors ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion IfErrors 0 lbl_winnt ; we are not NT ReadRegStr $R0 HK

非鱼 5311

在NSIS文件中添加版本信息的代码

!define INSTALLERNAME "FLSetup" !define PRODUCT_VERSION "1.0.2.0" !define PRODUCT_NAME "FileLocateSuit" !define COMPANY_NAME "Easytek" !include 'MUI.nsh' !insertmacro MUI_LANGUAGE "SIMPCHINESE" VI

勿忘初心,安得始终 3633

NSIS检测并统计字符串中某个字符个数

!include "LogicLib.nsh" OutFile "检查找字符串中c出现的次数.exe" Name "test" Section "test" StrCpy $0 "cabcdccccc" StrLen $1 $0 StrCpy $2 '' loop: IntOp $1 $1 - 1 StrCmp $1 "-1" end StrCpy $3 $0 1

水晶石专栏 4536

01_NSIS_设置密码卸载

01_NSIS_设置密码卸载1. 密码卸载1.1 添加卸载相关页面1.2 定义卸载密码页面1.3 定义离开时验证卸载密码函数2. 相关函数介绍2.1 StrCmp2.2 函数声明2.3 例子参考网址 1. 密码卸载 1.1 添加卸载相关页面 ;--------------------引入文件,声明变量---------------------------------- !include "nsDialogs.nsh" Var Dialog Var Label Var Text ;--------------

田一一 1322
上一篇: 如何使用DISPPARAMS和SAFEARRAY
下一篇: windows7下缺少msxml.dll
debehe
博客等级 码龄22年 38粉丝 67原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值