chiark / gitweb /
Windows setup script
authorOwen Dunn <owend@chiark.greenend.org.uk>
Sun, 6 Dec 2009 15:28:03 +0000 (15:28 +0000)
committerOwen Dunn <owend@chiark.greenend.org.uk>
Sun, 6 Dec 2009 15:28:03 +0000 (15:28 +0000)
windows-setup.vbs [new file with mode: 0644]

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