summaryrefslogtreecommitdiff
path: root/scripting/workben/installer/Register.java
blob: afe95f5d1de6d8e0e024e471de50a13de3ac1946 (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
/*
 * 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 java.io.*;
import javax.swing.*;
public class Register {


    public static boolean register(String path, JLabel statusLabel) {
        String[] packages = {"ooscriptframe.zip", "bshruntime.zip", "jsruntime.zip"};

        try {
            boolean goodResult = false;
            String env[] = new String[1];
            ExecCmd command = new ExecCmd();
            boolean isWindows =
                (System.getProperty("os.name").indexOf("Windows") != -1);

            String progpath = path.concat("program" + File.separator);

            statusLabel.setText("Registering Scripting Framework...");

            // pkgchk Scripting Framework Components
            statusLabel.setText("Registering Scripting Framework Components...");
            System.out.println("Registering Scripting Framework Components...");

            for (int i = 0; i < packages.length; i++) {
                String cmd = "";

                if (!isWindows) {
                    env[0] = "LD_LIBRARY_PATH=" + progpath;

                    goodResult = command.exec("chmod a+x " + progpath + "pkgchk", null);

                    if (goodResult) {
                        cmd = progpath + "pkgchk -s -f " + progpath + packages[i];

                        System.err.println(cmd);
                        goodResult = command.exec(cmd, env);
                    }
                } else {
                    cmd = "\"" + progpath + "pkgchk.exe\" -s -f \"" + progpath +
                          packages[i] + "\"";

                    System.err.println(cmd);
                    goodResult = command.exec(cmd, null);

                }

                if (!goodResult) {
                    System.err.println("\nPkgChk Failed");

                    if (!isWindows)
                        System.err.println("Command: " + cmd + "\n" + env[0]);
                    else
                        System.err.println("Command: \"" + cmd + "\"");

                    statusLabel.setText(
                        "PkgChk Failed, please view SFrameworkInstall.log");

                    return false;
                }
            }

            // updating StarBasic libraries
            statusLabel.setText("Updating StarBasic libraries...");

            if (!FileUpdater.updateScriptXLC(path, statusLabel)) {
                statusLabel.setText("Updating user/basic/script.xlc failed, please view SFrameworkInstall.log");
                return false;
            }

            if (!FileUpdater.updateDialogXLC(path, statusLabel)) {
                statusLabel.setText("Updating user/basic/dialog.xlc failed, please view SFrameworkInstall.log");
                return false;
            }

        } catch (Exception e) {
            String message =
                "\nError installing scripting package, please view SFrameworkInstall.log.";
            System.out.println(message);
            e.printStackTrace();
            statusLabel.setText(message);
            return false;
        }

        return true;
    }// register

}//Register