' JPCTB Installation Script ' ' This program is Free Software. Copyright (C) 2009 Owen Dunn ' ' Permission is hereby granted, free of charge, to any person obtaining a copy ' of this software and associated documentation files (the "Software"), to deal ' in the Software without restriction, including without limitation the rights ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ' copies of the Software, and to permit persons to whom the Software is fur- ' nished to do so, subject to the following conditions: ' ' The above copyright notice and this permission notice shall be included in ' all copies or substantial portions of the Software. ' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- ' NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ' AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- ' NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ' Set this variable to true if you want this script to adjust your YPP installation ' if it was installed before you installed a Sun JVM. We default to false to ' avoid any risk of rendering a YPP installation unusable. Use this feature at ' your own risk! fullauto = false ' If we're running under the GUI Windows Script Host, reexec ' ourselves under the CLI version If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then strPath = Wscript.ScriptFullName strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34) Set objShell = CreateObject("Wscript.Shell") objShell.Run(strCommand) Wscript.Quit End If ' First, find out where Puzzle Pirates is installed set WshShell = CreateObject("WScript.Shell") set objFSO = CreateObject("Scripting.FileSystemObject") on error resume next yppuninst = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Puzzle Pirates\UninstallString") if hex(Err.number) = "80070002" then WScript.Echo "Couldn't find YPP installation. Bailing out." WScript.Quit end if ' back to errors killing us... on error goto 0 yppdir = objFSO.GetParentFolderName(yppuninst) WScript.echo "Found YPP in "+yppdir ' Assuming we're running a Sun JVM, find out which one from ' the Registry and where it is on error resume next ver = WshShell.RegRead("HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion") if hex(Err.number) = "80070002" then WScript.Echo "Couldn't find your Sun Java VM. Bailing out." WScript.Echo "You will need to download and install a Sun Java VM from: " WScript.Echo " http://www.java.com/en/download/manual.jsp" WScript.Quit end if home = WshShell.RegRead("HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\"+ver+"\JavaHome") if hex(Err.number) = "80070002" then WScript.Echo "Couldn't find your Sun Java VM's location. Bailing out." WScript.Quit end if ' back to errors killing us... on error goto 0 WScript.echo "Found Sun Java "+ver+ " in "+home ' Is YPP using its own JVM or a system one? if (objFSO.FolderExists(yppdir+"\java")) then WScript.echo "YPP currently using internal Java 1.5." if (fullauto = true) then WScript.echo "...moving this aside." objFSO.MoveFolder yppdir+"\java", yppdir+"\java-aside" else WScript.echo "You will need to uninstall Puzzle Pirates and then reinstall it" WScript.echo "for this installation to work." WScript.Quit end if end if if (objFSO.FolderExists(yppdir+"\java_vm")) then WScript.echo "YPP currently using internal Java 1.6." if (fullauto = true) then WScript.echo "...moving this aside." objFSO.MoveFolder yppdir+"\java_vm", yppdir+"\java_vm-aside" else WScript.echo "You will need to uninstall Puzzle Pirates and then reinstall it" WScript.echo "for this installation to work." WScript.Quit end if end if ' Having furtled that, fix the desktop and start menu shortcut for non-modified YPP set WshSysEnv = WshShell.Environment("SYSTEM") winsysdir = WshSysEnv("WINDIR")+"\system32" strDesktop = WshShell.SpecialFolders("Desktop") strPrograms = WshShell.SpecialFolders("Programs") ' We only modify YPP shortcuts if we're in full auto mode if (fullauto = true) then set oShellLink = WshShell.CreateShortcut(strDesktop & "\Puzzle Pirates.lnk") oShellLink.TargetPath = winsysdir+"\javaw.exe" oShellLink.WorkingDirectory = yppdir oShellLink.Save set oShellLink = WshShell.CreateShortcut(strPrograms & "\Puzzle Pirates.lnk") oShellLink.TargetPath = winsysdir+"\javaw.exe" oShellLink.WorkingDirectory = yppdir oShellLink.Save end if SrcFolder = home ' Delete the destination folder if it currently exists ' FIXME find and kill any jqs or jusched processes that will stop us set WshvolEnv = WshShell.Environment("Volatile") localappdata = WshvolEnv("LOCALAPPDATA") ' XP doesn't have LOCALAPPDATA but does have APPDATA, although that's ' the roaming profile rather than the local one, so not ideal... if (localappdata = "") then localappdata = WshvolEnv("APPDATA") ' deeply undesirable if you have a roaming profile, but... end if DstFolder = localappdata+"\JPCTB" if (objFSO.FolderExists(DstFolder)) then objFSO.DeleteFolder DstFolder, true end if objFSO.CreateFolder DstFolder set objFolder = objFSO.GetFolder(SrcFolder) Wscript.echo("Copying Java directory tree...") objFSO.CopyFolder SrcFolder, DstFolder WScript.echo "Copying PCTB Uploader jar file..." objFSO.copyFile "PCTB-Uploader.jar",DstFolder+"\lib\ext\",true Wscript.echo "Adding Accessibility properties..." set ap = objFSO.CreateTextFile(DstFolder+"\lib\accessibility.properties", true) ap.WriteLine("assistive_technologies=com.tedpearson.ypp.market.MarketUploader") ap.Close WScript.echo "Adding Desktop shortcut..." set WshShell = WScript.CreateObject("WScript.Shell") strDesktop = WshShell.SpecialFolders("Desktop") set oShellLink = WshShell.CreateShortcut(strDesktop & "\PCTB and Yarrg Puzzle Pirates.lnk") oShellLink.TargetPath = DstFolder + "\bin\javaw.exe" oShellLink.Arguments = "-jar getdown-dop.jar ." oShellLink.WorkingDirectory = yppdir oShellLink.IconLocation = yppdir+"\app_icon.ico, 0" oShellLink.Save