nsis-installer-20040321
[openafs.git] / src / WINNT / install / NSIS / OpenAFS.nsi
index 627a96d..45e6a2e 100644 (file)
@@ -32,7 +32,7 @@ VIAddVersionKey "CompanyName" "OpenAFS.org"
 VIAddVersionKey "ProductVersion" ${AFS_VERSION}
 VIAddVersionKey "FileVersion" ${AFS_VERSION}
 VIAddVersionKey "FileDescription" "OpenAFS for Windows Installer"
-VIAddVersionKey "LegalCopyright" "(C)2003"
+VIAddVersionKey "LegalCopyright" "(C)2000-2004"
 !ifdef DEBUG
 VIAddVersionKey "PrivateBuild" "Checked/Debug"
 !endif               ; End DEBUG
@@ -455,14 +455,21 @@ var REG_DATA_3
 Section "AFS Client" secClient
 
   SetShellVarContext all
+
+  ; Check for bad previous installation (if we are doing a new install)
+  Call IsAnyAFSInstalled
+  Pop $R0
+  StrCmp $R0 "0" +1 skipCheck
+  Call CheckPathForAFS
+  skipCheck:
+
   ; Stop any running services or we can't replace the files
   ; Stop the running processes
   GetTempFileName $R0
   File /oname=$R0 "${AFS_WININSTALL_DIR}\Killer.exe"   ; Might not have the MSVCR71.DLL file to run
   nsExec::Exec '$R0 afscreds.exe'
-  nsExec::Exec "afscreds.exe -z"
+  Exec "afscreds.exe -z"
   ; in case we are upgrading an old version that does not support -z
-  Sleep 2000
   nsExec::Exec '$R0 afscreds.exe'
 !IFDEF INSTALL_KFW
   ;nsExec::Exec '$R0 krbcc32s.exe'
@@ -566,7 +573,7 @@ Section "AFS Client" secClient
   WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "VersionString" ${AFS_VERSION}
   WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "Title" "AFS Client"
   WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "Description" "AFS Client"
-  WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "PathName" "$INSTDIR\Client\Program"
+  WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "PathName" "$INSTDIR\Client"
   WriteRegStr HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "Software Type" "File System"
   WriteRegDWORD HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "MajorVersion" ${AFS_MAJORVERSION}
   WriteRegDWORD HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "MinorVersion" ${AFS_MINORVERSION}
@@ -601,14 +608,14 @@ Section "AFS Client" secClient
   CreateShortCut "$SMSTARTUP\AFS Credentials.lnk" "$INSTDIR\Client\Program\afscreds.exe" "-A -M -N -Q"
 
   Push "$INSTDIR\Client\Program"
-  Call AddToPath
+  Call AddToUniquePath
   Push "$INSTDIR\Common"
-  Call AddToPath
+  Call AddToUniquePath
   
 !ifdef INSTALL_KFW
   ; Add kfw to path too
   Push "$INSTDIR\kfw\bin"
-  Call AddToPath
+  Call AddToUniquePath
 !endif
    
   ; Create the AFS service
@@ -632,6 +639,11 @@ skipremove:
   WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\NetworkProvider" "AuthentProviderPath" "$INSTDIR\Client\Program\afslogon.dll"
   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\NetworkProvider" "Class" 2
   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\NetworkProvider" "VerboseLogging" 10
+
+  ; Must also add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder
+  ; and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order
+  ; to also include the service name.
+  Call AddProvider
   ReadINIStr $R0 $1 "Field 7" "State"
   ReadINIStr $R1 $1 "Field 9" "State"
   ; Complicated way to do $R1 = ($R1 *2) + $R0
@@ -649,7 +661,8 @@ skipremove:
   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "SecurityLevel" $R0
   ReadINIStr $R0 $1 "Field 5" "State"  
   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "FreelanceClient" $R0
-  WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "UseDNS" 1
+  ReadINIStr $R0 $1 "Field 11" "State"
+  WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "UseDNS" $R0
   WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "NetbiosName" "AFS"
   WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "MountRoot" "/afs"
   WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon\Parameters" "RxMaxMTU" 1260
@@ -684,12 +697,20 @@ SectionEnd
 Section "AFS Server" secServer
 
   SetShellVarContext all
+
+  ; Check for bad previous installation (if we are doing a new install)
+  Call IsAnyAFSInstalled
+  Pop $R0
+  StrCmp $R0 "0" +1 skipCheck
+  Call CheckPathForAFS
+skipCheck:
+
   ; Stop any running services or we can't replace the files
   ; Stop the running processes
   GetTempFileName $R0
   File /oname=$R0 "${AFS_WININSTALL_DIR}\Killer.exe"   ; Might not have the MSVCR71.DLL file to run
   nsExec::Exec '$R0 afscreds.exe'
-  nsExec::Exec "afscreds.exe -z"
+  Exec "afscreds.exe -z"
   ; in case we are upgrading an old version that does not support -z
   Sleep 2000
   nsExec::Exec '$R0 afscreds.exe'
@@ -1317,11 +1338,24 @@ contInstall:
    Call ShouldClientInstall
    Pop $R2
    
+   ; Check if it was an IBM/Transarc version
+   ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Services\TransarcAFSDaemon" "DisplayName"
+   StrCmp $R0 "IBM AFS Client" DoIBM
+   StrCmp $R0 "Transarc AFS Client" DoIBM
+NotIBM:
+   StrCpy $R9 ""
    StrCmp $R2 "0" NoClient
    StrCmp $R2 "1" ReinstallClient
    StrCmp $R2 "2" UpgradeClient
    StrCmp $R2 "3" DowngradeClient
-   
+   goto Continue
+DoIBM:
+   ReadRegDWORD $R0 HKLM "Software\TransarcCorporation\AFS Client\CurrentVersion" "MajorVersion"
+   StrCmp $R0 "3" +1 NotIBM
+   StrCpy $R9 "IBM"
+   goto UpgradeClient
+
+Continue:
        SectionGetFlags ${secClient} $0
        IntOp $0 $0 | ${SF_SELECTED}
        SectionSetFlags ${secClient} $0
@@ -1421,13 +1455,13 @@ CheckDocs:
        SectionGetFlags ${secDocs} $0
        IntOp $0 $0 | ${SF_SELECTED}
        SectionSetFlags ${secDocs} $0
-   goto end
+   goto CheckSDK
    
 NoDocs:
        SectionGetFlags ${secDocs} $0
        IntOp $0 $0 & ${SECTION_OFF}
        SectionSetFlags ${secDocs} $0
-   goto end
+   goto CheckSDK
    
 ; To check the SDK, we simply look to see if the files exist.  If they do,
 ; the SDK is installed.  If not, we don't need to push it on the user.
@@ -1486,7 +1520,24 @@ end:
   StrCmp $R0 "" TryServer
   Push $R0
   Call GetParent
-  Call GetParent
+  
+  ; Work around bug in 1.3.5000, 1.3.5100, 1.3.5200, 1.3.5201, 1.3.5299 installers...
+  ReadRegStr $R0 HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "MajorVersion"
+  StrCmp $R0 "1" +1 SkipParent
+  ReadRegStr $R0 HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "MinorVersion"
+  StrCmp $R0 "3" +1 SkipParent
+  ReadRegStr $R0 HKLM "${AFS_REGKEY_ROOT}\AFS Client\CurrentVersion" "PatchLevel"
+  StrCmp $R0 "5000" UpParent
+  StrCmp $R0 "5100" UpParent
+  StrCmp $R0 "5200" UpParent
+  StrCmp $R0 "5201" UpParent
+  StrCmp $R0 "5299" UpParent
+  goto SkipParent
+  
+UpParent:
+   Call GetParent
+  
+SkipParent:
   Pop $R0
   StrCpy $INSTDIR $R0
   goto Nope
@@ -1560,7 +1611,7 @@ StartRemove:
   GetTempFileName $R0
   File /oname=$R0 "${AFS_WININSTALL_DIR}\Killer.exe"
   nsExec::Exec '$R0 afscreds.exe'
-  nsExec::Exec "afscreds.exe -z"
+  Exec "afscreds.exe -z"
   ; in case we are upgrading an old version that does not support -z
   Sleep 2000
   nsExec::Exec '$R0 afscreds.exe'
@@ -1580,6 +1631,8 @@ StartRemove:
   nsExec::Exec '$R0 u TransarcAFSServer'
   Delete $R0
   
+  Call un.RemoveProvider
+
   Push "$INSTDIR\Client\Program"
   Call un.RemoveFromPath
   Push "$INSTDIR\Common"
@@ -1975,11 +2028,14 @@ StrCmp $R0 "1" DoDownload
 ReadINIStr $R0 $0 "Field 2" "State"
 StrCmp $R0 "1" done
 
+ReadINIStr $R0 $0 "Field 6" "State"
+StrCmp $R0 "1" CheckOther
+
 ReadINIStr $R0 $0 "Field 3" "State"
 StrCmp $R0 "1" UsePackaged
 
 ; If none of these, grab file from other location
-goto CheckOther
+goto UsePackaged
 
 DoDownload:
    ReadINIStr $R0 $0 "Field 5" "State"
@@ -1996,13 +2052,139 @@ UsePackaged:
    
 CheckOther:
    ReadINIStr $R0 $0 "Field 7" "State"
-   StrCmp $R0 "1" +1 done
+   StrCmp $R0 "" done
    CopyFiles $R0 "$WINDIR\afsdcell.ini"
    
 done:
 
 FunctionEnd
 
+Function AddProvider
+   Push $R0
+   Push $R1
+   ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\HWOrder" "ProviderOrder"
+   Push $R0
+   StrCpy $R0 "TransarcAFSDaemon"
+   Push $R0
+   Call StrStr
+   Pop $R0
+   StrCmp $R0 "" +1 DoOther
+   ReadRegStr $R1 HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\HWOrder" "ProviderOrder"   
+   StrCpy $R0 "$R1,TransarcAFSDaemon"
+   WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\HWOrder" "ProviderOrder" $R0
+DoOther:
+   ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" "ProviderOrder"
+   Push $R0
+   StrCpy $R0 "TransarcAFSDaemon"
+   Push $R0
+   Call StrStr
+   Pop $R0
+   StrCmp $R0 "" +1 End
+   ReadRegStr $R1 HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" "ProviderOrder"   
+   StrCpy $R0 "$R1,TransarcAFSDaemon"
+   WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" "ProviderOrder" $R0   
+End:
+   Pop $R1
+   Pop $R0
+FunctionEnd
+
+Function un.RemoveProvider
+   Push $R0
+   StrCpy $R0 "TransarcAFSDaemon"
+   Push $R0
+   StrCpy $R0 "SYSTEM\CurrentControlSet\Control\NetworkProvider\HWOrder"
+   Call un.RemoveFromProvider
+   StrCpy $R0 "TransarcAFSDaemon"
+   Push $R0
+   StrCpy $R0 "SYSTEM\CurrentControlSet\Control\NetworkProvider\Order"
+   Call un.RemoveFromProvider
+   Pop $R0
+FunctionEnd
+
+Function un.RemoveFromProvider
+  Exch $0
+  Push $1
+  Push $2
+  Push $3
+  Push $4
+  Push $5
+  Push $6
+
+  ReadRegStr $1 HKLM "$R0" "ProviderOrder"
+    StrCpy $5 $1 1 -1 # copy last char
+    StrCmp $5 "," +2 # if last char != ,
+      StrCpy $1 "$1," # append ,
+    Push $1
+    Push "$0,"
+    Call un.StrStr ; Find `$0,` in $1
+    Pop $2 ; pos of our dir
+    StrCmp $2 "" unRemoveFromPath_done
+      ; else, it is in path
+      # $0 - path to add
+      # $1 - path var
+      StrLen $3 "$0,"
+      StrLen $4 $2
+      StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
+      StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
+      StrCpy $3 $5$6
+
+      StrCpy $5 $3 1 -1 # copy last char
+      StrCmp $5 "," 0 +2 # if last char == ,
+        StrCpy $3 $3 -1 # remove last char
+
+      WriteRegStr HKLM "$R0" "ProviderOrder" $3
+      
+  unRemoveFromPath_done:
+    Pop $6
+    Pop $5
+    Pop $4
+    Pop $3
+    Pop $2
+    Pop $1
+    Pop $0
+FunctionEnd
+
+Function CheckPathForAFS
+   Push $0
+   Push $1
+   Push $2
+   Push $3
+   ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PATH"
+   StrCpy $1 "$1;"
+loop:
+   Push $1
+   Push ";"
+   Call StrStr
+   Pop $0
+   StrLen $2 $0
+   StrCpy $3 $1 -$2
+   IfFileExists "$3\afsd_service.exe" Error
+   StrCpy $1 $0 32768 1
+   StrLen $2 $1
+   IntCmp $2 0 Done Done loop
+   goto Done
+Error:
+   MessageBox MB_ICONSTOP|MB_OK|MB_TOPMOST "This installer is unable to upgrade the previous version of AFS. Please uninstall the current AFS version before continuing."
+   Abort "Unable to install OpenAFS"
+Done:
+   Pop $3
+   Pop $2
+   Pop $1
+   Pop $0
+FunctionEnd
+
+Function AddToUniquePath
+   Pop $R0
+   Push $R0
+   Push "$R0;"
+   ReadRegStr $R0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PATH"
+   Push "$R0;"
+   Call StrStr
+   Pop $R0
+   StrCmp $R0 "" +1 Done
+   Call AddToPath
+Done:
+FunctionEnd
 
 
 ;-------------------------------
@@ -2219,7 +2401,7 @@ Function ShouldClientInstall
    
    StrCmp $R0 "" NotInstalled
    ; Now we see if it's an older or newer version
-
+   
    Call GetInstalledVersionMajor
    Pop $R0
    IntCmpU $R0 ${AFS_MAJORVERSION} +1 Upgrade Downgrade
@@ -2247,7 +2429,6 @@ Downgrade:
    Exch $R0
    goto end
    
-   
 NotInstalled:
    StrCpy $R0 "0"
    Exch $R0