~ubuntu-branches/ubuntu/lucid/upnp-inspector/lucid

« back to all changes in this revision

Viewing changes to win32/win32.nsi

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-07-24 07:13:32 UTC
  • Revision ID: james.westby@ubuntu.com-20090724071332-yrscm1j820q0sihx
Tags: upstream-0.2.2+dfsg
ImportĀ upstreamĀ versionĀ 0.2.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
; global defines
 
3
!define INSPECTOR_VERSION "0.2.0" 
 
4
!define INSTALLER_VERSION "beta5"
 
5
!define GTK_RUNTIME_INSTALLER                   "gtk2-runtime*.exe"
 
6
!define GTK_MIN_VERSION                                 "2.6.10"
 
7
!define GTK_REG_KEY                                             "SOFTWARE\GTK\2.0"
 
8
!define GTK_DEFAULT_INSTALL_PATH                "$COMMONFILES\GTK\2.0"
 
9
 
 
10
; global vars
 
11
Var GTK_FOLDER
 
12
Var StartMenuFolder
 
13
Var name
 
14
Var ISSILENT
 
15
 
 
16
; global configuration
 
17
SetCompress force
 
18
SetCompressor /SOLID lzma
 
19
 
 
20
Name "UPnP Inspector ${INSPECTOR_VERSION}"
 
21
OutFile "UPnPInspector-${INSPECTOR_VERSION}-${INSTALLER_VERSION}-setup.exe"
 
22
 
 
23
InstallDir "$PROGRAMFILES\UPnPInspector"
 
24
 
 
25
XPStyle on
 
26
 
 
27
; helpers and macros
 
28
!include "MUI.nsh"
 
29
!include "Sections.nsh"
 
30
!include "WinVer.nsh"
 
31
!include "LogicLib.nsh"
 
32
 
 
33
!include "FileFunc.nsh"
 
34
!insertmacro GetParameters
 
35
!insertmacro GetOptions
 
36
!insertmacro GetParent
 
37
 
 
38
!include "WordFunc.nsh"
 
39
!insertmacro VersionCompare
 
40
!insertmacro WordFind
 
41
!insertmacro un.WordFind
 
42
 
 
43
!define MUI_Icon "inspector-icon.ico"
 
44
 
 
45
; -----------------------------------
 
46
; THE MENU
 
47
!define MUI_ABORTWARNING
 
48
 
 
49
!define MUI_FINISHPAGE_NOAUTOCLOSE
 
50
!define MUI_FINISHPAGE_RUN                      "$INSTDIR\upnp-inspector.exe"
 
51
 
 
52
!define MUI_PAGE_CUSTOMFUNCTION_PRE             preWelcomePage
 
53
!insertmacro MUI_PAGE_WELCOME
 
54
 
 
55
; GTK+ install page
 
56
!define MUI_PAGE_CUSTOMFUNCTION_PRE             preGtkDirPage
 
57
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE           postGtkDirPage
 
58
;!define MUI_DIRECTORYPAGE_VARIABLE             $GTK_FOLDER
 
59
!insertmacro MUI_PAGE_COMPONENTS
 
60
 
 
61
!insertmacro MUI_PAGE_DIRECTORY
 
62
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
 
63
!insertmacro MUI_PAGE_INSTFILES
 
64
!insertmacro MUI_PAGE_FINISH
 
65
 
 
66
!insertmacro MUI_LANGUAGE "English"
 
67
 
 
68
  ;Language strings
 
69
  LangString DESC_SecDummy ${LANG_ENGLISH} "UPnP Inspector ${INSPECTOR_VERSION}"
 
70
  LangString GTK_SECTION_DESCRIPTION ${LANG_ENGLISH} "GTK+ Package. To be installed if you dont have pre installed GTK+"
 
71
 
 
72
  ;Assign language strings to sections
 
73
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
 
74
    !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
 
75
        !insertmacro MUI_DESCRIPTION_TEXT ${SecGtk} $(GTK_SECTION_DESCRIPTION)
 
76
  !insertmacro MUI_FUNCTION_DESCRIPTION_END
 
77
 
 
78
Section "Inspector" SecDummy
 
79
        SetOutPath "$INSTDIR"
 
80
        File /r "build\*.*"
 
81
 
 
82
        WriteUninstaller "$INSTDIR\uninstall.exe"
 
83
        
 
84
        !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
 
85
                ;Create shortcuts
 
86
                CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
 
87
                CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
 
88
                CreateShortCut "$SMPROGRAMS\$StartMenuFolder\UPnP Inspector.lnk" "$INSTDIR\upnp-inspector.exe"
 
89
        !insertmacro MUI_STARTMENU_WRITE_END
 
90
 
 
91
SectionEnd
 
92
 
 
93
;--------------------------------
 
94
;GTK+ Runtime Install Section
 
95
 
 
96
Section "Gtk Installer" SecGtk
 
97
 
 
98
  Call CheckUserInstallRights
 
99
  Pop $R1
 
100
 
 
101
  SetOutPath $TEMP
 
102
  SetOverwrite on
 
103
  File /oname=gtk-runtime.exe ${GTK_RUNTIME_INSTALLER}
 
104
  SetOverwrite off
 
105
 
 
106
  Call DoWeNeedGtk
 
107
  Pop $R0
 
108
  Pop $R6
 
109
 
 
110
  StrCmp $R0 "0" have_gtk
 
111
  StrCmp $R0 "1" upgrade_gtk
 
112
  StrCmp $R0 "2" upgrade_gtk
 
113
  ;StrCmp $R0 "3" no_gtk no_gtk
 
114
 
 
115
  ;no_gtk:
 
116
    StrCmp $R1 "NONE" gtk_no_install_rights
 
117
    ClearErrors
 
118
    ExecWait '"$TEMP\gtk-runtime.exe" /L=$LANGUAGE $ISSILENT /D=$GTK_FOLDER'
 
119
    IfErrors gtk_install_error done
 
120
 
 
121
  upgrade_gtk:
 
122
    StrCpy $GTK_FOLDER $R6
 
123
    StrCmp $R0 "2" +2 ; Upgrade isn't optional
 
124
    MessageBox MB_YESNO $(GTK_UPGRADE_PROMPT) /SD IDYES IDNO done
 
125
    ClearErrors
 
126
    ExecWait '"$TEMP\gtk-runtime.exe" /L=$LANGUAGE $ISSILENT /D=$GTK_FOLDER'
 
127
    IfErrors gtk_install_error done
 
128
 
 
129
    gtk_install_error:
 
130
      Delete "$TEMP\gtk-runtime.exe"
 
131
      MessageBox MB_OK $(GTK_INSTALL_ERROR) /SD IDOK
 
132
      Quit
 
133
 
 
134
  have_gtk:
 
135
    StrCpy $GTK_FOLDER $R6
 
136
    StrCmp $R1 "NONE" done ; If we have no rights, we can't re-install
 
137
    ; Even if we have a sufficient version of GTK+, we give user choice to re-install.
 
138
    ClearErrors
 
139
    ExecWait '"$TEMP\gtk-runtime.exe" /L=$LANGUAGE $ISSILENT'
 
140
    IfErrors gtk_install_error
 
141
    Goto done
 
142
 
 
143
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
144
  ; end got_install rights
 
145
 
 
146
  gtk_no_install_rights:
 
147
    ; Install GTK+ to the inspector directory
 
148
    StrCpy $GTK_FOLDER $INSTDIR
 
149
    ClearErrors
 
150
    ExecWait '"$TEMP\gtk-runtime.exe" /L=$LANGUAGE $ISSILENT /D=$GTK_FOLDER'
 
151
    IfErrors gtk_install_error
 
152
      SetOverwrite on
 
153
      ClearErrors
 
154
      CopyFiles /FILESONLY "$GTK_FOLDER\bin\*.dll" $GTK_FOLDER
 
155
      SetOverwrite off
 
156
      IfErrors gtk_install_error
 
157
        Delete "$GTK_FOLDER\bin\*.dll"
 
158
        Goto done
 
159
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
160
  ; end gtk_no_install_rights
 
161
 
 
162
  done:
 
163
    Delete "$TEMP\gtk-runtime.exe"
 
164
SectionEnd ; end of GTK+ section
 
165
 
 
166
 
 
167
Section "Uninstall" 
 
168
 
 
169
  Delete "$INSTDIR\*.*"
 
170
 
 
171
  RMDir /r "$INSTDIR"
 
172
  
 
173
  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
 
174
    
 
175
  Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk"
 
176
  Delete "$SMPROGRAMS\$StartMenuFolder\UPnP Inspector.lnk"
 
177
  RMDir "$SMPROGRAMS\$StartMenuFolder"
 
178
 
 
179
SectionEnd
 
180
 
 
181
 
 
182
; ---------------- HELPERS ------------
 
183
; Borrowed from the great pidgin project
 
184
 
 
185
;
 
186
; Usage:
 
187
; Call DoWeNeedGtk
 
188
; First Pop:
 
189
;   0 - We have the correct version
 
190
;       Second Pop: Key where Version was found
 
191
;   1 - We have an old version that should work, prompt user for optional upgrade
 
192
;       Second Pop: HKLM or HKCU depending on where GTK was found.
 
193
;   2 - We have an old version that needs to be upgraded
 
194
;       Second Pop: HKLM or HKCU depending on where GTK was found.
 
195
;   3 - We don't have Gtk+ at all
 
196
;       Second Pop: "NONE, HKLM or HKCU" depending on our rights..
 
197
;
 
198
Function DoWeNeedGtk
 
199
  ; Logic should be:
 
200
  ; - Check what user rights we have (HKLM or HKCU)
 
201
  ;   - If HKLM rights..
 
202
  ;     - Only check HKLM key for GTK+
 
203
  ;       - If installed to HKLM, check it and return.
 
204
  ;   - If HKCU rights..
 
205
  ;     - First check HKCU key for GTK+
 
206
  ;       - if good or bad exists stop and ret.
 
207
  ;     - If no hkcu gtk+ install, check HKLM
 
208
  ;       - If HKLM ver exists but old, return as if no ver exits.
 
209
  ;   - If no rights
 
210
  ;     - Check HKLM
 
211
  Push $0
 
212
  Push $1
 
213
  Push $2
 
214
  Push $3
 
215
 
 
216
  Call CheckUserInstallRights
 
217
  Pop $1
 
218
  StrCmp $1 "HKLM" check_hklm
 
219
  StrCmp $1 "HKCU" check_hkcu check_hklm
 
220
    check_hkcu:
 
221
      ReadRegStr $0 HKCU ${GTK_REG_KEY} "Version"
 
222
      StrCpy $2 "HKCU"
 
223
      StrCmp $0 "" check_hklm have_gtk
 
224
 
 
225
    check_hklm:
 
226
      ReadRegStr $0 HKLM ${GTK_REG_KEY} "Version"
 
227
      StrCpy $2 "HKLM"
 
228
      StrCmp $0 "" no_gtk have_gtk
 
229
 
 
230
  have_gtk:
 
231
    ; GTK+ is already installed; check version.
 
232
    ; Change this to not even run the GTK installer if this version is already installed.
 
233
    ${VersionCompare} ${GTK_INSTALL_VERSION} $0 $3
 
234
    IntCmp $3 1 +1 good_version good_version
 
235
    ${VersionCompare} ${GTK_MIN_VERSION} $0 $3
 
236
 
 
237
      ; Bad version. If hklm ver and we have hkcu or no rights.. return no gtk
 
238
      StrCmp $1 "NONE" no_gtk ; if no rights.. can't upgrade
 
239
      StrCmp $1 "HKCU" 0 +2   ; if HKLM can upgrade..
 
240
      StrCmp $2 "HKLM" no_gtk ; have hkcu rights.. if found hklm ver can't upgrade..
 
241
      Push $2
 
242
      IntCmp $3 1 +3
 
243
        Push "1" ; Optional Upgrade
 
244
        Goto done
 
245
        Push "2" ; Mandatory Upgrade
 
246
        Goto done
 
247
 
 
248
  good_version:
 
249
    StrCmp $2 "HKLM" have_hklm_gtk have_hkcu_gtk
 
250
      have_hkcu_gtk:
 
251
        ; Have HKCU version
 
252
        ReadRegStr $0 HKCU ${GTK_REG_KEY} "Path"
 
253
        Goto good_version_cont
 
254
 
 
255
      have_hklm_gtk:
 
256
        ReadRegStr $0 HKLM ${GTK_REG_KEY} "Path"
 
257
        Goto good_version_cont
 
258
 
 
259
    good_version_cont:
 
260
      Push $0  ; The path to existing GTK+
 
261
      Push "0"
 
262
      Goto done
 
263
 
 
264
  no_gtk:
 
265
    Push $1 ; our rights
 
266
    Push "3"
 
267
    Goto done
 
268
 
 
269
  done:
 
270
  ; The top two items on the stack are what we want to return
 
271
  Exch 4
 
272
  Pop $1
 
273
  Exch 4
 
274
  Pop $0
 
275
  Pop $3
 
276
  Pop $2
 
277
FunctionEnd
 
278
 
 
279
Function preWelcomePage
 
280
  Push $R0
 
281
 
 
282
  Push $R1
 
283
  Push $R2
 
284
 
 
285
  Call DoWeNeedGtk
 
286
  Pop $R0
 
287
  Pop $R2
 
288
  IntCmp $R0 1 gtk_selection_done gtk_not_mandatory
 
289
    ; Make the GTK+ Section RO if it is required.
 
290
    !insertmacro SetSectionFlag ${SecGtk} ${SF_RO}
 
291
    Goto gtk_selection_done
 
292
  gtk_not_mandatory:
 
293
    ; Don't select the GTK+ section if we already have this version or newer installed
 
294
    !insertmacro UnselectSection ${SecGtk}
 
295
  gtk_selection_done:
 
296
 
 
297
  ; If on Win95/98/ME warn them that the GTK+ version wont work
 
298
  ${Unless} ${IsNT}
 
299
    !insertmacro UnselectSection ${SecGtk}
 
300
    !insertmacro SetSectionFlag ${SecGtk} ${SF_RO}
 
301
    MessageBox MB_OK $(GTK_WINDOWS_INCOMPATIBLE) /SD IDOK
 
302
    IntCmp $R0 1 done done ; Upgrade isn't optional - abort if we don't have a suitable version
 
303
    Quit
 
304
  ${EndIf}
 
305
 
 
306
  done:
 
307
  Pop $R2
 
308
  Pop $R1
 
309
  
 
310
  Pop $R0
 
311
FunctionEnd
 
312
 
 
313
Function preGtkDirPage
 
314
  Push $R0
 
315
  Push $R1
 
316
  Call DoWeNeedGtk
 
317
  Pop $R0
 
318
  Pop $R1
 
319
 
 
320
  IntCmp $R0 2 +2 +2 no_gtk
 
321
  StrCmp $R0 "3" no_gtk no_gtk
 
322
 
 
323
  ; Don't show dir selector.. Upgrades are done to existing path..
 
324
  Pop $R1
 
325
  Pop $R0
 
326
  Abort
 
327
 
 
328
  no_gtk:
 
329
    StrCmp $R1 "NONE" 0 no_gtk_cont
 
330
      ; Got no install rights..
 
331
      Pop $R1
 
332
      Pop $R0
 
333
      Abort
 
334
    no_gtk_cont:
 
335
      ; Suggest path..
 
336
      StrCmp $R1 "HKCU" 0 hklm1
 
337
        ${GetParent} $SMPROGRAMS $R0
 
338
        ${GetParent} $R0 $R0
 
339
        StrCpy $R0 "$R0\GTK\2.0"
 
340
        Goto got_path
 
341
      hklm1:
 
342
        StrCpy $R0 "${GTK_DEFAULT_INSTALL_PATH}"
 
343
 
 
344
   got_path:
 
345
     StrCpy $name "GTK+ ${GTK_INSTALL_VERSION}"
 
346
     StrCpy $GTK_FOLDER  $R0
 
347
     Pop $R1
 
348
     Pop $R0
 
349
FunctionEnd
 
350
 
 
351
Function postGtkDirPage
 
352
  Push $R0
 
353
  Push $GTK_FOLDER
 
354
  Call VerifyDir
 
355
  Pop $R0
 
356
  StrCmp $R0 "0" 0 done
 
357
    MessageBox MB_OK $(GTK_BAD_INSTALL_PATH) /SD IDOK
 
358
    Pop $R0
 
359
    Abort
 
360
  done:
 
361
  Pop $R0
 
362
FunctionEnd
 
363
 
 
364
!macro CheckUserInstallRightsMacro UN
 
365
Function ${UN}CheckUserInstallRights
 
366
  Push $0
 
367
  Push $1
 
368
  ClearErrors
 
369
  UserInfo::GetName
 
370
  IfErrors Win9x
 
371
  Pop $0
 
372
  UserInfo::GetAccountType
 
373
  Pop $1
 
374
 
 
375
  StrCmp $1 "Admin" 0 +3
 
376
    StrCpy $1 "HKLM"
 
377
    Goto done
 
378
  StrCmp $1 "Power" 0 +3
 
379
    StrCpy $1 "HKLM"
 
380
    Goto done
 
381
  StrCmp $1 "User" 0 +3
 
382
    StrCpy $1 "HKCU"
 
383
    Goto done
 
384
  StrCmp $1 "Guest" 0 +3
 
385
    StrCpy $1 "NONE"
 
386
    Goto done
 
387
  ; Unknown error
 
388
  StrCpy $1 "NONE"
 
389
  Goto done
 
390
 
 
391
  Win9x:
 
392
    StrCpy $1 "HKLM"
 
393
 
 
394
  done:
 
395
    Exch $1
 
396
    Exch
 
397
    Pop $0
 
398
FunctionEnd
 
399
!macroend
 
400
!insertmacro CheckUserInstallRightsMacro ""
 
401
!insertmacro CheckUserInstallRightsMacro "un."
 
402
 
 
403
 
 
404
;
 
405
; Usage:
 
406
;   Push $0 ; Path string
 
407
;   Call VerifyDir
 
408
;   Pop $0 ; 0 - Bad path  1 - Good path
 
409
;
 
410
Function VerifyDir
 
411
  Exch $0
 
412
  Push $1
 
413
  Push $2
 
414
  Loop:
 
415
    IfFileExists $0 dir_exists
 
416
    StrCpy $1 $0 ; save last
 
417
    ${GetParent} $0 $0
 
418
    StrLen $2 $0
 
419
    ; IfFileExists "C:" on xp returns true and on win2k returns false
 
420
    ; So we're done in such a case..
 
421
    IntCmp $2 2 loop_done
 
422
    ; GetParent of "C:" returns ""
 
423
    IntCmp $2 0 loop_done
 
424
    Goto Loop
 
425
 
 
426
  loop_done:
 
427
    StrCpy $1 "$0\GaImFooB"
 
428
    ; Check if we can create dir on this drive..
 
429
    ClearErrors
 
430
    CreateDirectory $1
 
431
    IfErrors DirBad DirGood
 
432
 
 
433
  dir_exists:
 
434
    ClearErrors
 
435
    FileOpen $1 "$0\pidginfoo.bar" w
 
436
    IfErrors PathBad PathGood
 
437
 
 
438
    DirGood:
 
439
      RMDir $1
 
440
      Goto PathGood1
 
441
 
 
442
    DirBad:
 
443
      RMDir $1
 
444
      Goto PathBad1
 
445
 
 
446
    PathBad:
 
447
      FileClose $1
 
448
      Delete "$0\pidginfoo.bar"
 
449
      PathBad1:
 
450
      StrCpy $0 "0"
 
451
      Push $0
 
452
      Goto done
 
453
 
 
454
    PathGood:
 
455
      FileClose $1
 
456
      Delete "$0\pidginfoo.bar"
 
457
      PathGood1:
 
458
      StrCpy $0 "1"
 
459
      Push $0
 
460
 
 
461
  done:
 
462
  Exch 3 ; The top of the stack contains the output variable
 
463
  Pop $0
 
464
  Pop $2
 
465
  Pop $1
 
466
FunctionEnd
 
467
 
 
468
Function .onVerifyInstDir
 
469
  Push $0
 
470
  Push $INSTDIR
 
471
  Call VerifyDir
 
472
  Pop $0
 
473
  StrCmp $0 "0" 0 dir_good
 
474
  Pop $0
 
475
  Abort
 
476
 
 
477
  dir_good:
 
478
  Pop $0
 
479
FunctionEnd
 
480