1 2 37 38 package jnlp.sample.JreInstaller; 39 40 import java.io.*; 41 import java.net.*; 42 import java.util.*; 43 import javax.swing.JOptionPane ; 44 45 49 public class WindowsInstaller { 50 51 private static final String JAVAWS_REBOOT_FLAG_FILE = "jawsboot.ini"; 52 53 57 public static boolean execute(String execString) { 58 Config.trace("execute !" + execString + "!"); 59 try { 60 Process p = Runtime.getRuntime().exec(execString); 61 p.waitFor(); 62 } 63 catch (IOException ioe) { 64 Config.trace("Got exception: " + ioe); 65 return false; 66 } 67 catch (InterruptedException ie) { 68 Config.trace("Got exception: " + ie); 69 return false; 70 } 71 return true; 72 } 73 74 75 static File createTempISSScript(String jrepath, String version) throws IOException { 76 if (jrepath.endsWith("\\")) { 77 jrepath = jrepath.substring(0, jrepath.length() - 1); 78 } 79 String script = null; 80 81 if (version.equals("1.4.1_02")) { 82 script = 83 "[InstallShield Silent]\n" + 84 "Version=v6.00.000\n" + 85 "File=Response File\n" + 86 "[File Transfer]\n" + 87 "OverwrittenReadOnly=NoToAll\n" + 88 "[{EFCE5837-FC21-11D6-9D24-00010240CE95}-DlgOrder]\n" + 89 "Dlg0={EFCE5837-FC21-11D6-9D24-00010240CE95}-SdLicense-0\n" + 90 "Count=3\n" + 91 "Dlg1={EFCE5837-FC21-11D6-9D24-00010240CE95}-SetupType-0\n" + 92 "Dlg2={EFCE5837-FC21-11D6-9D24-00010240CE95}-SdAskDestPath-0\n" + 93 "[{EFCE5837-FC21-11D6-9D24-00010240CE95}-SdLicense-0]\n" + 94 "Result=1\n" + 95 "[{EFCE5837-FC21-11D6-9D24-00010240CE95}-SetupType-0]\n" + 96 "Result=303\n" + 97 "[{EFCE5837-FC21-11D6-9D24-00010240CE95}-SdAskDestPath-0]\n" + 98 "szDir=" + jrepath + "\n" + 99 "Result=1\n" + 100 "[Application]\n" + 101 "Name=Java 2 Runtime Environment, SE v" + version + "\n" + 102 "Version=" + version + "\n" + 103 "Company=JavaSoft\n" + 104 "Lang=0009\n"; 105 } else if (Config.isHopper()) { 106 script = 107 "[InstallShield Silent]\n" + 108 "Version=v6.00.000\n" + 109 "File=Response File\n" + 110 "[File Transfer]\n" + 111 "OverwrittenReadOnly=NoToAll\n" + 112 "[{CD0159C9-17FB-11D6-A76A-00B0D079AF64}-DlgOrder]\n" + 113 "Dlg0={CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SdLicense-0\n" + 114 "Count=3\n" + 115 "Dlg1={CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SetupType-0\n" + 116 "Dlg2={CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SdAskDestPath-0\n" + 117 "[{CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SdLicense-0]\n" + 118 "Result=1\n" + 119 "[{CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SetupType-0]\n" + 120 "Result=303\n" + 121 "[{CD0159C9-17FB-11D6-A76A-00B0D079AF64}-SdAskDestPath-0]\n" + 122 "szDir=" + jrepath + "\n" + 123 "Result=1\n" + 124 "[Application]\n" + 125 "Name=Java 2 Runtime Environment, SE v" + version + "\n" + 126 "Version=" + version + "\n" + 127 "Company=JavaSoft\n" + 128 "Lang=0009\n"; 129 } else if (Config.isMerlin()) { 130 script = 131 "[InstallShield Silent]\n" + 132 "Version=v6.00.000\n" + 133 "File=Response File\n" + 134 "[File Transfer]\n" + 135 "OverwrittenReadOnly=NoToAll\n" + 136 "[{F4588301-0A06-11D6-A761-00B0D079AF64}-DlgOrder]\n" + 137 "Dlg0={EE21CE74-CD7F-11D5-A886-00B0D079AF64}-SdWelcome-0\n" + 138 "Count=4\n" + 139 "Dlg1={F4588301-0A06-11D6-A761-00B0D079AF64}-SdLicense-0\n" + 140 "Dlg2={F4588301-0A06-11D6-A761-00B0D079AF64}-SdAskDestPath-0\n" + 141 "Dlg3={F4588301-0A06-11D6-A761-00B0D079AF64}-SdAskOptions-0\n" + 142 "[{F4588301-0A06-11D6-A761-00B0D079AF64}-SdWelcome-0]\n" + 143 "Result=1\n" + 144 "[{F4588301-0A06-11D6-A761-00B0D079AF64}-SdLicense-0]\n" + 145 "Result=1\n" + 146 "[{F4588301-0A06-11D6-A761-00B0D079AF64}-SdAskDestPath-0]\n" + 147 "szDir=" + jrepath + "\n" + 148 "Result=1\n" + 149 "[{F4588301-0A06-11D6-A761-00B0D079AF64}-SdAskOptions-0]\n" + 150 "Component-type=string\n" + 151 "Component-count=0\n" + 152 "Result=1\n" + 153 "[Application]\n" + 154 "Name=Java 2 Runtime Environment, SE v" + version + "\n" + 155 "Version=" + version + "\n" + 156 "Company=JavaSoft\n" + 157 "Lang=0009\n"; 158 } else if (version.equals("1.3.1_08")) { 159 script = 160 "[InstallShield Silent]\n" + 161 "Version=v6.00.000\n" + 162 "File=Response File\n" + 163 "[File Transfer]\n" + 164 "OverwrittenReadOnly=NoToAll\n" + 165 "[{B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-DlgOrder]\n" + 166 "Dlg0={B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdLicense-0\n" + 167 "Count=3\n" + 168 "Dlg1={B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdAskDestPath-0\n" + 169 "Dlg2={B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdAskOptions-0\n" + 170 "[{B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdLicense-0]\n" + 171 "Result=1\n" + 172 "[{B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdAskDestPath-0]\n" + 173 "szDir=" + jrepath + "\n" + 174 "Result=1\n" + 175 "[{B11CAD0E-0E0F-11D7-88BE-0050DA21757E}-SdAskOptions-0]\n" + 176 "Component-type=string\n" + 177 "Component-count=0\n" + 178 "Result=1\n" + 179 "[Application]\n" + 180 "Name=Java 2 Runtime Environment, SE v" + version + "\n" + 181 "Version=" + version + "\n" + 182 "Company=JavaSoft\n" + 183 "Lang=0009\n"; 184 } else { 185 script = 186 "[InstallShield Silent]\n" + 187 "Version=v5.00.000\n" + 188 "File=Response File\n" + 189 "[DlgOrder]\n" + 190 "Dlg0=SdLicense-0\n" + 191 "Dlg2=SdFinishReboot-0\n" + 192 "Count=3\n" + 193 "Dlg1=SdAskDestPath-0\n" + 194 "[SdLicense-0]\n" + 195 "Result=1\n" + 196 "[SdAskDestPath-0]\n" + 197 "szDir=" + jrepath + "\n" + 198 "Result=1\n" + 199 "[Application]\n" + 200 "Name=Java Runtime Environment\n" + 201 "Version=" + version + "\n" + 202 "Company=JavaSoft\n" + 203 "Lang=0009\n" + 204 "[SdFinishReboot-0]\n" + 205 "Result=1\n" + 206 "BootOption=0\n"; 207 } 208 209 File result = File.createTempFile("jre", "iss"); 210 result.deleteOnExit(); 211 PrintStream out = new PrintStream(new FileOutputStream(result)); 212 out.println(script); 213 out.close(); 214 return result; 215 } 216 217 218 219 224 static public boolean IsRebootNecessary() { 225 long versionMS = getLongHexResource(Config.getMsvcrtVersionMS()); 226 long versionLS = getLongHexResource(Config.getMsvcrtVersionLS()); 227 228 Config.trace("versions: " + versionMS + " " + versionLS); 229 230 File tmp = null; 231 File flagFile = null; 232 try { 233 tmp = File.createTempFile("javaws", "tmp"); 234 if (tmp != null) { 235 flagFile = new File(tmp.getParent() + File.separator + 236 JAVAWS_REBOOT_FLAG_FILE); 237 tmp.delete(); 238 } 239 } catch (IOException ioe) { 240 } 241 if (new WindowsInstaller().needsReboot(versionMS, versionLS) || 242 (flagFile != null && Config.isHopper() && flagFile.exists())) { 243 Config.trace("needs reboot"); 244 return true; 245 } 246 return false; 247 } 248 249 253 public static boolean askUserForReboot() { 254 String message = Config.getRebootMessage(); 255 String title = Config.getRebootTitle(); 256 Object [] options = new Object [] { 257 Config.getRebootNowString(), 258 Config.getRebootLaterString() 259 }; 260 if (JOptionPane.showOptionDialog(null, message, title, -1, 261 JOptionPane.QUESTION_MESSAGE, 262 null, options, options[0]) == 0) { 263 WinRegistry.doReboot(); 264 return true; 265 } 266 return false; 267 } 268 269 273 static private long getLongHexResource(String value) 274 throws MissingResourceException { 275 long retValue = 0; 276 int length = value.length(); 277 for (int counter = 0; counter < length; counter++) { 278 char aChar = value.charAt(counter); 279 retValue *= 16; 280 if (Character.isDigit(aChar)) { 281 retValue += (aChar - '0'); 282 } 283 else if (aChar >= 'a' && aChar <= 'f') { 284 retValue += (10 + aChar - 'a'); 285 } 286 else if (aChar >= 'A' && aChar <= 'F') { 287 retValue += (10 + aChar - 'A'); 288 } 289 } 290 return retValue; 291 } 292 293 297 private native boolean needsReboot(long versionMS, long versionLS); 298 299 302 private native void reboot(); 303 } 304 305 306 | Popular Tags |