|
3 | 3 | @AUTHORS = Zinthose, Iceman_K |
4 | 4 | @REVISIONS = zenpoy[http://forums.winamp.com/member.php?u=401997] |
5 | 5 | @URL = http://nsis.sourceforge.net/mediawiki/index.php?title=Enumerate_INI |
| 6 | + @LICENSE = zlib/libpng License (https://nsis.sourceforge.io/License) |
6 | 7 | */ |
7 | 8 | !ifndef __EnumIni__ |
8 | 9 | !define __EnumIni__ |
|
13 | 14 | !include "StrFunc.nsh" |
14 | 15 | ${StrLoc} |
15 | 16 | !endif |
16 | | - |
| 17 | + |
17 | 18 | ## Macro to remove leading and trailing whitespaces from a string. |
18 | | - ## Derived from the function originaly posted by Iceman_K at: |
| 19 | + ## Derived from the function originaly posted by Iceman_K at: |
19 | 20 | ## http://nsis.sourceforge.net/Remove_leading_and_trailing_whitespaces_from_a_string |
20 | 21 | !ifmacrondef _Trim |
21 | 22 | !macro _Trim _UserVar _OriginalString |
22 | 23 | !define Trim_UID ${__LINE__} |
23 | | - |
| 24 | + |
24 | 25 | Push $R1 |
25 | 26 | Push $R2 |
26 | 27 | Push `${_OriginalString}` |
27 | 28 | Pop $R1 |
28 | | - |
| 29 | + |
29 | 30 | Loop_${Trim_UID}: |
30 | 31 | StrCpy $R2 "$R1" 1 |
31 | 32 | StrCmp "$R2" " " TrimLeft_${Trim_UID} |
32 | 33 | StrCmp "$R2" "$\r" TrimLeft_${Trim_UID} |
33 | 34 | StrCmp "$R2" "$\n" TrimLeft_${Trim_UID} |
34 | 35 | StrCmp "$R2" "$\t" TrimLeft_${Trim_UID} |
35 | 36 | GoTo Loop2_${Trim_UID} |
36 | | - TrimLeft_${Trim_UID}: |
| 37 | + TrimLeft_${Trim_UID}: |
37 | 38 | StrCpy $R1 "$R1" "" 1 |
38 | 39 | Goto Loop_${Trim_UID} |
39 | | - |
| 40 | + |
40 | 41 | Loop2_${Trim_UID}: |
41 | 42 | StrCpy $R2 "$R1" 1 -1 |
42 | 43 | StrCmp "$R2" " " TrimRight_${Trim_UID} |
43 | 44 | StrCmp "$R2" "$\r" TrimRight_${Trim_UID} |
44 | 45 | StrCmp "$R2" "$\n" TrimRight_${Trim_UID} |
45 | 46 | StrCmp "$R2" "$\t" TrimRight_${Trim_UID} |
46 | 47 | GoTo Done_${Trim_UID} |
47 | | - TrimRight_${Trim_UID}: |
| 48 | + TrimRight_${Trim_UID}: |
48 | 49 | StrCpy $R1 "$R1" -1 |
49 | 50 | Goto Loop2_${Trim_UID} |
50 | | - |
| 51 | + |
51 | 52 | Done_${Trim_UID}: |
52 | 53 | Pop $R2 |
53 | 54 | Exch $R1 |
|
60 | 61 | !define Trim `!insertmacro _Trim` |
61 | 62 | !endif |
62 | 63 | !endif |
63 | | - |
| 64 | + |
64 | 65 | ## Global variable needed for indexing the enumerations |
65 | 66 | !ifmacrondef EnumIni_IDX_VAR |
66 | 67 | !macro EnumIni_IDX_VAR |
67 | 68 | !ifndef EnumIni_IDX_VAR |
68 | 69 | VAR /GLOBAL EnumIni_IDX_VAR |
69 | 70 | !define EnumIni_IDX_VAR $EnumIni_IDX_VAR |
70 | 71 | !endif |
71 | | - !macroend |
| 72 | + !macroend |
72 | 73 | !endif |
73 | | - |
| 74 | + |
74 | 75 | /* ## EnumIniKey ## |
75 | | - Nearly identical in use to the builtin EnumRegKey function, the EnumIniKey macro |
| 76 | + Nearly identical in use to the builtin EnumRegKey function, the EnumIniKey macro |
76 | 77 | allows for enumeration of an existing ini file's sections. |
77 | | - |
| 78 | +
|
78 | 79 | ## Example ## |
79 | 80 | StrCpy $0 0 |
80 | 81 | loop: |
|
89 | 90 | !macro _EnumIniKey _UserVar _IniFilePath _Index |
90 | 91 | !define EnumIniKey_UID ${__LINE__} |
91 | 92 | ClearErrors |
92 | | - |
| 93 | + |
93 | 94 | Push $R0 |
94 | 95 | Push $R1 |
95 | | - |
| 96 | + |
96 | 97 | Push `${_IniFilePath}` |
97 | 98 | Push `${_Index}` |
98 | | - |
| 99 | + |
99 | 100 | Pop $R1 ; ${_Index} |
100 | 101 | Pop $R0 ; ${_IniFilePath} |
101 | | - |
| 102 | + |
102 | 103 | IfFileExists $R0 0 Else_IfFileExists_${EnumIniKey_UID} |
103 | | - StrCpy $EnumIni_IDX_VAR -1 |
| 104 | + StrCpy $EnumIni_IDX_VAR -1 |
104 | 105 | ## PATCH Added to Correct 0 length file infinite loop issue discovered by zenpoy |
105 | 106 | ## [http://forums.winamp.com/member.php?u=401997] on January 9th 2012 |
106 | 107 | ${LineSum} $R0 $R1 |
|
114 | 115 | StrCpy $R0 '' |
115 | 116 | SetErrors |
116 | 117 | EndIf_FileExists_${EnumIniKey_UID}: |
117 | | - |
| 118 | + |
118 | 119 | Pop $R1 |
119 | 120 | Exch $R0 |
120 | 121 | Pop ${_UserVar} |
121 | | - |
| 122 | + |
122 | 123 | !undef EnumIniKey_UID |
123 | 124 | !macroend |
124 | 125 | !ifndef EnumIniKey |
|
129 | 130 | !verbose 0 |
130 | 131 | Function EnumIniKey_CALLBACK |
131 | 132 | !insertmacro _Trim $R9 $R9 |
132 | | - |
| 133 | + |
133 | 134 | StrCmp $R9 '' End |
134 | 135 | StrCpy $R0 $R9 1 |
135 | 136 | StrCmp $R0 '[' 0 End |
|
143 | 144 | Return |
144 | 145 | End: |
145 | 146 | StrCpy $R0 '' |
146 | | - Push '' |
| 147 | + Push '' |
147 | 148 | FunctionEnd |
148 | 149 | !verbose pop |
149 | 150 | !else |
150 | 151 | !Error `An illegal attempt was made to insert the EnumIniValue_CALLBACK function outside the Global namespace!` |
151 | 152 | !endif |
152 | 153 | !endif |
153 | | - |
| 154 | + |
154 | 155 | /* ## EnumIniValue ## |
155 | | - Nearly identical in use to the builtin EnumRegValue function, the EnumIniValue macro |
| 156 | + Nearly identical in use to the builtin EnumRegValue function, the EnumIniValue macro |
156 | 157 | allows for enumeration of an existing ini file section. |
157 | | - |
| 158 | +
|
158 | 159 | ## Example ## |
159 | 160 | StrCpy $0 0 |
160 | 161 | loop: |
|
170 | 171 | !macro _EnumIniValue _UserVar _IniFilePath _Section _Index |
171 | 172 | !define EnumIniValue_UID ${__LINE__} |
172 | 173 | ClearErrors |
173 | | - |
| 174 | + |
174 | 175 | Push $R0 |
175 | 176 | Push $R1 |
176 | 177 | Push $R2 |
177 | 178 | Push $R3 |
178 | | - |
| 179 | + |
179 | 180 | Push `${_IniFilePath}` |
180 | 181 | Push `${_Section}` |
181 | 182 | Push `${_Index}` |
182 | | - |
| 183 | + |
183 | 184 | Pop $R2 ; ${_Index} |
184 | 185 | Pop $R1 ; ${_Section} |
185 | 186 | Pop $R0 ; ${_IniFilePath} |
186 | | - |
| 187 | + |
187 | 188 | IfFileExists $R0 0 Else_IfFileExists_${EnumIniValue_UID} |
188 | | - StrCpy $EnumIni_IDX_VAR -1 |
| 189 | + StrCpy $EnumIni_IDX_VAR -1 |
189 | 190 | ${LineFind} $R0 "/NUL" "1:-1" "EnumIniValue_CALLBACK" |
190 | 191 | IfErrors Else_IfFileExists_${EnumIniValue_UID} |
191 | 192 | Goto EndIf_FileExists_${EnumIniValue_UID} |
192 | 193 | Else_IfFileExists_${EnumIniValue_UID}: |
193 | 194 | StrCpy $R0 '' |
194 | 195 | SetErrors |
195 | 196 | EndIf_FileExists_${EnumIniValue_UID}: |
196 | | - |
| 197 | + |
197 | 198 | Pop $R3 |
198 | 199 | Pop $R2 |
199 | 200 | Pop $R1 |
|
209 | 210 | !verbose 0 |
210 | 211 | Function EnumIniValue_CALLBACK |
211 | 212 | !insertmacro _Trim $R9 $R9 |
212 | | - |
| 213 | + |
213 | 214 | StrCmp $R9 '' End |
214 | 215 | StrCpy $R0 $R9 1 |
215 | 216 | StrCmp $R0 ';' End |
|
229 | 230 | StrCpy $R3 $R9 |
230 | 231 | End: |
231 | 232 | StrCpy $R0 '' |
232 | | - Push '' |
| 233 | + Push '' |
233 | 234 | FunctionEnd |
234 | 235 | !verbose pop |
235 | 236 | !else |
|
0 commit comments