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