chiark / gitweb /
Merge branch 'master' of chiark:src/jpctb-linkfarmer
[jarrg-owen.git] / windows-setup.vbs
1 ' JPCTB Installation Script\r
2 '\r
3 ' This program is Free Software.  Copyright (C) 2009 Owen Dunn\r
4 '\r
5 ' Permission is hereby granted, free of charge, to any person obtaining a copy\r
6 ' of this software and associated documentation files (the "Software"), to deal\r
7 ' in the Software without restriction, including without limitation the rights\r
8 ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
9 ' copies of the Software, and to permit persons to whom the Software is fur-\r
10 ' nished to do so, subject to the following conditions:\r
11 '\r
12 ' The above copyright notice and this permission notice shall be included in\r
13 ' all copies or substantial portions of the Software.\r
14 '\r
15 ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16 ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-\r
17 ' NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
18 ' AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19 ' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-\r
20 ' NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21 \r
22 ' Set this variable to true if you want this script to adjust your YPP installation\r
23 ' if it was installed before you installed a Sun JVM.  We default to false to\r
24 ' avoid any risk of rendering a YPP installation unusable.  Use this feature at\r
25 ' your own risk!\r
26 \r
27 fullauto = false\r
28 \r
29 ' If we're running under the GUI Windows Script Host, reexec\r
30 ' ourselves under the CLI version\r
31 \r
32 If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then\r
33     strPath = Wscript.ScriptFullName\r
34     strCommand = "%comspec% /k cscript  " & Chr(34) & strPath & chr(34)\r
35     Set objShell = CreateObject("Wscript.Shell")\r
36     objShell.Run(strCommand)\r
37     Wscript.Quit\r
38 End If\r
39 \r
40 ' First, find out where Puzzle Pirates is installed\r
41 \r
42 set WshShell = CreateObject("WScript.Shell")\r
43 set objFSO = CreateObject("Scripting.FileSystemObject")\r
44 \r
45 on error resume next\r
46 yppuninst = WshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Puzzle Pirates\UninstallString")\r
47 if hex(Err.number) = "80070002" then\r
48         WScript.Echo "Couldn't find YPP installation.  Bailing out."\r
49         WScript.Quit\r
50 end if\r
51 \r
52 ' back to errors killing us...\r
53 \r
54 on error goto 0\r
55 \r
56 yppdir = objFSO.GetParentFolderName(yppuninst)\r
57 \r
58 WScript.echo "Found YPP in "+yppdir\r
59 \r
60 ' Assuming we're running a Sun JVM, find out which one from \r
61 ' the Registry and where it is\r
62 \r
63 on error resume next\r
64 ver = WshShell.RegRead("HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion")\r
65 if hex(Err.number) = "80070002" then\r
66         WScript.Echo "Couldn't find your Sun Java VM.  Bailing out."\r
67         WScript.Echo "You will need to download and install a Sun Java VM from: "\r
68         WScript.Echo "        http://www.java.com/en/download/manual.jsp"\r
69         WScript.Quit\r
70 end if\r
71 \r
72 home = WshShell.RegRead("HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\"+ver+"\JavaHome")\r
73 if hex(Err.number) = "80070002" then\r
74         WScript.Echo "Couldn't find your Sun Java VM's location.  Bailing out."\r
75         WScript.Quit\r
76 end if\r
77 \r
78 ' back to errors killing us...\r
79 \r
80 on error goto 0\r
81 \r
82 WScript.echo "Found Sun Java "+ver+ " in "+home\r
83 \r
84 ' Is YPP using its own JVM or a system one?\r
85 \r
86 if (objFSO.FolderExists(yppdir+"\java")) then\r
87         WScript.echo "YPP currently using internal Java 1.5."\r
88         if (fullauto = true) then\r
89                 WScript.echo "...moving this aside."\r
90                 objFSO.MoveFolder yppdir+"\java", yppdir+"\java-aside"\r
91         else\r
92                 WScript.echo "You will need to uninstall Puzzle Pirates and then reinstall it"\r
93                 WScript.echo "for this installation to work."\r
94                 WScript.Quit\r
95         end if\r
96 end if\r
97 \r
98 if (objFSO.FolderExists(yppdir+"\java_vm")) then\r
99         WScript.echo "YPP currently using internal Java 1.6."\r
100         if (fullauto = true) then\r
101                 WScript.echo "...moving this aside."\r
102                 objFSO.MoveFolder yppdir+"\java_vm", yppdir+"\java_vm-aside"\r
103         else\r
104                 WScript.echo "You will need to uninstall Puzzle Pirates and then reinstall it"\r
105                 WScript.echo "for this installation to work."\r
106                 WScript.Quit\r
107         end if\r
108 end if\r
109 \r
110 ' Having furtled that, fix the desktop and start menu shortcut for non-modified YPP\r
111 \r
112 set WshSysEnv = WshShell.Environment("SYSTEM")\r
113 winsysdir = WshSysEnv("WINDIR")+"\system32"\r
114 strDesktop = WshShell.SpecialFolders("Desktop")\r
115 strPrograms = WshShell.SpecialFolders("Programs")\r
116 \r
117 ' We only modify YPP shortcuts if we're in full auto mode\r
118 \r
119 if (fullauto = true) then\r
120 set oShellLink = WshShell.CreateShortcut(strDesktop & "\Puzzle Pirates.lnk")\r
121          oShellLink.TargetPath = winsysdir+"\javaw.exe"\r
122         oShellLink.WorkingDirectory = yppdir\r
123          oShellLink.Save\r
124 \r
125 set oShellLink = WshShell.CreateShortcut(strPrograms & "\Puzzle Pirates.lnk")\r
126          oShellLink.TargetPath = winsysdir+"\javaw.exe"\r
127         oShellLink.WorkingDirectory = yppdir\r
128          oShellLink.Save\r
129 end if\r
130 \r
131 SrcFolder = home\r
132 \r
133 \r
134 ' Delete the destination folder if it currently exists\r
135 ' FIXME find and kill any jqs or jusched processes that will stop us\r
136 \r
137 set WshvolEnv = WshShell.Environment("Volatile")\r
138 localappdata = WshvolEnv("LOCALAPPDATA")\r
139 \r
140 ' XP doesn't have LOCALAPPDATA but does have APPDATA, although that's\r
141 ' the roaming profile rather than the local one, so not ideal...\r
142 \r
143 if (localappdata = "") then\r
144         localappdata = WshvolEnv("APPDATA") ' deeply undesirable if you have a roaming profile, but...\r
145 end if\r
146 \r
147 DstFolder = localappdata+"\JPCTB"\r
148 \r
149 if (objFSO.FolderExists(DstFolder)) then\r
150 objFSO.DeleteFolder DstFolder, true\r
151 end if\r
152 objFSO.CreateFolder DstFolder\r
153 \r
154 set objFolder = objFSO.GetFolder(SrcFolder)\r
155 \r
156 Wscript.echo("Copying Java directory tree...")\r
157 \r
158 objFSO.CopyFolder SrcFolder, DstFolder\r
159 \r
160 WScript.echo "Copying PCTB Uploader jar file..."\r
161 objFSO.copyFile "PCTB-Uploader.jar",DstFolder+"\lib\ext\",true\r
162 \r
163 Wscript.echo "Adding Accessibility properties..."\r
164 \r
165 set ap = objFSO.CreateTextFile(DstFolder+"\lib\accessibility.properties", true)\r
166 ap.WriteLine("assistive_technologies=com.tedpearson.ypp.market.MarketUploader")\r
167 ap.Close\r
168 \r
169 WScript.echo "Adding Desktop shortcut..."\r
170 \r
171 set WshShell = WScript.CreateObject("WScript.Shell")\r
172 strDesktop = WshShell.SpecialFolders("Desktop")\r
173 set oShellLink = WshShell.CreateShortcut(strDesktop & "\PCTB and Yarrg Puzzle Pirates.lnk")\r
174          oShellLink.TargetPath = DstFolder + "\bin\javaw.exe"\r
175         oShellLink.Arguments = "-jar getdown-dop.jar ."\r
176         oShellLink.WorkingDirectory = yppdir\r
177         oShellLink.IconLocation = yppdir+"\app_icon.ico, 0"\r
178          oShellLink.Save\r