gcompris-installer.nsi.in 22.5 KB
Newer Older
1
; Installer script for win32 GCompris
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
; Copyed from GAIM By Herman Bloggs <hermanator12002@yahoo.com>
; Bruno Coudoin for GCompris
;
; NOTE: this .NSI script is intended for NSIS 2.0 (finale release).
;

;--------------------------------
;Global Variables
Var name
Var LANG_IS_SET
Var ISSILENT
Var STARTUP_RUN_KEY

;--------------------------------
;Configuration

;The name var is set in .onInit
Name $name

21
!define GCOMPRIS_VERSION			"@VERSION@"
22 23 24

OutFile "gcompris-${GCOMPRIS_VERSION}.exe"

25 26
UninstallIcon ".\gcompris-uninstal.ico"

27
SetCompressor lzma
28 29
ShowInstDetails hide
ShowUninstDetails hide
30 31 32 33 34 35 36 37 38 39 40 41 42 43
SetDateSave on

; $name and $INSTDIR are set in .onInit function..

!include "MUI.nsh"
!include "Sections.nsh"

;--------------------------------
;Defines

!define GCOMPRIS_NSIS_INCLUDE_PATH		".\nsis"
!define GCOMPRIS_INSTALLER_DEPS			"..\win32-dev\gcompris-inst-deps"

!define GCOMPRIS_REG_KEY			"SOFTWARE\gcompris"
44
!define GCOMPRIS_UNINSTALL_KEY			"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GCompris"
45 46 47 48 49 50 51 52
!define HKLM_APP_PATHS_KEY			"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\gcompris.exe"
!define GCOMPRIS_STARTUP_RUN_KEY		"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
!define GCOMPRIS_UNINST_EXE			"gcompris-uninst.exe"
!define GCOMPRIS_REG_LANG			"Installer Language"

;--------------------------------
;Modern UI Configuration

53
  !define MUI_ICON				".\gcompris-install.ico"
54
  !define MUI_UNICON				".\gcompris-uninstal.ico"
55 56 57 58 59 60 61 62 63
  !define MUI_WELCOMEFINISHPAGE_BITMAP 		".\nsis\gcompris-intro.bmp"
  !define MUI_HEADERIMAGE
  !define MUI_HEADERIMAGE_BITMAP		".\nsis\gcompris-header.bmp"

  !define MUI_ABORTWARNING

  ;Finish Page config
  !define MUI_FINISHPAGE_RUN			"$INSTDIR\gcompris.exe"
  !define MUI_FINISHPAGE_RUN_NOTCHECKED
64
  !define MUI_FINISHPAGE_LINK			$(GcomprisFinishVisitWebSite)
65 66 67 68
  !define MUI_FINISHPAGE_LINK_LOCATION          "http://gcompris.net/"

;--------------------------------
;Pages
69

70 71
  !insertmacro MUI_PAGE_WELCOME

72
  ; GCompris install dir page
73 74 75 76 77 78 79 80 81 82 83 84
  !insertmacro MUI_PAGE_DIRECTORY

  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH

  !insertmacro MUI_UNPAGE_WELCOME
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  !insertmacro MUI_UNPAGE_FINISH

;--------------------------------
;Languages
85

86
  @INSERT_TRANSLATIONS@
87 88 89 90 91 92

;--------------------------------
;Reserve Files
  ; Only need this if using bzip2 compression

  !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
93
  !insertmacro MUI_RESERVEFILE_LANGDLL
94 95 96 97 98 99 100 101
  ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Start Install Sections ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;--------------------------------
102
;Uninstall any old version of GCompris
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

Section -SecUninstallOldGcompris
  ; Check install rights..
  Call CheckUserInstallRights
  Pop $R0

  ;If gcompris is currently set to run on startup,
  ;  save the section of the Registry where the setting is before uninstalling,
  ;  so we can put it back after installing the new version
  ClearErrors
  ReadRegStr $STARTUP_RUN_KEY HKCU "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris"
  IfErrors +3
  StrCpy $STARTUP_RUN_KEY "HKCU"
  Goto +4
  ReadRegStr $STARTUP_RUN_KEY HKLM "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris"
  IfErrors +2
  StrCpy $STARTUP_RUN_KEY "HKLM"

  StrCmp $R0 "HKLM" gcompris_hklm
  StrCmp $R0 "HKCU" gcompris_hkcu done

  gcompris_hkcu:
      ReadRegStr $R1 HKCU ${GCOMPRIS_REG_KEY} ""
      ReadRegStr $R2 HKCU ${GCOMPRIS_REG_KEY} "Version"
      ReadRegStr $R3 HKCU "${GCOMPRIS_UNINSTALL_KEY}" "UninstallString"
      Goto try_uninstall

  gcompris_hklm:
      ReadRegStr $R1 HKLM ${GCOMPRIS_REG_KEY} ""
      ReadRegStr $R2 HKLM ${GCOMPRIS_REG_KEY} "Version"
      ReadRegStr $R3 HKLM "${GCOMPRIS_UNINSTALL_KEY}" "UninstallString"

  ; If previous version exists .. remove
  try_uninstall:
    StrCmp $R1 "" done
138
      ; Version key started with 0.60a3. Prior versions can't be
139 140 141 142
      ; automaticlly uninstalled.
      StrCmp $R2 "" uninstall_problem
        ; Check if we have uninstall string..
        IfFileExists $R3 0 uninstall_problem
143
          ; Have uninstall string.. go ahead and uninstall.
144

145
	  ; In this case just wipe out previous GCompris install dir..
146
	  ; We get here because versions 0.60a1 and 0.60a2 don't have versions set in the registry
147
	  ; and versions 0.60 and lower did not correctly set the uninstall reg string
148
	  ; (the string was set in quotes)
149
          MessageBox MB_YESNO $(GcomprisPromptWipeout) IDYES do_wipeout IDNO cancel_install
150 151
          cancel_install:
            Quit
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
          SetOverwrite on
          ; Need to copy uninstaller outside of the install dir
          ClearErrors
          CopyFiles /SILENT $R3 "$TEMP\${GCOMPRIS_UNINST_EXE}"
          SetOverwrite off
          IfErrors uninstall_problem
            ; Ready to uninstall..
            ClearErrors
	    ExecWait '"$TEMP\${GCOMPRIS_UNINST_EXE}" /S _?=$R1'
	    IfErrors exec_error
              Delete "$TEMP\${GCOMPRIS_UNINST_EXE}"
	      Goto done

	    exec_error:
              Delete "$TEMP\${GCOMPRIS_UNINST_EXE}"
              Goto uninstall_problem

        uninstall_problem:
171
	  ; In this case just wipe out previous GCompris install dir..
172 173 174 175 176 177
	  ; We get here because versions 0.60a1 and 0.60a2 don't have versions set in the registry
	  ; and versions 0.60 and lower did not correctly set the uninstall reg string
	  ; (the string was set in quotes)
          IfSilent do_wipeout
          MessageBox MB_YESNO "Uninstall previous version?" IDYES do_wipeout IDNO done

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
          do_wipeout:
            StrCmp $R0 "HKLM" gcompris_del_lm_reg gcompris_del_cu_reg
            gcompris_del_cu_reg:
              DeleteRegKey HKCU ${GCOMPRIS_REG_KEY}
              Goto uninstall_prob_cont
            gcompris_del_lm_reg:
              DeleteRegKey HKLM ${GCOMPRIS_REG_KEY}

            uninstall_prob_cont:
	      RMDir /r "$R1"

  done:
SectionEnd


;--------------------------------
194
;GCompris Install Section
195

196
Section "GCompris" SecGcompris
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  SectionIn 1 RO

  ; Check install rights..
  Call CheckUserInstallRights
  Pop $R0

  ; Get GTK+ lib dir if we have it..

  StrCmp $R0 "NONE" gcompris_none
  StrCmp $R0 "HKLM" gcompris_hklm gcompris_hkcu

  gcompris_hklm:
    WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "" "$INSTDIR\gcompris.exe"
    WriteRegStr HKLM "${HKLM_APP_PATHS_KEY}" "Path" "$R1\bin"
    WriteRegStr HKLM ${GCOMPRIS_REG_KEY} "" "$INSTDIR"
    WriteRegStr HKLM ${GCOMPRIS_REG_KEY} "Version" "${GCOMPRIS_VERSION}"
213
    WriteRegStr HKLM "${GCOMPRIS_UNINSTALL_KEY}" "DisplayName" "GCompris Uninstall"
214 215 216 217 218 219 220 221
    WriteRegStr HKLM "${GCOMPRIS_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${GCOMPRIS_UNINST_EXE}"
    ; Sets scope of the desktop and Start Menu entries for all users.
    SetShellVarContext "all"
    Goto gcompris_install_files

  gcompris_hkcu:
    WriteRegStr HKCU ${GCOMPRIS_REG_KEY} "" "$INSTDIR"
    WriteRegStr HKCU ${GCOMPRIS_REG_KEY} "Version" "${GCOMPRIS_VERSION}"
222
    WriteRegStr HKCU "${GCOMPRIS_UNINSTALL_KEY}" "DisplayName" "GCompris Uninstall"
223 224 225 226 227 228 229
    WriteRegStr HKCU "${GCOMPRIS_UNINSTALL_KEY}" "UninstallString" "$INSTDIR\${GCOMPRIS_UNINST_EXE}"
    Goto gcompris_install_files

  gcompris_none:

  gcompris_install_files:
    SetOutPath "$INSTDIR"
230
    ; GCompris files
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    SetOverwrite on
    File /r .\win32-install-dir\*.*

    ; If this is under NT4, delete the SILC support stuff
    ; there is a bug that will prevent any account from connecting
    ; See https://lists.silcnet.org/pipermail/silc-devel/2005-January/001588.html
    Call GetWindowsVersion
    Pop $R2
    StrCmp $R2 "NT 4.0" 0 nt4_done
    Delete "$INSTDIR\plugins\libsilc.dll"
    Delete "$INSTDIR\silcclient.dll"
    Delete "$INSTDIR\silc.dll"

    nt4_done:

246 247 248 249 250
    CreateDirectory "$SMPROGRAMS\GCompris"
    CreateShortCut "$SMPROGRAMS\GCompris\GCompris.lnk" "$INSTDIR\gcompris.exe"
    CreateShortCut "$DESKTOP\GCompris.lnk" "$INSTDIR\gcompris.exe"
    CreateShortCut "$SMPROGRAMS\GCompris\GCompris Admin.lnk" "$INSTDIR\gcompris.exe" `-a` "$INSTDIR\gcompris.exe" 1
    CreateShortCut "$DESKTOP\GCompris Admin.lnk" "$INSTDIR\gcompris.exe" `-a` "$INSTDIR\gcompris.exe" 1
251 252 253 254
    SetOutPath "$INSTDIR"

    ; If we don't have install rights.. we're done
    StrCmp $R0 "NONE" done
255
    CreateShortCut "$SMPROGRAMS\GCompris\Uninstall.lnk" "$INSTDIR\${GCOMPRIS_UNINST_EXE}"
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    SetOverwrite off

    ; Write out installer language
    WriteRegStr HKCU "${GCOMPRIS_REG_KEY}" "${GCOMPRIS_REG_LANG}" "$LANGUAGE"

    ; write out uninstaller
    SetOverwrite on
    WriteUninstaller "$INSTDIR\${GCOMPRIS_UNINST_EXE}"
    SetOverwrite off

    ; If we previously had gcompris setup to run on startup, make it do so again
    StrCmp $STARTUP_RUN_KEY "HKCU" +1 +2
    WriteRegStr HKCU "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris" "$INSTDIR\gcompris.exe"
    StrCmp $STARTUP_RUN_KEY "HKLM" +1 +2
    WriteRegStr HKLM "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris" "$INSTDIR\gcompris.exe"

  done:
273
SectionEnd ; end of default GCompris section
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

;--------------------------------
;Uninstaller Section


Section Uninstall
  Call un.CheckUserInstallRights
  Pop $R0
  StrCmp $R0 "NONE" no_rights
  StrCmp $R0 "HKCU" try_hkcu try_hklm

  try_hkcu:
    ReadRegStr $R0 HKCU ${GCOMPRIS_REG_KEY} ""
    StrCmp $R0 $INSTDIR 0 cant_uninstall
      ; HKCU install path matches our INSTDIR.. so uninstall
      DeleteRegKey HKCU ${GCOMPRIS_REG_KEY}
      DeleteRegKey HKCU "${GCOMPRIS_UNINSTALL_KEY}"
      Goto cont_uninstall

  try_hklm:
    ReadRegStr $R0 HKLM ${GCOMPRIS_REG_KEY} ""
    StrCmp $R0 $INSTDIR 0 try_hkcu
      ; HKLM install path matches our INSTDIR.. so uninstall
      DeleteRegKey HKLM ${GCOMPRIS_REG_KEY}
      DeleteRegKey HKLM "${GCOMPRIS_UNINSTALL_KEY}"
      DeleteRegKey HKLM "${HKLM_APP_PATHS_KEY}"
      ; Sets start menu and desktop scope to all users..
      SetShellVarContext "all"

  cont_uninstall:
    ; The WinPrefs plugin may have left this behind..
    DeleteRegValue HKCU "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris"
    DeleteRegValue HKLM "${GCOMPRIS_STARTUP_RUN_KEY}" "Gcompris"
    ; Remove Language preference info
    DeleteRegKey HKCU ${GCOMPRIS_REG_KEY} ;${MUI_LANGDLL_REGISTRY_ROOT} ${MUI_LANGDLL_REGISTRY_KEY}

310 311 312 313
    RMDir /r "$INSTDIR\etc"
    RMDir /r "$INSTDIR\GTK"
    RMDir /r "$INSTDIR\lib"
    RMDir /r "$INSTDIR\share"
314 315
    Delete "$INSTDIR\gcompris.exe"
    Delete "$INSTDIR\${GCOMPRIS_UNINST_EXE}"
316 317 318 319 320 321 322
    Delete "$INSTDIR\COPYING"
    Delete "$INSTDIR\Changelog"
    Delete "$INSTDIR\README"
    Delete "$INSTDIR\SDL.dll"
    Delete "$INSTDIR\SDL_mixer.dll"
    Delete "$INSTDIR\_cairo.pyd"
    Delete "$INSTDIR\_gtk.pyd"
323
    Delete "$INSTDIR\_hashlib.pyd"
324 325
    Delete "$INSTDIR\_socket.pyd"
    Delete "$INSTDIR\_ssl.pyd"
326
    Delete "$INSTDIR\_sqlite.pyd"
327 328 329 330 331
    Delete "$INSTDIR\_tkinter.pyd"
    Delete "$INSTDIR\atk.pyd"
    Delete "$INSTDIR\bz2.pyd"
    Delete "$INSTDIR\freetype6.dll"
    Delete "$INSTDIR\gnucap.exe"
332
    Delete "$INSTDIR\bin\gnuchess.exe"
333
    RMDir  "$INSTDIR\bin"
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    Delete "$INSTDIR\gobject.pyd"
    Delete "$INSTDIR\gspawn-win32-helper.exe"
    Delete "$INSTDIR\iconv.dll"
    Delete "$INSTDIR\intl.dll"
    Delete "$INSTDIR\jpeg62.dll"
    Delete "$INSTDIR\libart_lgpl_2-2.dll"
    Delete "$INSTDIR\libatk-1.0-0.dll"
    Delete "$INSTDIR\libcairo-2.dll"
    Delete "$INSTDIR\libfontconfig-1.dll"
    Delete "$INSTDIR\libgdk-win32-2.0-0.dll"
    Delete "$INSTDIR\libgdk_pixbuf-2.0-0.dll"
    Delete "$INSTDIR\libglib-2.0-0.dll"
    Delete "$INSTDIR\libgmodule-2.0-0.dll"
    Delete "$INSTDIR\libgnomecanvas-2-0.dll"
    Delete "$INSTDIR\libgobject-2.0-0.dll"
    Delete "$INSTDIR\libgthread-2.0-0.dll"
    Delete "$INSTDIR\libgtk-win32-2.0-0.dll"
    Delete "$INSTDIR\libiconv-2.dll"
    Delete "$INSTDIR\libintl-2.dll"
    Delete "$INSTDIR\libpango-1.0-0.dll"
    Delete "$INSTDIR\libpangocairo-1.0-0.dll"
    Delete "$INSTDIR\libpangoft2-1.0-0.dll"
    Delete "$INSTDIR\libpangowin32-1.0-0.dll"
    Delete "$INSTDIR\libreadline.dll"
    Delete "$INSTDIR\libxml2.dll"
    Delete "$INSTDIR\pango.pyd"
    Delete "$INSTDIR\pangocairo.pyd"
    Delete "$INSTDIR\pthreadGC.dll"
362
    Delete "$INSTDIR\python24.dll"
363 364 365
    Delete "$INSTDIR\python24.zip"
    Delete "$INSTDIR\select.pyd"
    Delete "$INSTDIR\setup.py"
366
    Delete "$INSTDIR\sqlite3.dll"
367 368 369 370 371
    Delete "$INSTDIR\unicodedata.pyd"
    Delete "$INSTDIR\xmlparse.dll"
    Delete "$INSTDIR\xmltok.dll"
    Delete "$INSTDIR\zlib.pyd"
    Delete "$INSTDIR\zlib1.dll"
372
    Delete "$INSTDIR\README.mingw"
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    Delete "$INSTDIR\config.h.mingw"
    Delete "$INSTDIR\libexpat.dll"
    Delete "$INSTDIR\libgio-2.0-0.dll"
    Delete "$INSTDIR\libogg-0.dll"
    Delete "$INSTDIR\libpng12-0.dll"
    Delete "$INSTDIR\libvorbis-0.dll"
    Delete "$INSTDIR\libvorbisfile-3.dll"
    Delete "$INSTDIR\pthreadGC2.dll"
    Delete "$INSTDIR\README.translators"
    Delete "$INSTDIR\_ctypes.pyd"
    Delete "$INSTDIR\_sqlite3.pyd"
    Delete "$INSTDIR\cairo._cairo.pyd"
    Delete "$INSTDIR\gobject._gobject.pyd"
    Delete "$INSTDIR\gtk._gtk.pyd"
    Delete "$INSTDIR\libcroco-0.6-3.dll"
    Delete "$INSTDIR\libexpat-1.dll"
    Delete "$INSTDIR\libgio-2.0-0.dll"
    Delete "$INSTDIR\libgsf-1-114.dll"
    Delete "$INSTDIR\libjpeg-7.dll"
    Delete "$INSTDIR\libogg-0.dll"
    Delete "$INSTDIR\libpng12-0.dll"
    Delete "$INSTDIR\librsvg-2-2.dll"
    Delete "$INSTDIR\libvorbis-0.dll"
    Delete "$INSTDIR\libvorbisfile-3.dll"
    Delete "$INSTDIR\libxml2-2.dll"
    Delete "$INSTDIR\pthreadGC2.dll"
    Delete "$INSTDIR\python26.dll"
    Delete "$INSTDIR\python26.zip"
    Delete "$INSTDIR\Microsoft.VC90.CRT\Microsoft.VC90.CRT.manifest"
    Delete "$INSTDIR\Microsoft.VC90.CRT\msvcm90.dll"
    Delete "$INSTDIR\Microsoft.VC90.CRT\msvcp90.dll"
    Delete "$INSTDIR\Microsoft.VC90.CRT\msvcr90.dll"
405
    RMDir  "$INSTDIR\Microsoft.VC90.CRT"
406 407 408 409 410 411 412
    Delete "$INSTDIR\manifest\gtk+-bundle_2.18.5-20091215_win32.mft"
    Delete "$INSTDIR\manifest\libcroco_0.6.2-1_win32.mft"
    Delete "$INSTDIR\manifest\libgsf_1.14.15-1_win32.mft"
    Delete "$INSTDIR\manifest\librsvg_2.26.0-1_win32.mft"
    Delete "$INSTDIR\manifest\librsvg-dev_2.26.0-1_win32.mft"
    Delete "$INSTDIR\manifest\svg-gdk-pixbuf-loader_2.26.0-1_win32.mft"
    Delete "$INSTDIR\manifest\svg-gtk-engine_2.26.0-1_win32.mft"
413
    RMDir  "$INSTDIR\manifest"
414 415

    ;Try to remove GCompris install dir .. if empty
416
    RMDir "$INSTDIR"
417 418

    ; Shortcuts..
419 420 421
    RMDir /r "$SMPROGRAMS\GCompris"
    Delete "$DESKTOP\GCompris.lnk"
    Delete "$DESKTOP\GCompris Admin.lnk"
422 423 424 425 426

    Goto done

  cant_uninstall:
    IfSilent skip_mb
427
    MessageBox MB_OK $(unGcomprisUninstallError1) IDOK
428 429 430 431 432
    skip_mb:
    Quit

  no_rights:
    IfSilent skip_mb1
433
    MessageBox MB_OK $(unGcomprisUninstallError2) IDOK
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    skip_mb1:
    Quit

  done:
SectionEnd ; end of uninstall section


;--------------------------------
;Functions

Function CheckUserInstallRights
	ClearErrors
	UserInfo::GetName
	IfErrors Win9x
	Pop $0
	UserInfo::GetAccountType
	Pop $1

	StrCmp $1 "Admin" 0 +3
                StrCpy $1 "HKLM"
		Goto done
	StrCmp $1 "Power" 0 +3
                StrCpy $1 "HKLM"
		Goto done
	StrCmp $1 "User" 0 +3
		StrCpy $1 "HKCU"
		Goto done
	StrCmp $1 "Guest" 0 +3
		StrCpy $1 "NONE"
		Goto done
	; Unknown error
	StrCpy $1 "NONE"
        Goto done

	Win9x:
		StrCpy $1 "HKLM"

	done:
        Push $1
FunctionEnd

Function un.CheckUserInstallRights
	ClearErrors
	UserInfo::GetName
	IfErrors Win9x
	Pop $0
	UserInfo::GetAccountType
	Pop $1

	StrCmp $1 "Admin" 0 +3
                StrCpy $1 "HKLM"
		Goto done
	StrCmp $1 "Power" 0 +3
                StrCpy $1 "HKLM"
		Goto done
	StrCmp $1 "User" 0 +3
		StrCpy $1 "HKCU"
		Goto done
	StrCmp $1 "Guest" 0 +3
		StrCpy $1 "NONE"
		Goto done
	; Unknown error
	StrCpy $1 "NONE"
        Goto done

	Win9x:
		StrCpy $1 "HKLM"

	done:
        Push $1
FunctionEnd

;
; Usage:
;   Push $0 ; Path string
;   Call VerifyDir
;   Pop $0 ; 0 - Bad path  1 - Good path
;
Function VerifyDir
  Pop $0
  Loop:
    IfFileExists $0 dir_exists
    StrCpy $1 $0 ; save last
    Push $0
    Call GetParent
    Pop $0
    StrLen $2 $0
    ; IfFileExists "C:" on xp returns true and on win2k returns false
    ; So we're done in such a case..
    IntCmp $2 2 loop_done
    ; GetParent of "C:" returns ""
    IntCmp $2 0 loop_done
    Goto Loop

  loop_done:
    StrCpy $1 "$0\GcomprisFooB"
    ; Check if we can create dir on this drive..
    ClearErrors
    CreateDirectory $1
    IfErrors DirBad DirGood

  dir_exists:
    ClearErrors
    FileOpen $1 "$0\gcomprisfoo.bar" w
    IfErrors PathBad PathGood

    DirGood:
      RMDir $1
      Goto PathGood1

    DirBad:
      RMDir $1
      Goto PathBad1

    PathBad:
      FileClose $1
      Delete "$0\gcomprisfoo.bar"
      PathBad1:
      StrCpy $0 "0"
      Push $0
      Return

    PathGood:
      FileClose $1
      Delete "$0\gcomprisfoo.bar"
      PathGood1:
      StrCpy $0 "1"
      Push $0
FunctionEnd

Function .onVerifyInstDir
  Push $INSTDIR
  Call VerifyDir
  Pop $0
  StrCmp $0 "0" 0 dir_good
    Abort
  dir_good:
FunctionEnd

; GetParent
; input, top of stack  (e.g. C:\Program Files\Poop)
; output, top of stack (replaces, with e.g. C:\Program Files)
; modifies no other variables.
;
; Usage:
;   Push "C:\Program Files\Directory\Whatever"
;   Call GetParent
;   Pop $R0
;   ; at this point $R0 will equal "C:\Program Files\Directory"
Function GetParent
   Exch $0 ; old $0 is on top of stack
   Push $1
   Push $2
   StrCpy $1 -1
   loop:
     StrCpy $2 $0 1 $1
     StrCmp $2 "" exit
     StrCmp $2 "\" exit
     IntOp $1 $1 - 1
   Goto loop
   exit:
     StrCpy $0 $0 $1
     Pop $2
     Pop $1
     Exch $0 ; put $0 on top of stack, restore $0 to original value
FunctionEnd


Function RunCheck
  System::Call 'kernel32::OpenMutex(i 2031617, b 0, t "gcompris_is_running") i .R0'
  IntCmp $R0 0 done
605
  MessageBox MB_OK|MB_ICONEXCLAMATION $(GcomprisIsRunning) IDOK
606 607 608 609 610 611 612
    Abort
  done:
FunctionEnd

Function un.RunCheck
  System::Call 'kernel32::OpenMutex(i 2031617, b 0, t "gcompris_is_running") i .R0'
  IntCmp $R0 0 done
613
  MessageBox MB_OK|MB_ICONEXCLAMATION $(GcomprisIsRunning) IDOK
614 615 616 617 618 619 620 621
    Abort
  done:
FunctionEnd

Function .onInit
  System::Call 'kernel32::CreateMutexA(i 0, i 0, t "gcompris_installer_running") i .r1 ?e'
  Pop $R0
  StrCmp $R0 0 +3
622
    MessageBox MB_OK|MB_ICONEXCLAMATION $(InstallerIsRunning)
623 624
    Abort
  Call RunCheck
625
  StrCpy $name "GCompris ${GCOMPRIS_VERSION}"
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
  StrCpy $ISSILENT "/NOUI"

  ; GTK installer has two silent states.. one with Message boxes, one without
  ; If gcompris installer was run silently, we want to supress gtk installer msg boxes.
  IfSilent 0 set_gtk_normal
      StrCpy $ISSILENT "/S"
  set_gtk_normal:

  Call ParseParameters

  ; Select Language
  IntCmp $LANG_IS_SET 1 skip_lang
    ; Display Language selection dialog
    !insertmacro MUI_LANGDLL_DISPLAY
    skip_lang:

  ; If install path was set on the command, use it.
  StrCmp $INSTDIR "" 0 instdir_done

  ;  If gcompris is currently intalled, we should default to where it is currently installed
  ClearErrors
  ReadRegStr $INSTDIR HKCU "${GCOMPRIS_REG_KEY}" ""
  IfErrors +2
  StrCmp $INSTDIR "" 0 instdir_done
  ReadRegStr $INSTDIR HKLM "${GCOMPRIS_REG_KEY}" ""
  IfErrors +2
  StrCmp $INSTDIR "" 0 instdir_done

  Call CheckUserInstallRights
  Pop $0

  StrCmp $0 "HKLM" 0 user_dir
658
    StrCpy $INSTDIR "$PROGRAMFILES\GCompris"
659 660 661 662 663 664 665
    Goto instdir_done
  user_dir:
    StrCpy $2 "$SMPROGRAMS"
    Push $2
    Call GetParent
    Call GetParent
    Pop $2
666
    StrCpy $INSTDIR "$2\GCompris"
667 668 669 670 671 672 673

  instdir_done:

FunctionEnd

Function un.onInit
  Call un.RunCheck
674
  StrCpy $name "GCompris ${GCOMPRIS_VERSION}"
675 676 677

  ; Get stored language prefrence
  ReadRegStr $LANGUAGE HKCU ${GCOMPRIS_REG_KEY} "${GCOMPRIS_REG_LANG}"
678

679 680 681 682 683 684 685
FunctionEnd


; GetParameters
; input, none
; output, top of stack (replaces, with e.g. whatever)
; modifies no other variables.
686

687
Function GetParameters
688

689 690 691 692
   Push $R0
   Push $R1
   Push $R2
   Push $R3
693

694 695
   StrCpy $R2 1
   StrLen $R3 $CMDLINE
696

697 698 699 700 701 702
   ;Check for quote or space
   StrCpy $R0 $CMDLINE $R2
   StrCmp $R0 '"' 0 +3
     StrCpy $R1 '"'
     Goto loop
   StrCpy $R1 " "
703

704 705 706 707 708 709
   loop:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 $R1 get
     StrCmp $R2 $R3 get
     Goto loop
710

711 712 713 714 715
   get:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 " " get
     StrCpy $R0 $CMDLINE "" $R2
716

717 718 719 720
   Pop $R3
   Pop $R2
   Pop $R1
   Exch $R0
721

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
FunctionEnd

 ; StrStr
 ; input, top of stack = string to search for
 ;        top of stack-1 = string to search in
 ; output, top of stack (replaces with the portion of the string remaining)
 ; modifies no other variables.
 ;
 ; Usage:
 ;   Push "this is a long ass string"
 ;   Push "ass"
 ;   Call StrStr
 ;   Pop $R0
 ;  ($R0 at this point is "ass string")

Function StrStr
   Exch $R1 ; st=haystack,old$R1, $R1=needle
   Exch    ; st=old$R1,haystack
   Exch $R2 ; st=old$R1,old$R2, $R2=haystack
   Push $R3
   Push $R4
   Push $R5
   StrLen $R3 $R1
   StrCpy $R4 0
   ; $R1=needle
   ; $R2=haystack
   ; $R3=len(needle)
   ; $R4=cnt
   ; $R5=tmp
   loop:
     StrCpy $R5 $R2 $R3 $R4
     StrCmp $R5 $R1 done
     StrCmp $R5 "" done
     IntOp $R4 $R4 + 1
     Goto loop
   done:
   StrCpy $R1 $R2 "" $R4
   Pop $R5
   Pop $R4
   Pop $R3
   Pop $R2
   Exch $R1
FunctionEnd

;
; Parse the Command line
;
; Unattended install command line parameters
; /L=Language e.g.: /L=1033
;
Function ParseParameters
  IntOp $LANG_IS_SET 0 + 0
  Call GetParameters
  Pop $R0
  Push $R0
  Push "L="
  Call StrStr
  Pop $R1
  StrCmp $R1 "" next
  StrCpy $R1 $R1 4 2 ; Strip first 2 chars of string
  StrCpy $LANGUAGE $R1
  IntOp $LANG_IS_SET 0 + 1
  next:
FunctionEnd

; GetWindowsVersion
;
; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
; Updated by Joost Verburg
;
; Returns on top of stack
;
; Windows Version (95, 98, ME, NT x.x, 2000, XP, 2003)
; or
; '' (Unknown Windows Version)
;
; Usage:
;   Call GetWindowsVersion
;   Pop $R0
;
; at this point $R0 is "NT 4.0" or whatnot
Function GetWindowsVersion

  Push $R0
  Push $R1

  ReadRegStr $R0 HKLM \
  "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion

  IfErrors 0 lbl_winnt

  ; we are not NT
  ReadRegStr $R0 HKLM \
  "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber

  StrCpy $R1 $R0 1
  StrCmp $R1 '4' 0 lbl_error

  StrCpy $R1 $R0 3

  StrCmp $R1 '4.0' lbl_win32_95
  StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98

  lbl_win32_95:
    StrCpy $R0 '95'
  Goto lbl_done

  lbl_win32_98:
    StrCpy $R0 '98'
  Goto lbl_done

  lbl_win32_ME:
    StrCpy $R0 'ME'
  Goto lbl_done

  lbl_winnt:
    StrCpy $R1 $R0 1

    StrCmp $R1 '3' lbl_winnt_x
    StrCmp $R1 '4' lbl_winnt_x

    StrCpy $R1 $R0 3

    StrCmp $R1 '5.0' lbl_winnt_2000
    StrCmp $R1 '5.1' lbl_winnt_XP
    StrCmp $R1 '5.2' lbl_winnt_2003 lbl_error

  lbl_winnt_x:
    StrCpy $R0 "NT $R0" 6
  Goto lbl_done

  lbl_winnt_2000:
    Strcpy $R0 '2000'
  Goto lbl_done

  lbl_winnt_XP:
    Strcpy $R0 'XP'
  Goto lbl_done

  lbl_winnt_2003:
    Strcpy $R0 '2003'
  Goto lbl_done

  lbl_error:
    Strcpy $R0 ''
  lbl_done:
868

869 870 871 872
  Pop $R1
  Exch $R0
FunctionEnd