1 package installer; 2 3 /* 4 * InstallWizard.java 5 * 6 * Created on 04 July 2002, 15:09 7 */ 8 9 /** 10 * 11 * @author mike 12 */ 13 14 import javax.swing.*; 15 import java.awt.*; 16 import java.awt.event.*; 17 import java.util.*; 18 import java.net.*; 19 import java.io.*; 20 21 public class InstallWizard extends javax.swing.JFrame implements ActionListener { 22 /* 23 private static class ShutdownHook extends Thread { 24 public void run() 25 { 26 if (InstallWizard.isInstallStarted()) 27 { 28 // Check for and backup any config.xml files 29 // Check for and backup any StarBasic macro files 30 // Check for and backup ProtocolHandler 31 32 if (!InstallWizard.isPatchedTypes()) 33 { 34 File backup = new File(InstUtil.getTmpDir(), "TypeDetection.xml"); 35 File destination = new File(InstallWizard.getTypesPath()); 36 InstUtil.copy(backup, destination); //Restore typedetection.xml 37 } 38 if (!InstallWizard.isPatchedJava()) 39 { 40 File backup = new File(InstUtil.getTmpDir(), "Java.xml"); 41 File destination = new File(InstallWizard.getJavaPath()); 42 InstUtil.copy(backup, destination); //Restore typedetection.xml 43 } 44 if (!InstallWizard.isPatchedRDB()) 45 { 46 File backup = new File(InstUtil.getTmpDir(), "applicat.rdb"); 47 File destination = new File(InstallWizard.getJavaPath()); 48 //InstUtil.copy(backup, destination); //Restore typedetection.xml 49 } 50 51 System.out.println( "ShutdownHook" ); 52 } 53 54 InstUtil.removeTmpDir(); 55 } 56 }// class ShutdownHook 57 58 static { 59 Runtime rt=Runtime.getRuntime(); 60 rt.addShutdownHook(new ShutdownHook()); 61 } 62 */ 63 /** Creates new form InstallWizard */ 64 public InstallWizard() { 65 super("Office Scripting Framework Installer - Early Developer Release"); 66 67 try { 68 System.out.print("All diagnostic output is being redirected to SFrameworkInstall.log\n"); 69 System.out.print("Location: "+ System.getProperty( "user.dir" ) + 70 File.separator + "SFrameworkInstall.log\n"); 71 72 LogStream log = new LogStream( "SFrameworkInstall.log" ); 73 System.setErr(log); 74 75 System.setOut(log); 76 } 77 catch( FileNotFoundException fnfe ) { 78 System.err.println("Office Scripting Framework Installer - Error: "); 79 System.err.println("Unable to create log file for installation."); 80 exitForm(null); 81 } 82 83 //setBackground(Color.WHITE); 84 setBackground(new Color(0,0,0)); 85 locations = new ArrayList(); 86 //Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); 87 Point center = new Point( 400, 400 ); 88 int windowWidth=200; 89 int windowHeight=300; 90 setSize(windowWidth,windowHeight); 91 setBounds((center.x-windowWidth/2)-115,(center.y-windowWidth/2)-100, windowWidth,windowHeight); 92 initComponents(); 93 setResizable(false); 94 } 95 96 /** This method is called from within the constructor to 97 * initialize the form. 98 */ 99 private void initComponents() { 100 navigation = new javax.swing.JPanel(); 101 navBack = new javax.swing.JButton(); 102 navNext = new javax.swing.JButton(); 103 navCancel = new javax.swing.JButton(); 104 screens = new javax.swing.JPanel(); 105 106 addWindowListener(new java.awt.event.WindowAdapter() { 107 public void windowClosing(java.awt.event.WindowEvent evt) { 108 exitForm(evt); 109 } 110 }); 111 112 navigation.setLayout(new java.awt.GridBagLayout()); 113 java.awt.GridBagConstraints gridBagConstraints1; 114 115 navBack.setText("<< Back"); 116 gridBagConstraints1 = new java.awt.GridBagConstraints(); 117 gridBagConstraints1.insets = new java.awt.Insets(1, 1, 1, 1); 118 119 navNext.setText("Next >>"); 120 gridBagConstraints1 = new java.awt.GridBagConstraints(); 121 gridBagConstraints1.gridx = 2; 122 gridBagConstraints1.gridy = 0; 123 124 navCancel.setText("Cancel"); 125 gridBagConstraints1 = new java.awt.GridBagConstraints(); 126 gridBagConstraints1.gridx = 6; 127 gridBagConstraints1.gridy = 0; 128 //navigation.add(navNext, gridBagConstraints1); 129 //navigation.add(navBack, gridBagConstraints1); 130 //navigation.add(navCancel, gridBagConstraints1); 131 132 getContentPane().add(navigation, java.awt.BorderLayout.SOUTH); 133 screens.setLayout(new java.awt.CardLayout()); 134 screens.add(WELCOME, new Welcome(this)); 135 version = new Version(this); 136 screens.add(VERSIONS, version); 137 _final = new Final(this); 138 screens.add(FINAL, _final); 139 140 //boolean hasIDEInstallation = (InstUtil.hasNetbeansInstallation() || InstUtil.hasJeditInstallation()) ; 141 boolean hasIDEInstallation = ( InstUtil.hasNetbeansInstallation() ) ; 142 143 if( hasIDEInstallation ) 144 { 145 idewelcome = new IdeWelcome(this); 146 screens.add(IDEWELCOME, idewelcome); 147 ideversion = new IdeVersion(this); 148 screens.add(IDEVERSIONS, ideversion); 149 idefinal = new IdeFinal(this); 150 screens.add(IDEFINAL, idefinal); 151 } 152 getContentPane().add(screens, java.awt.BorderLayout.CENTER); 153 154 navNext.addActionListener(this); 155 navNext.addActionListener(version); 156 navNext.addActionListener(_final); 157 158 if( hasIDEInstallation ) 159 { 160 navNext.addActionListener(ideversion); 161 navNext.addActionListener(idefinal); 162 } 163 164 navCancel.addActionListener(this); 165 navBack.addActionListener(this); 166 167 168 URL url = this.getClass().getResource("sidebar.jpg"); 169 JLabel sideBar = new JLabel(); 170 sideBar.setIcon(new ImageIcon(url)); 171 getContentPane().add (sideBar, java.awt.BorderLayout.WEST); 172 pack(); 173 }// initComponents 174 175 /** Exit the Application */ 176 public void exitForm(java.awt.event.WindowEvent evt) { 177 System.exit(0); 178 } 179 180 181 public void actionPerformed(ActionEvent e) 182 { 183 if (e.getSource() == navNext) 184 { 185 ((CardLayout)screens.getLayout()).next(screens); 186 } 187 188 if (e.getSource() == navCancel) 189 { 190 exitForm(null); 191 } 192 193 if (e.getSource() == navBack) 194 { 195 ((CardLayout)screens.getLayout()).previous(screens); 196 } 197 }// actionPerformed 198 199 public static void storeLocation(String path) 200 { 201 locations.add(path); 202 } 203 204 public static ArrayList getLocations() 205 { 206 return locations; 207 } 208 209 public static void clearLocations() 210 { 211 locations.clear(); 212 } 213 214 public void show(String cardName) 215 { 216 ((CardLayout)screens.getLayout()).show(screens, cardName); 217 } 218 219 /** 220 * @param args the command line arguments 221 */ 222 public static void main(String args[]) { 223 String officePath = null; 224 String netbeansPath = null; 225 //String jeditPath = null; 226 int i = 0; 227 228 while (i < args.length) { 229 if (args[i].equals("-help")) { 230 printUsage(); 231 System.exit(0); 232 } 233 if (args[i].equals("-office")) 234 officePath = args[++i]; 235 if (args[i].equals("-netbeans")) 236 netbeansPath = args[++i]; 237 if (args[i].equals("-net")) 238 bNetworkInstall = true; 239 if (args[i].equals("-bindings")) 240 bBindingsInstall = true; 241 //if (args[i].equals("-jedit")) 242 // jeditPath = args[++i]; 243 i++; 244 } 245 246 //if (officePath == null && netbeansPath == null && jeditPath == null) 247 if (officePath == null && netbeansPath == null) 248 new InstallWizard().show(); 249 250 JLabel label = new JLabel(); 251 JProgressBar progressbar = new JProgressBar(); 252 253 try { 254 System.out.println("Log file is: " + 255 System.getProperty("user.dir") + 256 File.separator + "SFrameworkInstall.log"); 257 258 LogStream log = new LogStream( "SFrameworkInstall.log" ); 259 System.setErr(log); 260 System.setOut(log); 261 } 262 catch( FileNotFoundException fnfe ) { 263 System.err.println("Error: Unable to create log file: " 264 + fnfe.getMessage()); 265 System.exit(-1); 266 } 267 268 if (officePath != null) { 269 XmlUpdater xud = new XmlUpdater(officePath, label, progressbar, bNetworkInstall, bBindingsInstall ); 270 xud.run(); 271 } 272 273 if (netbeansPath != null) { 274 IdeUpdater ideup = new IdeUpdater(netbeansPath, label, progressbar); 275 ideup.run(); 276 } 277 278 //if (jeditPath != null) { 279 // IdeUpdater ideup = new IdeUpdater(jeditPath, label, progressbar); 280 // ideup.run(); 281 //} 282 } 283 284 private static void printUsage() { 285 System.err.println("java -jar SFrameworkInstall.jar"); 286 System.err.println("\t[-office <path_to_office_installation]"); 287 System.err.println("\t[-netbeans <path_to_netbeans_installation]"); 288 System.err.println("\t[-net]"); 289 System.err.println("\t[-bindings]"); 290 System.err.println("\n\n-net indicates that this is the network part of a network install."); 291 System.err.println("-bindings will only install the menu & key bindings in user/config/soffice.cfg."); 292 //System.err.println("\t[-jedit <path_to_jedit_installation]"); 293 } 294 295 public static synchronized boolean isPatchedTypes() 296 { 297 return bPatchedTypes; 298 } 299 300 public static synchronized boolean isPatchedJava() 301 { 302 return bPatchedJava; 303 } 304 305 public static synchronized boolean isPatchedRDB() 306 { 307 return bPatchedRDB; 308 } 309 310 public static synchronized boolean isInstallStarted() 311 { 312 return bInstallStarted; 313 } 314 315 public static synchronized void setPatchedTypes(boolean value) 316 { 317 bPatchedTypes = value; 318 } 319 320 public static synchronized void setPatchedJava(boolean value) 321 { 322 bPatchedJava = value; 323 } 324 325 public static synchronized void setPatchedRDB(boolean value) 326 { 327 bPatchedRDB = value; 328 } 329 330 public static synchronized void setInstallStarted(boolean value) 331 { 332 bInstallStarted = value; 333 } 334 335 public static synchronized void setTypesPath(String path) 336 { 337 typesPath = path; 338 } 339 340 public static synchronized void setJavaPath(String path) 341 { 342 javaPath = path; 343 } 344 345 public static synchronized String getTypesPath() 346 { 347 return typesPath; 348 } 349 350 public static synchronized String getJavaPath() 351 { 352 return javaPath; 353 } 354 355 private javax.swing.JPanel navigation; 356 private javax.swing.JButton navBack; 357 private javax.swing.JButton navNext; 358 private javax.swing.JButton navCancel; 359 private javax.swing.JPanel screens; 360 361 private Version version = null; 362 private Final _final = null; 363 private IdeVersion ideversion = null; 364 private IdeFinal idefinal = null; 365 private IdeWelcome idewelcome = null; 366 private static ArrayList locations = null; 367 368 public static String VERSIONS = "VERSIONS"; 369 public static String WELCOME = "WELCOME"; 370 public static String FINAL = "FINAL"; 371 public static String IDEVERSIONS = "IDEVERSIONS"; 372 public static String IDEWELCOME = "IDEWELCOME"; 373 public static String IDEFINAL = "IDEFINAL"; 374 375 public static int DEFWIDTH = 480; 376 public static int DEFHEIGHT = 240; 377 378 private static String typesPath = null; 379 private static String javaPath = null; 380 381 public static boolean bNetworkInstall = false; 382 public static boolean bBindingsInstall = false; 383 384 private static boolean bPatchedTypes = false; 385 private static boolean bPatchedJava = false; 386 private static boolean bPatchedRDB = false; 387 private static boolean bInstallStarted = false; 388 389 }// InstallWizard 390