home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Examples / waplugin.nsi < prev   
Text File  |  2003-12-24  |  5KB  |  201 lines

  1. ; waplugin.nsi
  2. ;
  3. ; This script will generate an installer that installs a Winamp 2 plug-in.
  4. ;
  5. ; This installer will automatically alert the user that installation was
  6. ; successful, and ask them whether or not they would like to make the 
  7. ; plug-in the default and run Winamp.
  8.  
  9. ;--------------------------------
  10.  
  11. ; Uncomment the next line to enable auto Winamp download
  12. ; !define WINAMP_AUTOINSTALL
  13.  
  14. ; The name of the installer
  15. Name "TinyVis Plug-in"
  16.  
  17. ; The file to write
  18. OutFile "waplugin.exe"
  19.  
  20. ; The default installation directory
  21. InstallDir $PROGRAMFILES\Winamp
  22.  
  23. ; detect winamp path from uninstall string if available
  24. InstallDirRegKey HKLM \
  25.                  "Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \
  26.                  "UninstallString"
  27.  
  28. ; The text to prompt the user to enter a directory
  29. DirText "Please select your Winamp path below (you will be able to proceed when Winamp is detected):"
  30. # currently doesn't work - DirShow hide
  31.  
  32. ; automatically close the installer when done.
  33. AutoCloseWindow true
  34.  
  35. ; hide the "show details" box
  36. ShowInstDetails nevershow
  37.  
  38. ;--------------------------------
  39.  
  40. ;Pages
  41.  
  42. Page directory
  43. Page instfiles
  44.  
  45. ;--------------------------------
  46.  
  47. ; The stuff to install
  48.  
  49. Section ""
  50.  
  51. !ifdef WINAMP_AUTOINSTALL
  52.   Call MakeSureIGotWinamp
  53. !endif
  54.  
  55.   Call QueryWinampVisPath
  56.   SetOutPath $1
  57.  
  58.   ; File to extract
  59.   File "C:\program files\winamp\plugins\vis_nsfs.dll"
  60.  
  61.   ; prompt user, and if they select no, go to NoWinamp
  62.   MessageBox MB_YESNO|MB_ICONQUESTION \
  63.              "The plug-in was installed. Would you like to run Winamp now with TinyVis as the default plug-in?" \
  64.              IDNO NoWinamp
  65.     WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_name" "vis_nsfs.dll"
  66.     WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_num" "0"
  67.     Exec '"$INSTDIR\Winamp.exe"'
  68.   NoWinamp:
  69.   
  70. SectionEnd
  71.  
  72. ;--------------------------------
  73.  
  74. Function .onVerifyInstDir
  75.  
  76. !ifndef WINAMP_AUTOINSTALL
  77.  
  78.   ;Check for Winamp installation
  79.  
  80.   IfFileExists $INSTDIR\Winamp.exe Good
  81.     Abort
  82.   Good:
  83.  
  84. !endif ; WINAMP_AUTOINSTALL
  85.  
  86. FunctionEnd
  87.  
  88. Function QueryWinampVisPath ; sets $1 with vis path
  89.  
  90.   StrCpy $1 $INSTDIR\Plugins
  91.   ; use DSPDir instead of VISDir to get DSP plugins directory
  92.   ReadINIStr $9 $INSTDIR\winamp.ini Winamp VisDir 
  93.   StrCmp $9 "" End
  94.   IfFileExists $9 0 End
  95.     StrCpy $1 $9 ; update dir
  96.   End:
  97.   
  98. FunctionEnd
  99.  
  100. !ifdef WINAMP_AUTOINSTALL
  101.  
  102. Function GetWinampInstPath
  103.  
  104.   Push $0
  105.   Push $1
  106.   Push $2
  107.   ReadRegStr $0 HKLM \
  108.      "Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \ 
  109.      "UninstallString"
  110.   StrCmp $0 "" fin
  111.  
  112.     StrCpy $1 $0 1 0 ; get firstchar
  113.     StrCmp $1 '"' "" getparent 
  114.       ; if first char is ", let's remove "'s first.
  115.       StrCpy $0 $0 "" 1
  116.       StrCpy $1 0
  117.       rqloop:
  118.         StrCpy $2 $0 1 $1
  119.         StrCmp $2 '"' rqdone
  120.         StrCmp $2 "" rqdone
  121.         IntOp $1 $1 + 1
  122.         Goto rqloop
  123.       rqdone:
  124.       StrCpy $0 $0 $1
  125.     getparent:
  126.     ; the uninstall string goes to an EXE, let's get the directory.
  127.     StrCpy $1 -1
  128.     gploop:
  129.       StrCpy $2 $0 1 $1
  130.       StrCmp $2 "" gpexit
  131.       StrCmp $2 "\" gpexit
  132.       IntOp $1 $1 - 1
  133.       Goto gploop
  134.     gpexit:
  135.     StrCpy $0 $0 $1
  136.  
  137.     StrCmp $0 "" fin
  138.     IfFileExists $0\winamp.exe fin
  139.       StrCpy $0 ""
  140.   fin:
  141.   Pop $2
  142.   Pop $1
  143.   Exch $0
  144.   
  145. FunctionEnd
  146.  
  147. Function MakeSureIGotWinamp
  148.  
  149.   Call GetWinampInstPath
  150.   
  151.   Pop $0
  152.   StrCmp $0 "" getwinamp
  153.     Return
  154.     
  155.   getwinamp:
  156.   
  157.   Call ConnectInternet ;Make an internet connection (if no connection available)
  158.   
  159.   StrCpy $2 "$TEMP\Winamp Installer.exe"
  160.   NSISdl::download http://download.nullsoft.com/winamp/client/winamp281_lite.exe $2
  161.   Pop $0
  162.   StrCmp $0 success success
  163.     SetDetailsView show
  164.     DetailPrint "download failed: $0"
  165.     Abort
  166.   success:
  167.     ExecWait '"$2" /S'
  168.     Delete $2
  169.     Call GetWinampInstPath
  170.     Pop $0
  171.     StrCmp $0 "" skip
  172.     StrCpy $INSTDIR $0
  173.   skip:
  174.   
  175. FunctionEnd
  176.  
  177. Function ConnectInternet
  178.  
  179.   Push $R0
  180.     
  181.     ClearErrors
  182.     Dialer::AttemptConnect
  183.     IfErrors noie3
  184.     
  185.     Pop $R0
  186.     StrCmp $R0 "online" connected
  187.       MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
  188.       Quit
  189.     
  190.     noie3:
  191.   
  192.     ; IE3 not installed
  193.     MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
  194.     
  195.     connected:
  196.   
  197.   Pop $R0
  198.   
  199. FunctionEnd
  200.  
  201. !endif ; WINAMP_AUTOINSTALL