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