代码之家  ›  专栏  ›  技术社区  ›  Ray Hayes

基于文件存在的NSI脚本条件编译

  •  4
  • Ray Hayes  · 技术社区  · 15 年前

    我有一个基于NSI的安装程序,我需要能够在不同的条件下生成稍微不同的版本。

    这些条件在编译时很容易建立,如果磁盘上存在特定的文件,则可以使用其他品牌。我知道我可以使用makensis.exe的命令行选项来提供这种行为,但是如果编译器能为我处理好这一点就更好了。

    有没有一种方法可以生成编译时的“ifexist”类型逻辑?

    2 回复  |  直到 7 年前
        1
  •  6
  •   Anders    15 年前
    !macro CompileTimeIfFileExist path define
    !tempfile tmpinc
    !system 'IF EXIST "${path}" echo !define ${define} > "${tmpinc}"'
    !include "${tmpinc}"
    !delfile "${tmpinc}"
    !undef tmpinc
    !macroend
    
    Section 
    !insertmacro CompileTimeIfFileExist "$%windir%\explorer.exe" itsThere
    !ifdef itsThere
    MessageBox mb_Topmost yes
    !else
    MessageBox mb_Topmost no
    !endif
    SectionEnd
    

    注:!此处使用的系统命令假定您正在Windows上编译

        2
  •  2
  •   Kyle Gagnet    15 年前

    我没有回答你关于编译时文件检测的一般问题,但我确实有一个解决方案来解决你想要完成的事情。

    我的安装程序使用类似的方法:

    在custombranding.nsh文件中:

    !define CUSTOM_BRANDING
    !define APPNAME "Brand X"
    !define LOGO "C:\Brand_X_Logo.png"
    

    在主安装程序脚本中:

    !include /NONFATAL "CustomBranding.nsh"
    !ifndef CUSTOM_BRANDING
        !define APPNAME "Generic"
        !define LOGO "C:\Generic_Logo.png"
    !endif
    

    这是你要问的“另类品牌”吗?