summaryrefslogtreecommitdiff
path: root/uvim/nsis/auxiliary.nsh
blob: 68471a7ad83c0c51c9aa4099472bab3279167fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# -*- coding: utf-8 -*-
# NSIS helper file for creating a self-installing exe for MNV.
# 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_MNV}" ${reg_value} 1
    ${Else}
      WriteRegDWORD HKLM "${UNINST_REG_KEY_MNV}" ${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_MNV}" ${reg_value}
    ${IfNot} ${Errors}
      ${If} $3 = 1
	!insertmacro SelectSection ${section_id}
      ${Else}
	!insertmacro UnselectSection ${section_id}
      ${EndIf}
    ${EndIf}
  !macroend

# Reading the settings for _mnvrc from the registry of a previous installation
  !macro LoadDefaultMNVrc out_var reg_value default_value
    ClearErrors
    ReadRegStr ${out_var} HKLM "${UNINST_REG_KEY_MNV}" ${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: