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