0
0
mirror of https://github.com/vim/vim.git synced 2025-10-16 07:24:23 -04:00

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 <restorer@mail2k.ru>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
RestorerZ
2025-09-29 19:48:54 +00:00
committed by Christian Brabandt
parent f9feda2d6d
commit c55efbb148
3 changed files with 152 additions and 126 deletions

View File

@@ -639,6 +639,7 @@ SRC_DOS = \
src/tee/tee.c \ src/tee/tee.c \
src/xxd/Make_ming.mak \ src/xxd/Make_ming.mak \
src/xxd/Make_mvc.mak \ src/xxd/Make_mvc.mak \
nsis/auxiliary.nsh \
nsis/gvim.nsi \ nsis/gvim.nsi \
nsis/gvim_version.nsh \ nsis/gvim_version.nsh \
nsis/Makefile \ nsis/Makefile \

148
nsis/auxiliary.nsh Normal file
View File

@@ -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:

View File

@@ -1,6 +1,6 @@
# NSIS file to create a self-installing exe for Vim. # NSIS file to create a self-installing exe for Vim.
# It requires NSIS version 3.0 or later. # It requires NSIS version 3.0 or later.
# Last Change: 2025-08-30 # Last Change: 2025-09-03
# #
Unicode true Unicode true
@@ -87,39 +87,8 @@ Unicode true
!include "nsDialogs.nsh" !include "nsDialogs.nsh"
!include "Sections.nsh" !include "Sections.nsh"
!include "x64.nsh" !include "x64.nsh"
!include "StrFunc.nsh"
${StrRep}
# See https://nsis.sourceforge.io/LogicLib !include .\auxiliary.nsh # helper file
;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`
!define PRODUCT "Vim ${VER_MAJOR}.${VER_MINOR}" !define PRODUCT "Vim ${VER_MAJOR}.${VER_MINOR}"
!define UNINST_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall" !define UNINST_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall"
@@ -268,9 +237,6 @@ Var vim_nsd_mouse
Var vim_compat_stat Var vim_compat_stat
Var vim_keymap_stat Var vim_keymap_stat
Var vim_mouse_stat Var vim_mouse_stat
!if ${HAVE_NLS}
Var lng_usr
!endif
# Reserve files # Reserve files
ReserveFile ${VIMSRC}\installw32.exe ReserveFile ${VIMSRC}\installw32.exe
@@ -278,54 +244,6 @@ ReserveFile ${VIMSRC}\installw32.exe
########################################################## ##########################################################
# Functions # 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. # Check if Vim is already installed.
# return: Installed directory. If not found, it will be empty. # return: Installed directory. If not found, it will be empty.
Function CheckOldVim Function CheckOldVim
@@ -728,14 +646,6 @@ Section -call_install_exe
SectionEnd 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 Section -post
# Get estimated install size # Get estimated install size
SectionGetSize ${id_section_exe} $3 SectionGetSize ${id_section_exe} $3
@@ -789,27 +699,6 @@ Section -post
SectionEnd 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 Function .onInit
!if ${HAVE_MULTI_LANG} !if ${HAVE_MULTI_LANG}
# Select a language (or read from the registry). # Select a language (or read from the registry).
@@ -817,19 +706,7 @@ Function .onInit
!endif !endif
!if ${HAVE_NLS} !if ${HAVE_NLS}
ClearErrors call GetUserLocale
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:
!endif !endif
${If} $INSTDIR == ${DEFAULT_INSTDIR} ${If} $INSTDIR == ${DEFAULT_INSTDIR}