From c55efbb148a9022aa7f2c6e87b9c3ca7e844426c Mon Sep 17 00:00:00 2001 From: RestorerZ Date: Mon, 29 Sep 2025 19:48:54 +0000 Subject: [PATCH] nsis: Split gvim.nsi and factor out auxiliary code into auxiliary.nsh Improves maintainability by separating helper functions and macros from the main installer script. related: #18440 Signed-off-by: RestorerZ Signed-off-by: Christian Brabandt --- Filelist | 1 + nsis/auxiliary.nsh | 148 +++++++++++++++++++++++++++++++++++++++++++++ nsis/gvim.nsi | 129 +-------------------------------------- 3 files changed, 152 insertions(+), 126 deletions(-) create mode 100644 nsis/auxiliary.nsh diff --git a/Filelist b/Filelist index 3a2e066e33..225eaf2b5c 100644 --- a/Filelist +++ b/Filelist @@ -639,6 +639,7 @@ SRC_DOS = \ src/tee/tee.c \ src/xxd/Make_ming.mak \ src/xxd/Make_mvc.mak \ + nsis/auxiliary.nsh \ nsis/gvim.nsi \ nsis/gvim_version.nsh \ nsis/Makefile \ diff --git a/nsis/auxiliary.nsh b/nsis/auxiliary.nsh new file mode 100644 index 0000000000..c350f69e0b --- /dev/null +++ b/nsis/auxiliary.nsh @@ -0,0 +1,148 @@ +# -*- coding: utf-8 -*- +# NSIS helper file for creating a self-installing exe for Vim. +# Contains service macros and functions. +# Last Change: 2025-09-03 +# + +!ifndef __AUXILIARY__NSH__ + !define __AUXILIARY__NSH__ + +# See https://nsis.sourceforge.io/LogicLib +;FileExists is already part of LogicLib, but returns true for directories +;as well as files + !macro _FileExists2 _a _b _t _f + !insertmacro _LOGICLIB_TEMP + StrCpy $_LOGICLIB_TEMP "0" +;if path is not blank, continue to next check + StrCmp `${_b}` `` +4 0 +;if path exists, continue to next check (IfFileExists returns true if this +;is a directory) + IfFileExists `${_b}` `0` +3 +;if path is not a directory, continue to confirm exists + IfFileExists `${_b}\*.*` +2 0 + StrCpy $_LOGICLIB_TEMP "1" ;file exists +;now we have a definitive value - the file exists or it does not + StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}` + !macroend + !undef FileExists + !define FileExists `"" FileExists2` + !macro _DirExists _a _b _t _f + !insertmacro _LOGICLIB_TEMP + StrCpy $_LOGICLIB_TEMP "0" +;if path is not blank, continue to next check + StrCmp `${_b}` `` +3 0 +;if directory exists, continue to confirm exists + IfFileExists `${_b}\*.*` 0 +2 + StrCpy $_LOGICLIB_TEMP "1" + StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}` + !macroend + !define DirExists `"" DirExists` + +# Get parent directory +# Share this function both on installer and uninstaller + !macro GetParent un + Function ${un}GetParent + Exch $0 ; old $0 is on top of stack + Push $1 + Push $2 + StrCpy $1 -1 + ${Do} + StrCpy $2 $0 1 $1 + ${If} $2 == "" + ${OrIf} $2 == "\" + ${ExitDo} + ${EndIf} + IntOp $1 $1 - 1 + ${Loop} + StrCpy $0 $0 $1 + Pop $2 + Pop $1 + Exch $0 ; put $0 on top of stack, restore $0 to original value + FunctionEnd + !macroend + + !insertmacro GetParent "" + !insertmacro GetParent "un." + +# Get home directory + !macro GetHomeDir un + Function ${un}GetHomeDir + Push $0 + Push $1 + ReadEnvStr $0 "HOME" + ${If} $0 == "" + ReadEnvStr $0 "HOMEDRIVE" + ReadEnvStr $1 "HOMEPATH" + StrCpy $0 "$0$1" + ${If} $0 == "" + ReadEnvStr $0 "USERPROFILE" + ${EndIf} + ${EndIf} + Pop $1 + Exch $0 ; put $0 on top of stack, restore $0 to original value + FunctionEnd + !macroend + + !insertmacro GetHomeDir "" + !insertmacro GetHomeDir "un." + +# Saving the status of sections of the current installation in the registry + !macro SaveSectionSelection section_id reg_value + ${If} ${SectionIsSelected} ${section_id} + WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 1 + ${Else} + WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 0 + ${EndIf} + !macroend + +# Reading the status of sections from the registry of the previous installation + !macro LoadSectionSelection section_id reg_value + ClearErrors + ReadRegDWORD $3 HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} + ${IfNot} ${Errors} + ${If} $3 = 1 + !insertmacro SelectSection ${section_id} + ${Else} + !insertmacro UnselectSection ${section_id} + ${EndIf} + ${EndIf} + !macroend + +# Reading the settings for _vimrc from the registry of a previous installation + !macro LoadDefaultVimrc out_var reg_value default_value + ClearErrors + ReadRegStr ${out_var} HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} + ${If} ${Errors} + ${OrIf} ${out_var} == "" + StrCpy ${out_var} ${default_value} + ${EndIf} + !macroend + +# Get user locale + !if ${HAVE_NLS} + Var lng_usr ; variable containing the locale of the current user + + !include "StrFunc.nsh" + ${StrRep} + + Function GetUserLocale + ClearErrors + System::Call \ + 'kernel32::GetUserDefaultLocaleName(t.r19, *i${NSIS_MAX_STRLEN})' + StrCmp $R9 "zh-cn" coincide 0 + StrCmp $R9 "zh-tw" coincide 0 + StrCmp $R9 "pt-br" 0 part + coincide: + System::Call 'User32::CharLower(t r19 r19)*i${NSIS_MAX_STRLEN}' + ${StrRep} $lng_usr "$R9" "-" "_" + Goto done + part: + StrCpy $lng_usr $R9 2 + done: + FunctionEnd + !endif + + + +!endif # __AUXILIARY__NSH__ +# vi:set ts=8 sw=2 sts=2 tw=79 wm=0 ft=nsis: diff --git a/nsis/gvim.nsi b/nsis/gvim.nsi index 4b47536a06..fe85798c23 100644 --- a/nsis/gvim.nsi +++ b/nsis/gvim.nsi @@ -1,6 +1,6 @@ # NSIS file to create a self-installing exe for Vim. # It requires NSIS version 3.0 or later. -# Last Change: 2025-08-30 +# Last Change: 2025-09-03 # Unicode true @@ -87,39 +87,8 @@ Unicode true !include "nsDialogs.nsh" !include "Sections.nsh" !include "x64.nsh" -!include "StrFunc.nsh" -${StrRep} -# See https://nsis.sourceforge.io/LogicLib -;FileExists is already part of LogicLib, but returns true for directories -;as well as files -!macro _FileExists2 _a _b _t _f - !insertmacro _LOGICLIB_TEMP - StrCpy $_LOGICLIB_TEMP "0" -;if path is not blank, continue to next check - StrCmp `${_b}` `` +4 0 -;if path exists, continue to next check (IfFileExists returns true if this -;is a directory) - IfFileExists `${_b}` `0` +3 -;if path is not a directory, continue to confirm exists - IfFileExists `${_b}\*.*` +2 0 -StrCpy $_LOGICLIB_TEMP "1" ;file exists -;now we have a definitive value - the file exists or it does not - StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}` -!macroend -!undef FileExists -!define FileExists `"" FileExists2` -!macro _DirExists _a _b _t _f - !insertmacro _LOGICLIB_TEMP - StrCpy $_LOGICLIB_TEMP "0" -;if path is not blank, continue to next check - StrCmp `${_b}` `` +3 0 -;if directory exists, continue to confirm exists - IfFileExists `${_b}\*.*` 0 +2 - StrCpy $_LOGICLIB_TEMP "1" - StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}` -!macroend -!define DirExists `"" DirExists` +!include .\auxiliary.nsh # helper file !define PRODUCT "Vim ${VER_MAJOR}.${VER_MINOR}" !define UNINST_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall" @@ -268,9 +237,6 @@ Var vim_nsd_mouse Var vim_compat_stat Var vim_keymap_stat Var vim_mouse_stat -!if ${HAVE_NLS} - Var lng_usr -!endif # Reserve files ReserveFile ${VIMSRC}\installw32.exe @@ -278,54 +244,6 @@ ReserveFile ${VIMSRC}\installw32.exe ########################################################## # Functions -# Get parent directory -# Share this function both on installer and uninstaller -!macro GetParent un -Function ${un}GetParent - Exch $0 ; old $0 is on top of stack - Push $1 - Push $2 - StrCpy $1 -1 - ${Do} - StrCpy $2 $0 1 $1 - ${If} $2 == "" - ${OrIf} $2 == "\" - ${ExitDo} - ${EndIf} - IntOp $1 $1 - 1 - ${Loop} - StrCpy $0 $0 $1 - Pop $2 - Pop $1 - Exch $0 ; put $0 on top of stack, restore $0 to original value -FunctionEnd -!macroend - -!insertmacro GetParent "" -!insertmacro GetParent "un." - -# Get home directory -!macro GetHomeDir un -Function ${un}GetHomeDir - Push $0 - Push $1 - ReadEnvStr $0 "HOME" - ${If} $0 == "" - ReadEnvStr $0 "HOMEDRIVE" - ReadEnvStr $1 "HOMEPATH" - StrCpy $0 "$0$1" - ${If} $0 == "" - ReadEnvStr $0 "USERPROFILE" - ${EndIf} - ${EndIf} - Pop $1 - Exch $0 # put $0 on top of stack, restore $0 to original value -FunctionEnd -!macroend - -!insertmacro GetHomeDir "" -!insertmacro GetHomeDir "un." - # Check if Vim is already installed. # return: Installed directory. If not found, it will be empty. Function CheckOldVim @@ -728,14 +646,6 @@ Section -call_install_exe SectionEnd ########################################################## -!macro SaveSectionSelection section_id reg_value - ${If} ${SectionIsSelected} ${section_id} - WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 1 - ${Else} - WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 0 - ${EndIf} -!macroend - Section -post # Get estimated install size SectionGetSize ${id_section_exe} $3 @@ -789,27 +699,6 @@ Section -post SectionEnd ########################################################## -!macro LoadSectionSelection section_id reg_value - ClearErrors - ReadRegDWORD $3 HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} - ${IfNot} ${Errors} - ${If} $3 = 1 - !insertmacro SelectSection ${section_id} - ${Else} - !insertmacro UnselectSection ${section_id} - ${EndIf} - ${EndIf} -!macroend - -!macro LoadDefaultVimrc out_var reg_value default_value - ClearErrors - ReadRegStr ${out_var} HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} - ${If} ${Errors} - ${OrIf} ${out_var} == "" - StrCpy ${out_var} ${default_value} - ${EndIf} -!macroend - Function .onInit !if ${HAVE_MULTI_LANG} # Select a language (or read from the registry). @@ -817,19 +706,7 @@ Function .onInit !endif !if ${HAVE_NLS} - ClearErrors - System::Call \ - 'kernel32::GetUserDefaultLocaleName(t.r19, *i${NSIS_MAX_STRLEN})' - StrCmp $R9 "zh-cn" coincide 0 - StrCmp $R9 "zh-tw" coincide 0 - StrCmp $R9 "pt-br" 0 part - coincide: - System::Call 'User32::CharLower(t r19 r19)*i${NSIS_MAX_STRLEN}' - ${StrRep} $lng_usr "$R9" "-" "_" - Goto done - part: - StrCpy $lng_usr $R9 2 - done: + call GetUserLocale !endif ${If} $INSTDIR == ${DEFAULT_INSTDIR}