由于使用 SetOverwrite,NSIS 部分大小翻了一番
NSIS section sizes doubled due to use of SetOverwrite
我继承了一个安装程序脚本,我很生气它声称需要的 space 是实际需要的两倍。
我发现这是由于每个部分如何使用 SetOverwrite
(因为它们被重新用于修复安装?)。我知道有必要在每个 If/Else 块中保留重复的 File
命令,因为 SetOverwrite
是如何工作的(见下文),但我已经确认它会导致加倍自动截面尺寸计算。
${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
?
就我个人而言,我只会对两者都使用 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 [=10=] 0
loop:
ClearErrors
SectionGetFlags [=10=] ; The error flag is set if we try to access a section that does not exist
IfErrors done
!insertmacro ModifySectionHack [=10=]
IntOp [=10=] [=10=] + 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}
!insertmacro ModifySectionHack ${SID_BAZ}
FunctionEnd
我继承了一个安装程序脚本,我很生气它声称需要的 space 是实际需要的两倍。
我发现这是由于每个部分如何使用 SetOverwrite
(因为它们被重新用于修复安装?)。我知道有必要在每个 If/Else 块中保留重复的 File
命令,因为 SetOverwrite
是如何工作的(见下文),但我已经确认它会导致加倍自动截面尺寸计算。
${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
?
就我个人而言,我只会对两者都使用 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 [=10=] 0
loop:
ClearErrors
SectionGetFlags [=10=] ; The error flag is set if we try to access a section that does not exist
IfErrors done
!insertmacro ModifySectionHack [=10=]
IntOp [=10=] [=10=] + 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}
!insertmacro ModifySectionHack ${SID_BAZ}
FunctionEnd