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 import java.lang.String;
25cdf0e10cSrcweir import java.io.*;
26cdf0e10cSrcweir import javax.swing.*;
27cdf0e10cSrcweir public class Register{
28cdf0e10cSrcweir     private static String[] singletonDefParams = { "drafts.com.sun.star.script.framework.theScriptRuntimeForJava=drafts.com.sun.star.script.framework.ScriptRuntimeForJava",
29cdf0e10cSrcweir                                            "drafts.com.sun.star.script.framework.storage.theScriptStorageManager=drafts.com.sun.star.script.framework.storage.ScriptStorageManager",
30cdf0e10cSrcweir                                            "drafts.com.sun.star.script.framework.theScriptRuntimeManager=drafts.com.sun.star.script.framework.ScriptRuntimeManager"};
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
quotedString( String stringToQuote )33cdf0e10cSrcweir     private static String quotedString ( String stringToQuote ) {
34cdf0e10cSrcweir             String doubleQuote = "\"";
35cdf0e10cSrcweir 	    String result = new String ( doubleQuote + stringToQuote + doubleQuote );
36cdf0e10cSrcweir 	    return result;
37cdf0e10cSrcweir     }
regSingletons( String path, String progPath, String opSys, JLabel statusLabel )38cdf0e10cSrcweir     private static boolean regSingletons( String path, String progPath, String opSys, JLabel statusLabel ) {
39cdf0e10cSrcweir         try{
40cdf0e10cSrcweir             boolean goodResult = false;
41cdf0e10cSrcweir             String[] env = new String[1];
42cdf0e10cSrcweir             String regCmd = null;
43cdf0e10cSrcweir             ExecCmd command = new ExecCmd();
44cdf0e10cSrcweir             for ( int i=0; i<singletonDefParams.length; i++){
45cdf0e10cSrcweir                 if ( opSys.indexOf( "Windows" ) == -1 ){
46cdf0e10cSrcweir 	            // Not windows
47cdf0e10cSrcweir                     env[0] = "LD_LIBRARY_PATH=" + progPath;
48cdf0e10cSrcweir                     command.exec( "chmod a+x " + progPath + "regsingleton", null );
49cdf0e10cSrcweir                     regCmd = progPath + "regsingleton " + path + "user" + File.separator + "uno_packages" + File.separator + "cache" + File.separator + "services.rdb " + singletonDefParams[i];
50cdf0e10cSrcweir                     goodResult = command.exec( regCmd, env );
51cdf0e10cSrcweir                 }
52cdf0e10cSrcweir                 else {
53cdf0e10cSrcweir 		    // Windows
54cdf0e10cSrcweir                     regCmd = quotedString( progPath + "regsingleton.exe" ) + " " + quotedString( path + "user" + File.separator + "uno_packages" + File.separator + "cache" + File.separator + "services.rdb" ) + " " + quotedString( singletonDefParams[i] );
55cdf0e10cSrcweir                     goodResult = command.exec( regCmd,null );
56cdf0e10cSrcweir                 }
57cdf0e10cSrcweir                 if ( !goodResult ){
58cdf0e10cSrcweir                     System.out.println("Regsingleton cmd failed, cmd: " + regCmd );
59cdf0e10cSrcweir                     statusLabel.setText("Regsingleton ScriptRuntimeForJava Failed, please view SFrameworkInstall.log");
60cdf0e10cSrcweir                     return false;
61cdf0e10cSrcweir 		}
62cdf0e10cSrcweir 	    }
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir         catch ( Exception e ) {
65cdf0e10cSrcweir             String message = "\nError installing scripting package, please view SFrameworkInstall.log.";
66cdf0e10cSrcweir             System.out.println(message);
67cdf0e10cSrcweir             e.printStackTrace();
68cdf0e10cSrcweir             statusLabel.setText(message);
69cdf0e10cSrcweir             return false;
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir         return true;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     }
register(String path, JLabel statusLabel)75cdf0e10cSrcweir     public static boolean register(String path, JLabel statusLabel) {
76cdf0e10cSrcweir         String[] packages = {"ooscriptframe.zip", "bshruntime.zip", "jsruntime.zip"};
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	try {
79cdf0e10cSrcweir 	    String s=null;
80cdf0e10cSrcweir 	    boolean goodResult = false;
81cdf0e10cSrcweir 	    String env[] = new String[1];
82cdf0e10cSrcweir             ExecCmd command = new ExecCmd();
83cdf0e10cSrcweir 	    boolean isWindows =
84cdf0e10cSrcweir                 (System.getProperty("os.name").indexOf("Windows") != -1);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	    String progpath = path.concat("program" + File.separator);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             statusLabel.setText("Registering Scripting Framework...");
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             // pkgchk Scripting Framework Components
91cdf0e10cSrcweir             statusLabel.setText("Registering Scripting Framework Components...");
92cdf0e10cSrcweir 	    System.out.println("Registering Scripting Framework Components...");
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             for (int i = 0; i < packages.length; i++) {
95cdf0e10cSrcweir                 String cmd = "";
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	        if (!isWindows) {
98cdf0e10cSrcweir 		    env[0]="LD_LIBRARY_PATH=" + progpath;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 		    goodResult = command.exec("chmod a+x " + progpath + "pkgchk", null );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		    if ( goodResult ){
103cdf0e10cSrcweir                         cmd = progpath + "pkgchk -s -f " + progpath + packages[i];
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		        System.err.println(cmd);
106cdf0e10cSrcweir                         goodResult = command.exec(cmd, env);
107cdf0e10cSrcweir                     }
108cdf0e10cSrcweir                 }
109cdf0e10cSrcweir 	        else {
110cdf0e10cSrcweir                     cmd = "\"" + progpath + "pkgchk.exe\" -s -f \"" + progpath +
111cdf0e10cSrcweir                         packages[i] + "\"";
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		    System.err.println(cmd);
114cdf0e10cSrcweir                     goodResult =command.exec(cmd,null);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	        }
117cdf0e10cSrcweir                 if (!goodResult) {
118cdf0e10cSrcweir                     System.err.println("\nPkgChk Failed");
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		    if(!isWindows)
121cdf0e10cSrcweir 		        System.err.println("Command: " + cmd + "\n" + env[0]);
122cdf0e10cSrcweir 		    else
123cdf0e10cSrcweir 			System.err.println("Command: \"" + cmd + "\"");
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		    statusLabel.setText(
126cdf0e10cSrcweir                         "PkgChk Failed, please view SFrameworkInstall.log");
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		    return false;
129cdf0e10cSrcweir                 }
130cdf0e10cSrcweir 	    }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             // if ( !regSingletons( path, progpath, opSys, statusLabel ) )
133cdf0e10cSrcweir 	    // {
134cdf0e10cSrcweir             //     return false;
135cdf0e10cSrcweir             // }
136cdf0e10cSrcweir             // updating ProtocolHandler
137cdf0e10cSrcweir             /* statusLabel.setText("Updating ProtocolHandler...");
138cdf0e10cSrcweir             if(!FileUpdater.updateProtocolHandler(path, statusLabel)) {
139cdf0e10cSrcweir 		    statusLabel.setText("Updating ProtocolHandler failed, please view SFrameworkInstall.log");
140cdf0e10cSrcweir 		    return false;
141cdf0e10cSrcweir 	    } */
142cdf0e10cSrcweir 
143cdf0e10cSrcweir             // updating StarBasic libraries
144cdf0e10cSrcweir             statusLabel.setText("Updating StarBasic libraries...");
145cdf0e10cSrcweir             if(!FileUpdater.updateScriptXLC(path, statusLabel)) {
146cdf0e10cSrcweir 		    statusLabel.setText("Updating user/basic/script.xlc failed, please view SFrameworkInstall.log");
147cdf0e10cSrcweir 		    return false;
148cdf0e10cSrcweir 	    }
149cdf0e10cSrcweir             if(!FileUpdater.updateDialogXLC(path, statusLabel)) {
150cdf0e10cSrcweir 		    statusLabel.setText("Updating user/basic/dialog.xlc failed, please view SFrameworkInstall.log");
151cdf0e10cSrcweir 		    return false;
152cdf0e10cSrcweir 	    }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	catch(Exception e){
156cdf0e10cSrcweir 		String message = "\nError installing scripting package, please view SFrameworkInstall.log.";
157cdf0e10cSrcweir 		System.out.println(message);
158cdf0e10cSrcweir 		e.printStackTrace();
159cdf0e10cSrcweir 		statusLabel.setText(message);
160cdf0e10cSrcweir 		return false;
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 	return true;
163cdf0e10cSrcweir     }// register
164cdf0e10cSrcweir 
165cdf0e10cSrcweir }//Register
166