【问题标题】:NSIS - Install a file to a pre-existing, uncertain subfolder?NSIS - 将文件安装到预先存在的不确定子文件夹?
【发布时间】:2015-09-16 13:42:07
【问题描述】:

我正在尝试将文件安装到结构如下的预先存在的文件夹中:

$APPDATA/somefolder/(uncertainFolder)

“不确定文件夹”可以是“1.0”或“2.0”。

尽管文件夹名称不同,但相同的文件将安装到“不确定文件夹”中。我怎样才能做到这一点?

提前谢谢你。

【问题讨论】:

  • 我怀疑“不确定性”是否真的是一个有效的标签(我猜很多提问者对很多事情都不确定!)。是否需要检查1.0或2.0是否存在,然后选择一个,还是有其他条件?
  • 是的。检查是否存在任何一个并选择一个将是完美的。你怎么能这样做?
  • 看起来像 Locate in FileFunc.nsh 或(较新的)Locate plugin 应该能够告诉您其中是否存在。我没有用过,所以不能给你任何示例代码。

标签: installation directory nsis


【解决方案1】:

使用File 指令安装的文件被解压到SetOutPath 设置的目录中。一旦你知道你想要哪个文件夹,在运行时更改这个路径就不是问题了。

如果可能的文件夹名称在编译时已知,您可以使用 if/or if/else:

!include LogicLib.nsh
${If} ${FileExists} "$InstDir\SomeFolder\2.0\*.*"
    SetOutPath "$InstDir\SomeFolder\2.0"
${Else}
    SetOutPath "$InstDir\SomeFolder\1.0"
${EndIf}

您还可以在运行时枚举文件和文件夹:

FindFirst $0 $1 "$InstDir\SomeFolder\*.*"
loop:
    StrCmp $1 "" end ; No more files?
    StrCmp $1 "." next ; DOS special name
    StrCmp $1 ".." next ; DOS special name
    IfFileExists "$InstDir\SomeFolder\$1\*.*" 0 next ; Skip files
    DetailPrint "$1 is a folder in $InstDir\SomeFolder"
    SetOutPath "$InstDir\SomeFolder\$1"
    Goto end ; This stops the search at the first folder it finds
next:
    FindNext $0 $1
    goto loop
end:
FindClose $0

FileFunc.nsh 中的 Locate 宏构建在 FindFirst/FindNext 之上,如果您更喜欢它的语法,也可以使用它...

【讨论】:

  • 如果语句有效。我为要安装到两个不同位置的两个文件设置了两个部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-17
  • 2013-03-12
  • 1970-01-01
  • 2011-12-17
  • 2012-02-12
  • 2012-05-13
相关资源
最近更新 更多