;; Windows Pidgin NSIS installer plugin helper utilities ;; Copyright 2005, Daniel Atallah <daniel_atallah@yahoo.com> ;; Include in plugin installer scripts using: ;; !addincludedir "${PATH_TO_PIDGIN_SRC}\pidgin\win32\nsis" ;; !include "pidgin-plugin.nsh" !define PIDGIN_REG_KEY
"SOFTWARE\pidgin" !define PIDGIN_VERSION_OK
0
!define PIDGIN_VERSION_INCOMPATIBLE
1
!define PIDGIN_VERSION_UNDEFINED
2
; Extract the Pidgin Version from the registry ; This will set the Error flag if unable to determine the value ; Pop the value of the stack after calling this to get the value (unless Error Flag is set) Function GetPidginVersion
; Read the pidgin version ReadRegStr $R0 HKLM ${PIDGIN_REG_KEY} "Version" IfErrors +1
GetPidginVersion_found
; fall back to the HKCU registry key ReadRegStr $R0 HKCU ${PIDGIN_REG_KEY} "Version" IfErrors GetPidginVersion_done
; Keep the error flag set Push $R0 ; Push the value onto the stack ; Check that the currently installed Pidgin version is compatible ; with the plugin version we are installing ; Push the Plugin's Pidgin Version onto the Stack before calling ; After calling, the top of the Stack will contain the result of the check: ; PIDGIN_VERSION_OK - If the installed Pidgin version is compatible w/ the version specified ; PIDGIN_VERSION_INCOMPATIBLE - If the installed Pidgin version isn't compatible w/ the version specified ; PIDGIN_VERSION_UNDEFINED - If the installed Pidgin version can't be determined Function CheckPidginVersion
; Save the Variable values that we will use in the stack Pop $R4 ; Get the plugin's Pidgin Version ; Read the pidgin version IfErrors checkPidginVersion_noPidginInstallFound
;If they are exactly the same, we don't need to look at anything else StrCmp $R0 $R4 checkPidginVersion_VersionOK
; Versions are in the form of X.Y.Z ; If X is different or plugin's Y > pidgin's Y, then we shouldn't install IfErrors checkPidginVersion_noPidginInstallFound
;We couldn't extract 'X' from the installed pidgin version IfErrors checkPidginVersion_BadVersion
; this isn't a valid version, so don't bother even checking ;Check that both versions' X is the same StrCmp $R1 $R2 +1
checkPidginVersion_BadVersion
IfErrors checkPidginVersion_noPidginInstallFound
;We couldn't extract 'Y' from the installed pidgin version IfErrors checkPidginVersion_BadVersion
; this isn't a valid version, so don't bother even checking ;Check that plugin's Y <= pidgin's Y IntCmp $R1 $R2 checkPidginVersion_VersionOK
checkPidginVersion_VersionOK
checkPidginVersion_BadVersion
checkPidginVersion_BadVersion: Push ${PIDGIN_VERSION_INCOMPATIBLE} goto checkPidginVersion_done
checkPidginVersion_noPidginInstallFound: Push ${PIDGIN_VERSION_UNDEFINED} goto checkPidginVersion_done
checkPidginVersion_VersionOK: Push ${PIDGIN_VERSION_OK} ; Restore the Variables that we used ; Extract the part of a string prior to "." (or the whole string if there is no ".") ; If no "." was found, the ErrorFlag will be set ; Before this is called, Push ${VERSION_STRING} must be called, and then Push 0 for Major, 1 for Minor, etc ; Pop should be called after to retrieve the new value Function GetVersionComponent
; Save the Variable values that we will use in the stack Pop $1 ;The version component which we want to extract (0, 1, 2) Pop $0 ;The string from which to extract the version component StrCpy $2 "0" ;Initialize our string index counter StrCpy $7 "0" ;Index of last "." StrCpy $3 "0" ;Initialize our version index counter startGetVersionComponentLoop: ;avoid infinite loop (if we have gotten the whole initial string, exit the loop and set the error flag) StrCmp $6 $0 GetVersionComponentSetErrorFlag
StrCpy $6 $0 $2 ;Update the infinite loop preventing string ;Determine the correct substring (only the current index component) StrCpy $4 $0 $5 $7 ;Append the current character in $0 to $4 StrCpy $5 $0 1
$2 ;store the next character in $5 ;if the next character is ".", $4 will contain the version component prior to "." StrCmp $5 "." +1
startGetVersionComponentLoop
StrCmp $3 $1 doneGetVersionComponent
;If it is the version component we're looking for, stop IntOp $3 $3 + 1
;Increment the version index counter IntOp $2 $2 + 1
;Increment the version string index to "." (so it will be skipped) StrCpy $7 $2 ;Keep track of the index of the last "." StrCpy $6 $0 $2 ;Update the infinite loop preventing string goto startGetVersionComponentLoop
GetVersionComponentSetErrorFlag: ; Restore the Variables that we used Push $4 ;This is the value we're returning