【问题标题】:Using nsis to retrieve choices from checkboxes使用 nsis 从复选框中检索选项
【发布时间】:2009-12-03 13:00:03
【问题描述】:

我将 nsis 用于 Web 应用程序的安装程序。在向导的一个页面中,我希望用户选择三个复选框之一:每个复选框都必须以不同的方式设置两个变量。

这是我要运行的代码:

!define DATA_ONE data_one.zip !define DATA_TWO data_two.zip !define DATA_THREE data_three.zip

函数 myfunc ... ${NSD_GetState} $RadioOne $1 ${NSD_GetState} $RadioTwo $2 ${NSD_GetState} $RadioThree $3

  ; The two variables i want to set
  Var /GLOBAL CUSTOMER_DATA    ; this should be a File (?)
  Var /GLOBAL LENGTH_POS       ; this is a string

  StrCpy $CUSTOMER_DATA ${DATA_ONE} ; default value
  StrCpy $LENGTH_POS ""

  ${If} $1 == ${BST_CHECKED}         
     StrCpy $CUSTOMER_DATA ${DATA_ONE}
 StrCpy $LENGTH_POS "3"
  ${endif}

  ${If} $2 == ${BST_CHECKED}     
     StrCpy $CUSTOMER_DATA ${DATA_TWO}
     StrCpy $LENGTH_POS ""
  ${endif}

  ${If} $3 == ${BST_CHECKED}     
     StrCpy $CUSTOMER_DATA ${DATA_THREE}
     StrCpy $LENGTH_POS ""
  ${endif}      

; here the line i've got the error
  File ${BUILD_DIR}/$CUSTOMER_DATA

...

函数结束

当我尝试运行它时,我得到了:

File: "./$CUSTOMER_DATA" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
  /oname=outfile one_file_only)

我认为错误是因为我正在构建的文件不是在编译时定义的,而只是在运行时定义的。这是对的吗 ?我应该使用宏吗? 解决这个问题的更优雅的方法是什么?

【问题讨论】:

    标签: java nsis


    【解决方案1】:

    如果您在编译时知道该安装程序中只会使用这些文件中的一个,EVER,那么您需要使用 !defines 和 !ifdef 以及可能的 !system 做一些编译时魔法(您不能使用变量在文件命令中)

    如果用户/最终用户的机器正在做出选择,那么您需要包含所有 3 个文件:

    SetOutPath $instdir
    ${If} $somevar == 1
     File "file1"
    ${EndIf}
    ${If} $someothervar == 1
     File "file2"
    ${EndIf}
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      相关资源
      最近更新 更多