【问题标题】:NSIS section sizes doubled due to use of SetOverwrite由于使用了 SetOverwrite,NSIS 部分的大小增加了一倍
【发布时间】:2016-03-11 01:39:41
【问题描述】:

我继承了一个安装程序脚本,但它声称需要的空间是实际需要的两倍,这让我很恼火。

我发现这是由于每个部分如何使用SetOverwrite(因为它们被重新用于修复安装?)。我知道由于SetOverwrite 的工作方式(见下文),有必要在每个 If/Else 块中保留重复的File 命令,但我已经确认它会导致自动部分大小计算加倍。

${MementoSection} $(APP_Section_SecHelp) SecHelp
  SetDetailsPrint textonly
  DetailPrint  $(APP_DetailPrint_SecHelp)
  SetDetailsPrint listonly

  SetOutPath $INSTDIR
  SectionIn 1 2
    ${If} $SetOverwriteOn == TRUE
      SetOverwrite ifnewer
      File /r "${APP_SOURCE_DIR}\Help"
    ${Else}
      SetOverwrite off
      File /r "${APP_SOURCE_DIR}\Help"
    ${EndIf}
  SectionGetFlags ${SecHelp} $SecHelp_GetFlag
${MementoSectionEnd}

这是一个糟糕的设计模式,我应该改变吗?我需要添加一个hack来调用SectionGetSize,除以2并调用SectionSetSize吗?

【问题讨论】:

    标签: nsis


    【解决方案1】:

    就我个人而言,我只会使用SetOverwrite ifnewer,但如果您绝对想按照自己的方式进行操作,那么使用SectionSetSize 是一种选择。

    您可以做的另一件事是将修复File /r 指令放在您从该部分调用的单独函数中。函数的缺点是进度条在提取过程中不会移动太多。

    第三种选择是将一些修复任务放在默认未选中的单独部分中,并在您处于修复模式时启用它。

    编辑:这是一个使用 SectionSetSize 的例子:

    !include LogicLib.nsh
    InstallDir $Temp
    Page Components InitComponentsPage
    Page Directory
    Page InstFiles  
    
    !macro ModifySectionHack SID TEMPVAR
    SectionGetSize ${SID} ${TEMPVAR}
    IntOp ${TEMPVAR} ${TEMPVAR} / 2
    SectionSetSize ${SID} ${TEMPVAR}
    !macroend
    
    Function InitComponentsPage
    StrCpy $0 0
    loop:
        ClearErrors
        SectionGetFlags $0 $1 ; The error flag is set if we try to access a section that does not exist
        IfErrors done
        !insertmacro ModifySectionHack $0 $1
        IntOp $0 $0 + 1
        Goto loop
    done:
    FunctionEnd
    
    Section "Foo"
    InitPluginsDir ; Need a place to extract to for this example
    SetOutPath $PluginsDir
    
    ${If} 1 <> 2 ; Don't really care about the result
        SetOverwrite ifnewer
        File "${NSISDIR}\bin\makensis.exe" ; ~400kb
    ${Else}
        SetOverwrite off
        File "${NSISDIR}\bin\makensis.exe"
    ${EndIf}
    SectionEnd
    
    Section "Bar"
    InitPluginsDir ; Need a place to extract to for this example
    SetOutPath $PluginsDir
    
    ${If} 1 <> 2 ; Don't really care about the result
        SetOverwrite ifnewer
        File "${NSISDIR}\nsis.exe" ; ~700kb
    ${Else}
        SetOverwrite off
        File "${NSISDIR}\nsis.exe"
    ${EndIf}
    SectionEnd
    

    这将遍历所有部分并调整所有部分,但我不确定这是否是个好主意。如果这是我的脚本,那么我会在每个有 SetOverwrite 问题的部分上手动调用 ModifySectionHack:

    !include LogicLib.nsh
    InstallDir $Temp
    Page Components
    Page Directory
    Page InstFiles
    
    !macro ModifySectionHack SID TEMPVAR
    SectionGetSize ${SID} ${TEMPVAR}
    IntOp ${TEMPVAR} ${TEMPVAR} / 2
    SectionSetSize ${SID} ${TEMPVAR}
    !macroend
    
    Section "Foo" SID_FOO
    InitPluginsDir ; Need a place to extract to for this example
    SetOutPath $PluginsDir
    
    ${If} 1 <> 2 ; Don't really care about the result
        SetOverwrite ifnewer
        File "${NSISDIR}\bin\makensis.exe" ; ~400kb
    ${Else}
        SetOverwrite off
        File "${NSISDIR}\bin\makensis.exe"
    ${EndIf}
    SectionEnd
    
    Section "Bar"
    ${If} 1 = 2
      File /r "${NSISDIR}\stubs"
    ${EndIf}
    SectionEnd
    
    Section "Baz" SID_BAZ
    InitPluginsDir ; Need a place to extract to for this example
    SetOutPath $PluginsDir
    
    ${If} 1 <> 2 ; Don't really care about the result
        SetOverwrite ifnewer
        File "${NSISDIR}\nsis.exe" ; ~700kb
    ${Else}
        SetOverwrite off
        File "${NSISDIR}\nsis.exe"
    ${EndIf}
    SectionEnd
    
    Function .onInit
    ; Adjust the section size for the sections that use SetOverwrite:
    !insertmacro ModifySectionHack ${SID_FOO} $1
    !insertmacro ModifySectionHack ${SID_BAZ} $1
    FunctionEnd
    

    【讨论】:

    • 我很想看到一个使用SectionSetSize 的例子。我可以将它嵌入到每个部分中,还是需要在其他地方编写脚本以循环通过部分名称列表获取大小,除以 2,然后设置大小?我在 NSIS 方面的经验有限,不想一起破解可能不可靠的解决方案。
    • 您必须使用 SectionSetSize 才能到达 UI 中可见的位置。组件页面的预回调是一个好地方,但如果您需要在其他地方调整部分大小,您可能希望将其放入 .onInit 中。
    猜你喜欢
    • 2015-07-07
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 2018-07-31
    • 1970-01-01
    • 2014-01-27
    相关资源
    最近更新 更多