我正在尝试更新与[Version]DisplayVersion=0.0.298
类似的INI字符串,以便在文件夹中查找新目录。当前INI字符串0.0.298
与当前目录..\app-0.0.298
匹配。
在运行时,应用程序有时会更新自己,创建一个可能看起来像..\app-0.0.301
的新文件夹。我想要做的是找到这个目录并将其新版本号写入[Version]DisplayVersion
以匹配新的更新版本,所以它看起来像这样:[Version]DisplayVersion=0.0.301
。
到目前为止我还没有这个:
FindFirst $0 $1 `${APPDIR}\app-*`
ReadEnvStr $2 BUILD # Set earlier in the script ($2 = 0.0.298)
StrCmp $1 "" +11
Push `$2.0`
Push `$1.0`
Call VersionCompare # http://nsis.sourceforge.net/VersionCompare
Pop $3
IntCmp $3 1 +4 +4 0
IfFileExists `${APPDIR}\app-$1\${APP}.exe` 0 +3
DeleteINIStr "${InfoINI}" "Version" "DisplayVersion"
WriteINIStr "${InfoINI}" "Version" "DisplayVersion" "$1"
FindNext $0 $1
Goto -10
FindClose $0
我在这里缺少什么,或者有更好的方法来做这件事吗?
答案 0 :(得分:1)
即使您将通配符传递给FindFirst
,返回的文件名仍会包含整个名称,您最终会将0.0.298.0
与app-0.0.298.0
进行比较。
Section "-Initialize example"
!define APP "MyApp"
!define APPDIR "$temp\Test"
!define InfoINI "$temp\Test\app.ini"
CreateDirectory "${APPDIR}\app-0.0.298"
WriteINIStr "${InfoINI}" "Version" "DisplayVersion" "0.0.298"
System::Call 'KERNEL32::SetEnvironmentVariable(t "BUILD", t "0.0.298")'
SectionEnd
!include LogicLib.nsh
Page Components
Page InstFiles
Section "Emulate a update"
CreateDirectory "${APPDIR}\app-0.0.301"
File "/oname=${APPDIR}\app-0.0.301\${APP}.exe" "${__FILE__}"
SectionEnd
Section "Test"
SectionIn RO
FindFirst $0 $1 `${APPDIR}\app-*`
ReadEnvStr $2 BUILD # Set earlier in the script ($2 = 0.0.298)
loop:
StrCmp $1 "" done
StrCpy $3 $1 4
StrCmp $3 "app-" 0 trynext
StrCpy $1 $1 "" 4 ; Remove "app-" prefix
Push `$2.0`
Push `$1.0`
Call VersionCompare # http://nsis.sourceforge.net/VersionCompare
Pop $3
${If} $3 > 1
${If} ${FileExists} "${APPDIR}\app-$1\${APP}.exe"
# DeleteINIStr "${InfoINI}" "Version" "DisplayVersion" ; You don't have to delete before writing
WriteINIStr "${InfoINI}" "Version" "DisplayVersion" "$1"
${EndIf}
${EndIf}
trynext:
FindNext $0 $1
Goto loop
done:
FindClose $0
SectionEnd
提示:使用相对跳转会使代码更难阅读(和修改),使用标签和/或LogicLib.nsh