
!macro GETCMDLINE

 ; This function was taken directly from the scripting reference.
 ;
 ; Usage:
 ;
 ; Function .oninit
 ; !insertmacro GETCMDLINE
 ; pop $0
 ; ;at this point $0 has the commands line parameters in it.
 ; FunctionEnd


   Push $R0
   Push $R1
   Push $R2
   Push $R3

   StrCpy $R2 1
   StrLen $R3 $CMDLINE

   ;Check for quote or space
   StrCpy $R0 $CMDLINE $R2
   StrCmp $R0 '"' 0 +3
     StrCpy $R1 '"'
     Goto loop
   StrCpy $R1 " "

   loop:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 $R1 get
     StrCmp $R2 $R3 get
     Goto loop

   get:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 " " get
     StrCpy $R0 $CMDLINE "" $R2

   Pop $R3
   Pop $R2
   Pop $R1
   Exch $R0

!macroend

!macro CHECKWINVER
 ; CheckWinver
 ;
 ; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
 ; Updated by Joost Verburg
 ;
 ; Modified for use in a header and for InstallSpider by Jason Ross
 ;
 ; Windows Version (95, 98, ME, NT x.x, 2000, XP, 2003, Vista)
 ; or
 ; '' (Unknown Windows Version)
 ; NOTE: Vista is only experimental at this stage. I will update this function when Vista is released.
 ;
 ; If you want to install on any system, don't include the defines or the macro.
 ;
 ; Usage:
 ;   Function .oninit
 ;     !define win98
 ;     !define winXP
 ;     !insertmacro CHECKWINVER
 ;   ; If the system is not one of those defined, the macro puts up an error message
 ;   ; saying which versions this program can be installed on.


   Push $0
   Push $1
   Push $2
   Push $3
   Push $4
   Push $5
   Push $6
   Push $7

   Push $R0
   Push $R1
   Push $R2
   Push $R3
   Push $R4
   Push $R5

   strcpy $R3 0
   
   strcpy $0 false
   strcpy $1 false
   strcpy $2 false
   strcpy $3 false
   strcpy $4 false
   strcpy $5 false
   strcpy $6 false
   strcpy $7 false

   ClearErrors

   strcpy $R2 0

   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 $0 true
     Goto Message
   lbl_win32_98:
     strcpy $1 true
     Goto Message
   lbl_win32_ME:
     strcpy $2 true
     Goto Message

   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
   StrCmp $R1 '6.0' lbl_winnt_VISTA

   lbl_winnt_x:
     !ifdef winNT
       StrCpy $R0 $R0 3
       IntCmp $R0 ${winNT} lbl_done 0 lbl_done
       strcpy $3 true
       Goto Message
     !endif
   lbl_winnt_2000:
     strcpy $4 true
     Goto Message

   lbl_winnt_2003:
     strcpy $5 true
     Goto Message

   lbl_winnt_XP:
     strcpy $6 true
     Goto Message

   lbl_winnt_VISTA:
     strcpy $7 true
     Goto Message

   lbl_error:
     MessageBox MB_OK|MB_ICONSTOP "This setup program is running on an unsupported operating system. Setup will now close."
     Quit
   Message:

        !ifdef winVISTA
          strcmp $7 false 0 lbl_done
            push "Windows Vista"
            intop $R2 $R2 + 1
        !endif
        !ifdef winXP
          strcmp $6 false 0 lbl_done
            push "Windows XP"
            intop $R2 $R2 + 1
        !endif
        !ifdef win2003
          strcmp $5 false 0 lbl_done
            push "Windows 2003"
            intop $R2 $R2 + 1
        !endif
        !ifdef win2000
          strcmp $4 false 0 lbl_done
            push "Windows 2000"
            intop $R2 $R2 + 1
        !endif
        !ifdef winNT
          strcmp $3 false 0 lbl_done
            push "Windows NT ${winNT} and above"
            intop $R2 $R2 + 1
        !endif
        !ifdef winME
          strcmp $2 false 0 lbl_done
            push "Windows ME"
            intop $R2 $R2 + 1
        !endif
        !ifdef win98
          strcmp $1 false 0 lbl_done
            push "Windows 98"
            intop $R2 $R2 + 1
        !endif
        !ifdef win95
          strcmp $0 false 0 lbl_done
            push "Windows 95"
            intop $R2 $R2 + 1
        !endif

     StrCpy $R3 0

     Loop:
     pop $R4
     strcmp $R3 0 +3 0
     strcpy $R5 "$R5, $R4"
     goto +2
     strcpy $R5 $R4
     intop $R3 $R3 + 1
     StrCmp $R3 $R2 0 Loop

     MessageBox MB_OK|MB_ICONSTOP "This program can only be installed on the following operating systems: $R5."
     Quit
   lbl_done:

   Pop $R5
   Pop $R4
   Pop $R3
   Pop $R2
   Pop $R1
   Pop $R0

   Pop $7
   Pop $6
   Pop $5
   Pop $4
   Pop $3
   Pop $2
   Pop $1
   Pop $0

!macroend