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