3 import java
.net
.URLDecoder
;
6 import java
.util
.zip
.*;
8 import java
.awt
.event
.*;
12 public class InstUtil
{
14 public static File
buildSversionLocation() throws IOException
{
16 StringBuffer str
= new StringBuffer();
17 str
.append(System
.getProperty("user.home"));
18 str
.append(File
.separator
);
19 StringBuffer thePath
= new StringBuffer(str
.toString());
21 String os
= System
.getProperty("os.name");
23 if (os
.indexOf("Windows") != -1) {
24 boolean bSVersionInHomeDir
= new File(thePath
.toString() + "sversion.ini").exists();
26 if (!bSVersionInHomeDir
) {
27 thePath
.append("Application Data");
28 thePath
.append(File
.separator
);
30 theFile
= findVersionFile(new File(thePath
.toString()));
31 } else if (os
.indexOf("SunOS") != -1) {
32 thePath
.append(".sversionrc");
33 theFile
= new File(thePath
.toString());
34 } else if (os
.indexOf("Linux") != -1) {
35 thePath
.append(".sversionrc");
36 theFile
= new File(thePath
.toString());
41 throw new IOException("Could not locate the OpenOffice settings file.\nAre you sure StarOffice is installed on your system?");
43 if (!theFile
.exists())
45 throw new IOException("Could not locate the OpenOffice settings file.\nAre you sure StarOffice is installed on your system?");
52 public static boolean hasNetbeansInstallation() {
53 boolean result
= false;
56 result
= checkForSupportedVersion( getNetbeansLocation(), versions
);
59 System
.out
.println("No supported version of NetBeans found.");
61 catch ( IOException ioe
)
63 System
.err
.println("Exception caught trying to determine netbeans installation: " + ioe
);
64 ioe
.printStackTrace();
70 private static boolean checkForSupportedVersion( Properties installs
, String
[] supportedVersions
)
72 if ( installs
!= null )
74 for ( int index
= 0; index
< supportedVersions
.length
; index
++ )
76 String key
= supportedVersions
[ index
];
78 if ( ( path
= installs
.getProperty(key
) ) != null )
80 // at least one supported version for netbeans present, so return;
90 public static boolean hasJeditInstallation() {
91 boolean result
= false;
94 result
= checkForSupportedVersion( getJeditLocation(), versions
);
97 System
.out
.println("No supported version for JEdit found.");
100 catch ( IOException ioe
)
102 System
.err
.println("Exception caught trying to determine jedit installation: " + ioe
);
103 ioe
.printStackTrace();
111 public static Properties
getNetbeansLocation() throws IOException
{
113 Properties results
= new Properties();
115 StringBuffer str
= new StringBuffer();
116 str
.append(System
.getProperty("user.home"));
117 str
.append(File
.separator
);
118 StringBuffer thePath
= new StringBuffer(str
.toString());
120 String os
= System
.getProperty("os.name");
122 if (os
.indexOf("Windows") != -1) {
123 //theFile = findVersionFile(new File(str.toString()));
124 thePath
.append(".netbeans");
125 //theFile = new File(thePath.toString());
126 } else if (os
.indexOf("SunOS") != -1) {
127 thePath
.append(".netbeans");
128 //theFile = new File(thePath.toString());
129 } else if (os
.indexOf("Linux") != -1) {
130 thePath
.append(".netbeans");
131 //theFile = new File(thePath.toString());
134 if ( thePath
.toString().indexOf( ".netbeans" ) == -1 )
136 else if ( new File( thePath
.append( File
.separator
+"3.4"+File
.separator
).toString() ).isDirectory() ) {
138 System
.out
.println( "Found NetBeans 3.4 user directory: " + thePath
);
139 File netbeansLogFile
= new File( thePath
.toString() + File
.separator
+ "system" + File
.separator
+ "ide.log" );
140 if( netbeansLogFile
.exists() ) {
141 String installPath
= getNetbeansInstallation( netbeansLogFile
);
142 File f
= new File(installPath
);
143 results
.put("NetBeans 3.4", f
.getPath()+File
.separator
);
144 System
.out
.println( "NetBeans Installation directory: " + f
.getPath());
147 System
.out
.println( "No NetBeans log file found" );
153 System
.out
.println( "No NetBeans user directory found" );
163 public static Properties
getJeditLocation() throws IOException
{
165 /*if( !hasJeditInstallation() ) {
166 System.out.println( "No Jedit found (line195 InstUtil");
171 Properties results
= new Properties();
173 StringBuffer str
= new StringBuffer();
174 str
.append(System
.getProperty("user.home"));
175 str
.append(File
.separator
);
176 StringBuffer thePath
= new StringBuffer(str
.toString());
178 String os
= System
.getProperty("os.name");
179 thePath
.append(".jedit");
180 //System.out.println( ".jedit path " + thePath );
182 File jeditLogFile
= new File( thePath
.toString() + File
.separator
+ "activity.log" );
183 if( jeditLogFile
.exists() ) {
184 String
[] jeditDetails
= getJeditInstallation( jeditLogFile
);
185 System
.out
.println( "getJeditLocation ) " + jeditDetails
[0] );
186 File f
= new File(jeditDetails
[0]);
187 results
.put("jEdit "+jeditDetails
[1], jeditDetails
[0]);
188 System
.out
.println( "jeditDetails[0] is " + jeditDetails
[0]);
191 System
.out
.println( "Prompt user for Jedit installation path" );
202 private static String
getNetbeansInstallation( File logFile
) {
203 String installPath
= "";
205 BufferedReader reader
= new BufferedReader(new FileReader(logFile
));
207 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) {
209 if( s
.indexOf( "IDE Install" ) != -1 ) {
210 int pathStart
= s
.indexOf( "=" ) + 2;
211 //System.out.println( "pathStart " + pathStart );
212 installPath
= s
.substring( pathStart
, s
.length() );
213 //System.out.println( "installPath 1" + installPath );
214 int pathEnd
= installPath
.indexOf( ";");
215 //System.out.println( "pathEnd " + pathEnd );
216 installPath
= installPath
.substring( 0, pathEnd
) +File
.separator
;
217 //System.out.println( "pathStart " + pathStart );
218 //int pathEnd = s.indexOf( ";");
219 //System.out.println( "pathEnd " + pathEnd );
220 //System.out.println( "s is " + s + " and " + s.length() + " long" );
221 //installPath = s.substring( pathStart, pathEnd - 1 );
227 catch( IOException ioe
) {
228 System
.out
.println( "Error reading Netbeans location information" );
230 //catch( FileNotFoundException fnfe ) {
231 //System.out.println( "NetBeans ide.log FileNotFoundException" );
238 private static String
[] getJeditInstallation( File logFile
) {
239 String
[] jeditDetails
= new String
[2];
241 BufferedReader reader
= new BufferedReader(new FileReader(logFile
));
242 String installPath
= "";
245 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) {
247 if( s
.indexOf( "jEdit home directory is" ) != -1 ) {
248 int pathStart
= new String( "[message] jEdit: jEdit home directory is " ).length();
249 //System.out.println( "pathStart " + pathStart );
250 installPath
= s
.substring( pathStart
, s
.length() ) +File
.separator
;
251 System
.out
.println( "installPath 1" + installPath
);
252 //int pathEnd = installPath.indexOf( ";");
253 //System.out.println( "pathEnd " + pathEnd );
254 //installPath = installPath.substring( 0, pathEnd ) +File.separator;
255 //System.out.println( "pathStart " + pathStart );
256 //int pathEnd = s.indexOf( ";");
257 //System.out.println( "pathEnd " + pathEnd );
258 //System.out.println( "s is " + s + " and " + s.length() + " long" );
259 //installPath = s.substring( pathStart, pathEnd - 1 );
261 //System.out.println( "installPath 2 " + installPath );
263 jeditDetails
[0] = installPath
;
265 if( s
.indexOf( "jEdit: jEdit version" ) != -1 ) {
266 int versionStart
= s
.indexOf( "version" ) + 8;
267 System
.out
.println( "versionStart is: " + versionStart
);
268 version
= s
.substring( versionStart
, s
.length() );
270 System
.out
.println( "jEdit version is: " + version
);
271 jeditDetails
[1] = version
;
275 catch( IOException ioe
) {
276 System
.out
.println( "Error reading Jedit location information" );
278 //catch( FileNotFoundException fnfe ) {
279 //System.out.println( "Jedit activity.log FileNotFoundException" );
287 public static File
findVersionFile(File start
)
289 File versionFile
= null;
291 File files
[] = start
.listFiles(new VersionFilter());
292 if (files
.length
== 0)
294 File dirs
[] = start
.listFiles(new DirFilter());
295 for (int i
=0; i
< dirs
.length
; i
++)
297 versionFile
= findVersionFile(dirs
[i
]);
298 if (versionFile
!= null)
306 versionFile
= files
[0];
312 public static boolean verifySversionExists(File sversionFile
) {
313 if (!sversionFile
.exists())
318 public static Properties
getOfficeVersions(File sversionFile
) throws IOException
{
319 BufferedReader reader
= new BufferedReader(new FileReader(sversionFile
));
321 String sectionName
= null;
322 Properties results
= new Properties();
324 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) {
326 //System.out.println(s);
329 if (s
.charAt(0) == '[') {
330 sectionName
= s
.substring(1, s
.length() - 1);
331 //System.out.println(sectionName);
334 if ((sectionName
!= null) && sectionName
.equalsIgnoreCase("Versions")) {
335 int equals
= s
.indexOf( "=" );
336 String officeName
= s
.substring(0, equals
);
338 String instPath
= s
.substring(equals
+ 8, s
.length());
339 String
[] parts
= new String
[2];
340 parts
[0] = officeName
;
341 parts
[1] = instPath
+ File
.separator
;
342 //System.out.println( "InstUtil officeName " + officeName );
343 //System.out.println( "InstUtil instPath " + instPath );
345 //String [] parts = s.split("=");
346 if (parts
.length
== 2) {
347 //ver.version = parts[0].trim();
348 //File f = new File(parts[1].trim());
349 //results.put(parts[0].trim(), f.getPath());
351 URL url
= new URL("file://" + parts
[1].trim());
352 String opSys
=System
.getProperty("os.name");
353 if (opSys
.indexOf("Windows")!=-1){
354 String windowsPath
= URLDecoder
.decode( url
.getPath() );
355 boolean firstSlash
= true;
356 while( windowsPath
.indexOf("/") != -1 ) {
357 int forwardSlashPos
= windowsPath
.indexOf("/");
358 String firstPart
= windowsPath
.substring( 0, forwardSlashPos
);
359 String lastPart
= windowsPath
.substring( forwardSlashPos
+ 1, windowsPath
.length() );
361 windowsPath
= lastPart
;
365 windowsPath
= firstPart
+ "\\" + lastPart
;
368 int lastSlash
= windowsPath
.lastIndexOf("\\");
369 windowsPath
= windowsPath
.substring( 0, lastSlash
);
370 results
.put( parts
[0].trim(), windowsPath
);
373 //System.err.println( " InstUtil URLDecoder " + URLDecoder.decode(url.getPath()) );
374 results
.put(parts
[0].trim(), URLDecoder
.decode(url
.getPath()));
376 //File f = new File(url);
378 //.sversion: OpenOffice.org 643=file:///scriptdev/neil/ScriptFrameOpenoffice1.0.1
379 // parts = Installation name. f.getPath = Installation path
380 //results.put(parts[0].trim(), f.getPath());
382 //results.put(parts[0].trim(), URLDecoder.decode(url.getPath()));
383 //results.put( parts[0].trim(), windowsPath );
386 catch (MalformedURLException eSyntax
) {
387 //throw new IOException("Error while reading version information");
388 results
.put(parts
[0].trim(), parts
[1].trim());
389 //System.out.println(parts[0].trim() + " : " + parts[1].trim());
390 System
.err
.println("GotHereException");
394 System
.out
.println("not splitting on equals");
402 public static String
getJavaVersion() {
403 return System
.getProperty("java.version");
406 public static boolean isCorrectJavaVersion() {
407 if (System
.getProperty("java.version").startsWith("1.4"))
412 public static void main(String args
[]) {
413 InstUtil inst
= new InstUtil();
417 f
= inst
.buildSversionLocation();
419 catch (IOException e
)
422 System
.out
.println(e
.getMessage());
424 if (!inst
.verifySversionExists(f
)) {
425 System
.err
.println("Problem with sversion.ini");
428 Properties vers
= inst
.getOfficeVersions(f
);
429 } catch (IOException e
) {
431 System
.err
.println(e
);
433 System
.out
.println(inst
.getJavaVersion());
434 if (!inst
.isCorrectJavaVersion()) {
435 System
.err
.println("Not correct Java Version");
439 public static final String
[] versions
= {"NetBeans 3.4", "jEdit 4.0.3", "jEdit 4.1pre5" };
440 private static File tmpDir
= null;
445 class DirFilter
implements java
.io
.FileFilter
447 public boolean accept(File aFile
)
449 return aFile
.isDirectory();
452 class VersionFilter
implements java
.io
.FileFilter
454 public boolean accept(File aFile
)
456 if (aFile
.getName().compareToIgnoreCase("sversion.ini") == 0)