summaryrefslogtreecommitdiff
path: root/scripting/workben/installer/InstallWizard.java
blob: c02f5f13b90447bd41741d566f9ca02f33e66cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package installer;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;

public class InstallWizard extends javax.swing.JFrame implements ActionListener {
/*
    private static class ShutdownHook extends Thread {
        public void run()
    {
            if (InstallWizard.isInstallStarted())
            {
                // Check for and backup any config.xml files
                // Check for and backup any StarBasic macro files
                // Check for and backup ProtocolHandler

                if (!InstallWizard.isPatchedTypes())
        {
                    File backup = new File(InstUtil.getTmpDir(), "TypeDetection.xml");
                    File destination = new File(InstallWizard.getTypesPath());
                    InstUtil.copy(backup, destination); //Restore typedetection.xml
        }
        if (!InstallWizard.isPatchedJava())
        {
                    File backup = new File(InstUtil.getTmpDir(), "Java.xml");
                    File destination = new File(InstallWizard.getJavaPath());
                    InstUtil.copy(backup, destination); //Restore typedetection.xml
        }
        if (!InstallWizard.isPatchedRDB())
        {
                    File backup = new File(InstUtil.getTmpDir(), "applicat.rdb");
                    File destination = new File(InstallWizard.getJavaPath());
                    //InstUtil.copy(backup, destination); //Restore typedetection.xml
        }

                System.out.println( "ShutdownHook" );
            }

            InstUtil.removeTmpDir();
    }
    }// class ShutdownHook

    static {
        Runtime rt=Runtime.getRuntime();
        rt.addShutdownHook(new ShutdownHook());
    }
*/
    /** Creates new form InstallWizard */
    public InstallWizard() {
        super("Office Scripting Framework Installer - Early Developer Release");

     try {
         System.out.print("All diagnostic output is being redirected to SFrameworkInstall.log\n");
         System.out.print("Location: "+  System.getProperty( "user.dir" ) +
             File.separator + "SFrameworkInstall.log\n");

         LogStream log = new LogStream( "SFrameworkInstall.log" );
                 System.setErr(log);

                 System.setOut(log);
     }
     catch( FileNotFoundException fnfe ) {
         System.err.println("Office Scripting Framework Installer - Error: ");
         System.err.println("Unable to create log file for installation.");
         exitForm();
     }

    setBackground(new Color(0,0,0));
    locations = new ArrayList<String>();
    Point center = new Point( 400, 400 );
    int windowWidth=200;
    int windowHeight=300;
    setSize(windowWidth,windowHeight);
    setBounds((center.x-windowWidth/2)-115,(center.y-windowWidth/2)-100, windowWidth,windowHeight);
    initComponents();
    setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     */
    private void initComponents() {
        navigation = new javax.swing.JPanel();
        navBack = new javax.swing.JButton();
        navNext = new javax.swing.JButton();
        navCancel = new javax.swing.JButton();
        screens = new javax.swing.JPanel();

        addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm();
            }
        });

        navigation.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;

        navBack.setText("<< Back");
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.insets = new java.awt.Insets(1, 1, 1, 1);

        navNext.setText("Next >>");
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 2;
        gridBagConstraints1.gridy = 0;

        navCancel.setText("Cancel");
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 6;
        gridBagConstraints1.gridy = 0;

        getContentPane().add(navigation, java.awt.BorderLayout.SOUTH);
        screens.setLayout(new java.awt.CardLayout());
        screens.add(WELCOME, new Welcome(this));
        version = new Version(this);
        screens.add(VERSIONS, version);
    _final = new Final(this);
        screens.add(FINAL, _final);

    boolean hasIDEInstallation = ( InstUtil.hasNetbeansInstallation() ) ;

    if( hasIDEInstallation )
    {
        idewelcome = new IdeWelcome(this);
        screens.add(IDEWELCOME, idewelcome);
        ideversion = new IdeVersion(this);
        screens.add(IDEVERSIONS, ideversion);
        idefinal = new IdeFinal(this);
        screens.add(IDEFINAL, idefinal);
    }
        getContentPane().add(screens, java.awt.BorderLayout.CENTER);

    navNext.addActionListener(this);
    navNext.addActionListener(version);
    navNext.addActionListener(_final);

    if( hasIDEInstallation )
    {
        navNext.addActionListener(ideversion);
        navNext.addActionListener(idefinal);
    }

    navCancel.addActionListener(this);
    navBack.addActionListener(this);


    URL url = this.getClass().getResource("sidebar.jpg");
    JLabel sideBar = new JLabel();
    sideBar.setIcon(new ImageIcon(url));
    getContentPane().add (sideBar, java.awt.BorderLayout.WEST);
        pack();
    }// initComponents

    /** Exit the Application */
    public void exitForm() {
        System.exit(0);
    }


    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == navNext)
    {
            ((CardLayout)screens.getLayout()).next(screens);
    }

    if (e.getSource() == navCancel)
    {
            exitForm();
    }

    if (e.getSource() == navBack)
    {
            ((CardLayout)screens.getLayout()).previous(screens);
    }
    }// actionPerformed

    public static void storeLocation(String path)
    {
        locations.add(path);
    }

    public static ArrayList<String> getLocations()
    {
        return locations;
    }

    public static void clearLocations()
    {
        locations.clear();
    }

    public void show(String cardName)
    {
        ((CardLayout)screens.getLayout()).show(screens, cardName);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        String officePath = null;
        String netbeansPath = null;
        int i = 0;

        while (i < args.length) {
            if (args[i].equals("-help")) {
                printUsage();
                System.exit(0);
            }
            if (args[i].equals("-office"))
                officePath = args[++i];
            if (args[i].equals("-netbeans"))
                netbeansPath = args[++i];
            if (args[i].equals("-net"))
                bNetworkInstall = true;
            if (args[i].equals("-bindings"))
                bBindingsInstall = true;
            i++;
        }

        if (officePath == null && netbeansPath == null)
            new InstallWizard().show();

        JLabel label = new JLabel();
        JProgressBar progressbar = new JProgressBar();

        try {
            System.out.println("Log file is: " +
                System.getProperty("user.dir") +
                File.separator + "SFrameworkInstall.log");

            LogStream log = new LogStream( "SFrameworkInstall.log" );
            System.setErr(log);
            System.setOut(log);
        }
        catch( FileNotFoundException fnfe ) {
            System.err.println("Error: Unable to create log file: "
                + fnfe.getMessage());
            System.exit(-1);
        }

        if (officePath != null) {
            XmlUpdater xud = new XmlUpdater(officePath, label, progressbar, bNetworkInstall, bBindingsInstall );
            xud.run();
        }

        if (netbeansPath != null) {
            IdeUpdater ideup = new IdeUpdater(netbeansPath, label, progressbar);
            ideup.run();
        }
    }

    private static void printUsage() {
        System.err.println("java -jar SFrameworkInstall.jar");
        System.err.println("\t[-office <path_to_office_installation]");
        System.err.println("\t[-netbeans <path_to_netbeans_installation]");
        System.err.println("\t[-net]");
        System.err.println("\t[-bindings]");
        System.err.println("\n\n-net indicates that this is the network part of a network install.");
        System.err.println("-bindings will only install the menu & key bindings in user/config/soffice.cfg.");
    }









    public static synchronized void setPatchedTypes(boolean value)
    {
        bPatchedTypes = value;
    }

    public static synchronized void setPatchedJava(boolean value)
    {
        bPatchedJava = value;
    }

    public static synchronized void setPatchedRDB(boolean value)
    {
        bPatchedRDB = value;
    }

    public static synchronized void setInstallStarted(boolean value)
    {
        bInstallStarted = value;
    }









    private javax.swing.JPanel  navigation;
    private javax.swing.JButton navBack;
    private javax.swing.JButton navNext;
    private javax.swing.JButton navCancel;
    private javax.swing.JPanel  screens;

    private Version version = null;
    private Final _final  = null;
    private IdeVersion ideversion = null;
    private IdeFinal idefinal = null;
    private IdeWelcome idewelcome = null;
    private static ArrayList<String> locations = null;

    public static String VERSIONS = "VERSIONS";
    public static String WELCOME  = "WELCOME";
    public static String FINAL    = "FINAL";
    public static String IDEVERSIONS = "IDEVERSIONS";
    public static String IDEWELCOME  = "IDEWELCOME";
    public static String IDEFINAL    = "IDEFINAL";

    public static int DEFWIDTH     = 480;
    public static int DEFHEIGHT    = 240;

    private static String typesPath = null;
    private static String javaPath  = null;

    public static boolean bNetworkInstall   = false;
    public static boolean bBindingsInstall   = false;

    private static boolean bPatchedTypes     = false;
    private static boolean bPatchedJava      = false;
    private static boolean bPatchedRDB       = false;
    private static boolean bInstallStarted   = false;

}// InstallWizard