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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
;NSIS Modern User Interface
;Start Menu Folder Selection Example Script
;Modified by Fahim Khan, Saurabh Bansode, Rahul Paknikar - 01_03_2020
;Made by eSim Team, FOSSEE, IIT Bombay
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
!include "ZipDLL.nsh"
!include "EnvVarUpdate.nsh"
!include "x64.nsh"
;--------------------------------
;--------------------------------
; StrContains
; This function does a case sensitive searches for an occurrence of a substring in a string.
; It returns the substring if it is found.
; Otherwise it returns null("").
; Written by kenglish_hi
; Adapted from StrReplace written by dandaman32
Var STR_HAYSTACK
Var STR_NEEDLE
Var STR_CONTAINS_VAR_1
Var STR_CONTAINS_VAR_2
Var STR_CONTAINS_VAR_3
Var STR_CONTAINS_VAR_4
Var STR_RETURN_VAR
Function StrContains
Exch $STR_NEEDLE
Exch 1
Exch $STR_HAYSTACK
; Uncomment to debug
;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
StrCpy $STR_RETURN_VAR ""
StrCpy $STR_CONTAINS_VAR_1 -1
StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
loop:
IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
Goto loop
found:
StrCpy $STR_RETURN_VAR $STR_NEEDLE
Goto done
done:
Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
Exch $STR_RETURN_VAR
FunctionEnd
!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
Push `${HAYSTACK}`
Push `${NEEDLE}`
Call StrContains
Pop `${OUT}`
!macroend
!define StrContains '!insertmacro "_StrContainsConstructor"'
;--------------------------------
;General
!define PRODUCT_NAME "eSim"
!define PRODUCT_VERSION "2.0"
!define VERSION "2.0.0.0"
!define PRODUCT_PUBLISHER "FOSSEE, IIT Bombay"
!define PRODUCT_WEB_SITE "https://esim.fossee.in/"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
VIAddVersionKey "ProductName" "eSim"
VIProductVersion "${VERSION}"
VIFileVersion "${VERSION}"
VIAddVersionKey "FileVersion" "${VERSION}"
VIAddVersionKey "CompanyName" "FOSSEE, IIT Bombay"
VIAddVersionKey "LegalCopyright" "Copyright (C) 2007 Free Software Foundation, Inc."
VIAddVersionKey "FileDescription" "Installer for eSim EDA Suite"
;Default installation folder
InstallDir "C:\FOSSEE"
;Request application privileges for Admin Rights
RequestExecutionLevel admin
;Get installation folder from registry if available
InstallDirRegKey HKLM "Software\eSim" ""
!include LogicLib.nsh
Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
FunctionEnd
;--------------------------------
;Variables
Var StartMenuFolder
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "LICENSE.rtf"
!insertmacro MUI_PAGE_DIRECTORY
;Start Menu Folder Page Configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\eSim"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "eSim-2.0_install.exe"
Function .onVerifyInstDir
${StrContains} $0 "Program Files" $INSTDIR
StrCmp $0 "" notfound
MessageBox MB_ICONSTOP|MB_OK \
"Installation in 'Program Files' is not allowed, choose another directory."
Abort
notfound:
${StrContains} $0 " " $INSTDIR
StrCmp $0 "" PathGood
MessageBox MB_ICONSTOP|MB_OK \
"Installation path containing spaces is not allowed, choose another directory."
Abort
PathGood:
FunctionEnd
;Installer Sections
Section -NgspiceSim
;Current section needs an additional "size_kb" kilobytes of disk space
AddSize 2726298
SetOutPath "$EXEDIR"
File "spice.zip"
File "eSim.zip"
File "logo.ico"
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
ZipDLL::extractall "$EXEDIR\spice.zip" "$INSTDIR\"
ZipDLL::extractall "$EXEDIR\eSim.zip" "$INSTDIR\"
;Setting Env Variable for Ngspice
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\spice\bin"
;Copying Folder to install directory
SetOutPath "$INSTDIR\eSim"
;File /nonfatal /a /r "eSim\"
;Store installation folder
WriteRegStr HKLM "Software\eSim" "" $INSTDIR
;Create eSim config directory
CreateDirectory $PROFILE\.esim
CopyFiles "$EXEDIR\logo.ico" "$PROFILE\.esim"
FileOpen $0 "$PROFILE\.esim\config.ini" w
FileWrite $0 `[eSim]$\n`
FileWrite $0 `eSim_HOME = $INSTDIR\eSim$\n`
FileWrite $0 `LICENSE = %(eSim_HOME)s\LICENSE.rtf$\n`
FileWrite $0 `KicadLib = %(eSim_HOME)s\library\kicadLibrary.zip$\n`
FileWrite $0 `IMAGES = %(eSim_HOME)s\images$\n`
FileWrite $0 `VERSION = %(eSim_HOME)s\VERSION$\n`
FileWrite $0 `MODELICA_MAP_JSON = %(eSim_HOME)s\library\ngspicetoModelica\Mapping.json$\n`
FileClose $0
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
;Create shortcuts
;create desktop shortcut
CreateShortCut "$PROFILE\..\Public\Desktop\eSim.lnk" "$INSTDIR\eSim\eSim" "" "$PROFILE\.esim\logo.ico" "" SW_SHOWMINIMIZED
;Remove not required files
Delete "$EXEDIR\spice.zip"
Delete "$EXEDIR\eSim.zip"
Delete "$EXEDIR\logo.ico"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section -InstallKiCad
SetOutPath "$EXEDIR"
File "kicad-4.0.7-i686.exe"
SetOutPath "$INSTDIR"
SetDetailsPrint both
DetailPrint "Installing: KiCad......"
SetDetailsPrint listonly
ExecWait '"$EXEDIR\kicad-4.0.7-i686.exe" /S /D=$INSTDIR\KiCad'
SetDetailsPrint both
Goto endActiveSync
endActiveSync:
;Remove not required files
Delete "$EXEDIR\kicad-4.0.7-i686.exe"
Delete "$PROFILE\..\Public\Desktop\KiCad.lnk"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\KiCad\bin"
ZipDLL::extractall "$INSTDIR\eSim\library\kicadLibrary.zip" "$INSTDIR\eSim\library\"
;CopyFiles "$INSTDIR\eSim\library\kicadLibrary\library\*" "$INSTDIR\KiCad\share\kicad\library\"
;Copy KiCad library made for eSim
CopyFiles "$INSTDIR\eSim\library\kicadLibrary\kicad_eSim-Library\*" "$INSTDIR\KiCad\share\kicad\library\"
CopyFiles "$INSTDIR\eSim\library\kicadLibrary\modules\*" "$INSTDIR\KiCad\share\kicad\modules\"
CopyFiles "$INSTDIR\eSim\library\kicadLibrary\template\*" "$INSTDIR\KiCad\share\kicad\template\"
;Remove older KiCad config files (if any).
RMDir /r "$PROFILE\AppData\Roaming\kicad"
CreateDirectory "$PROFILE\AppData\Roaming\kicad"
CopyFiles "$INSTDIR\eSim\library\supportFiles\fp-lib-table" "$PROFILE\AppData\Roaming\kicad\"
CopyFiles "$INSTDIR\eSim\library\supportFiles\fp-lib-table-online" "$PROFILE\AppData\Roaming\kicad\"
FileOpen $0 "$INSTDIR\eSim\library\supportFiles\kicad_config_path.txt" w
FileWrite $0 `$PROFILE\AppData\Roaming\kicad$\n`
FileClose $0
;Remove extracted KiCad Library - not needed anymore
RMDir /r "$INSTDIR\eSim\library\kicadLibrary"
SectionEnd
Section -AdditionalIcons
SetOutPath "$INSTDIR"
CreateDirectory "$SMPROGRAMS\eSim"
CreateShortCut "$SMPROGRAMS\eSim\Uninstall.lnk" "$INSTDIR\eSim\uninst-eSim.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\eSim\uninst-eSim.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\eSim\uninst-eSim.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
;Function un.onUninstSuccess
; HideWindow
; MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
;FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
FunctionEnd
Section Uninstall
;Note that in uninstaller code, $INSTDIR contains the directory where the uninstaller lies
Delete "$INSTDIR\uninst-eSim.exe"
Delete "$SMPROGRAMS\eSim\Uninstall.lnk"
;Removing Env Variable for KiCad
GetFullPathName $0 $INSTDIR\..\KiCad\bin
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" $0
;Remove KiCad config
RMDir /r "$PROFILE\AppData\Roaming\kicad"
;Removing KiCad
ExecWait '"$INSTDIR\..\KiCad\uninstaller.exe" /S'
Goto endActiveSync
endActiveSync:
;Removing Env Variable for Ngspice
GetFullPathName $0 $INSTDIR\..\spice\bin
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" $0
;Removing Ngspice
RMDir /r "$INSTDIR\..\spice"
;Removing eSim
RMDir /r "$PROFILE\.esim"
RMDir "$SMPROGRAMS\eSim"
RMDir /r "$INSTDIR\..\eSim"
Delete "$PROFILE\..\Public\Desktop\eSim.lnk"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
;SetAutoClose true
SectionEnd
;Descriptions--------------------
;Language strings
;LangString DESC_NgspiceSim ${LANG_ENGLISH} "Ngspice is a mixed-level/mixed-signal circuit simulator. Its code is based on three open source software packages: Spice3f5, Cider1b1 and Xspice. Ngspice is part of gEDA project, a full GPL'd suite of Electronic Design Automation tools."
;Assign language strings to sections
;!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
;!insertmacro MUI_DESCRIPTION_TEXT ${NgspiceSim} $(DESC_NgspiceSim)
;!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
|