xref: /AOO41X/main/scripting/workben/installer/InstUtil.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir package installer;
2*cdf0e10cSrcweir 
3*cdf0e10cSrcweir import java.net.URLDecoder;
4*cdf0e10cSrcweir import java.io.*;
5*cdf0e10cSrcweir import java.util.*;
6*cdf0e10cSrcweir import java.util.zip.*;
7*cdf0e10cSrcweir import java.awt.*;
8*cdf0e10cSrcweir import java.awt.event.*;
9*cdf0e10cSrcweir import javax.swing.*;
10*cdf0e10cSrcweir import java.net.*;
11*cdf0e10cSrcweir 
12*cdf0e10cSrcweir public class InstUtil {
13*cdf0e10cSrcweir 
14*cdf0e10cSrcweir     public static File buildSversionLocation() throws IOException {
15*cdf0e10cSrcweir 		File theFile = null;
16*cdf0e10cSrcweir         StringBuffer str = new StringBuffer();
17*cdf0e10cSrcweir         str.append(System.getProperty("user.home"));
18*cdf0e10cSrcweir         str.append(File.separator);
19*cdf0e10cSrcweir 		StringBuffer thePath = new StringBuffer(str.toString());
20*cdf0e10cSrcweir 
21*cdf0e10cSrcweir         String os = System.getProperty("os.name");
22*cdf0e10cSrcweir 
23*cdf0e10cSrcweir 		if (os.indexOf("Windows") != -1) {
24*cdf0e10cSrcweir 			boolean bSVersionInHomeDir = new File(thePath.toString() + "sversion.ini").exists();
25*cdf0e10cSrcweir 
26*cdf0e10cSrcweir 			if (!bSVersionInHomeDir) {
27*cdf0e10cSrcweir 				thePath.append("Application Data");
28*cdf0e10cSrcweir 				thePath.append(File.separator);
29*cdf0e10cSrcweir 			}
30*cdf0e10cSrcweir 			theFile = findVersionFile(new File(thePath.toString()));
31*cdf0e10cSrcweir         } else if (os.indexOf("SunOS") != -1) {
32*cdf0e10cSrcweir             thePath.append(".sversionrc");
33*cdf0e10cSrcweir 			theFile = new File(thePath.toString());
34*cdf0e10cSrcweir         } else if (os.indexOf("Linux") != -1) {
35*cdf0e10cSrcweir             thePath.append(".sversionrc");
36*cdf0e10cSrcweir 			theFile = new File(thePath.toString());
37*cdf0e10cSrcweir 		}
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 		if (theFile == null)
40*cdf0e10cSrcweir 		{
41*cdf0e10cSrcweir 			throw new IOException("Could not locate the OpenOffice settings file.\nAre you sure StarOffice is installed on your system?");
42*cdf0e10cSrcweir 		}
43*cdf0e10cSrcweir 		if  (!theFile.exists())
44*cdf0e10cSrcweir 		{
45*cdf0e10cSrcweir 			throw new IOException("Could not locate the OpenOffice settings file.\nAre you sure StarOffice is installed on your system?");
46*cdf0e10cSrcweir 		}
47*cdf0e10cSrcweir         return theFile;
48*cdf0e10cSrcweir     }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     public static boolean hasNetbeansInstallation() {
53*cdf0e10cSrcweir         boolean result = false;
54*cdf0e10cSrcweir         try
55*cdf0e10cSrcweir         {
56*cdf0e10cSrcweir             result = checkForSupportedVersion( getNetbeansLocation(), versions );
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir             if (result == false)
59*cdf0e10cSrcweir                 System.out.println("No supported version of NetBeans found.");
60*cdf0e10cSrcweir         }
61*cdf0e10cSrcweir         catch ( IOException ioe )
62*cdf0e10cSrcweir         {
63*cdf0e10cSrcweir             System.err.println("Exception caught trying to determine netbeans installation: " + ioe );
64*cdf0e10cSrcweir             ioe.printStackTrace();
65*cdf0e10cSrcweir             result = false;
66*cdf0e10cSrcweir         }
67*cdf0e10cSrcweir         return result;
68*cdf0e10cSrcweir     }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     private static boolean checkForSupportedVersion( Properties installs, String[] supportedVersions )
71*cdf0e10cSrcweir     {
72*cdf0e10cSrcweir         if ( installs != null )
73*cdf0e10cSrcweir         {
74*cdf0e10cSrcweir             for ( int index = 0; index < supportedVersions.length; index++ )
75*cdf0e10cSrcweir             {
76*cdf0e10cSrcweir                 String key = supportedVersions[ index ];
77*cdf0e10cSrcweir                 String path = null;
78*cdf0e10cSrcweir                 if ( ( path = installs.getProperty(key) ) != null )
79*cdf0e10cSrcweir                 {
80*cdf0e10cSrcweir                     // at least one supported version for netbeans present, so return;
81*cdf0e10cSrcweir                     return true;
82*cdf0e10cSrcweir                 }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir             }
85*cdf0e10cSrcweir         }
86*cdf0e10cSrcweir         return false;
87*cdf0e10cSrcweir     }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     public static boolean hasJeditInstallation() {
91*cdf0e10cSrcweir         boolean result = false;
92*cdf0e10cSrcweir         try
93*cdf0e10cSrcweir         {
94*cdf0e10cSrcweir             result = checkForSupportedVersion( getJeditLocation(), versions );
95*cdf0e10cSrcweir             if ( !result )
96*cdf0e10cSrcweir             {
97*cdf0e10cSrcweir                 System.out.println("No supported version for JEdit found.");
98*cdf0e10cSrcweir             }
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir         catch ( IOException ioe )
101*cdf0e10cSrcweir         {
102*cdf0e10cSrcweir             System.err.println("Exception caught trying to determine jedit installation: " + ioe );
103*cdf0e10cSrcweir             ioe.printStackTrace();
104*cdf0e10cSrcweir             result = false;
105*cdf0e10cSrcweir         }
106*cdf0e10cSrcweir         return result;
107*cdf0e10cSrcweir     }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     public static Properties getNetbeansLocation() throws IOException {
112*cdf0e10cSrcweir 	File theFile = null;
113*cdf0e10cSrcweir 	Properties results = new Properties();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	StringBuffer str = new StringBuffer();
116*cdf0e10cSrcweir         str.append(System.getProperty("user.home"));
117*cdf0e10cSrcweir         str.append(File.separator);
118*cdf0e10cSrcweir 	StringBuffer thePath = new StringBuffer(str.toString());
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         String os = System.getProperty("os.name");
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	if (os.indexOf("Windows") != -1) {
123*cdf0e10cSrcweir 		//theFile = findVersionFile(new File(str.toString()));
124*cdf0e10cSrcweir 		thePath.append(".netbeans");
125*cdf0e10cSrcweir 		//theFile = new File(thePath.toString());
126*cdf0e10cSrcweir         } else if (os.indexOf("SunOS") != -1) {
127*cdf0e10cSrcweir 		thePath.append(".netbeans");
128*cdf0e10cSrcweir 		//theFile = new File(thePath.toString());
129*cdf0e10cSrcweir         } else if (os.indexOf("Linux") != -1) {
130*cdf0e10cSrcweir 		thePath.append(".netbeans");
131*cdf0e10cSrcweir 		//theFile = new File(thePath.toString());
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	if ( thePath.toString().indexOf( ".netbeans" ) == -1 )
135*cdf0e10cSrcweir 		return null;
136*cdf0e10cSrcweir 	else if ( new File( thePath.append( File.separator+"3.4"+File.separator ).toString() ).isDirectory() ) {
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 		System.out.println( "Found NetBeans 3.4 user directory: " + thePath );
139*cdf0e10cSrcweir 		File netbeansLogFile = new File( thePath.toString() + File.separator + "system" + File.separator + "ide.log" );
140*cdf0e10cSrcweir 		if( netbeansLogFile.exists() ) {
141*cdf0e10cSrcweir 			String installPath = getNetbeansInstallation( netbeansLogFile );
142*cdf0e10cSrcweir 			File f = new File(installPath);
143*cdf0e10cSrcweir 			results.put("NetBeans 3.4", f.getPath()+File.separator);
144*cdf0e10cSrcweir 			System.out.println( "NetBeans Installation directory: " + f.getPath());
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 		else {
147*cdf0e10cSrcweir 			System.out.println( "No NetBeans log file found" );
148*cdf0e10cSrcweir                         return null;
149*cdf0e10cSrcweir 		}
150*cdf0e10cSrcweir 	}
151*cdf0e10cSrcweir         else
152*cdf0e10cSrcweir         {
153*cdf0e10cSrcweir 	    System.out.println( "No NetBeans user directory found" );
154*cdf0e10cSrcweir 	    return null;
155*cdf0e10cSrcweir         }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	return results;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     public static Properties getJeditLocation() throws IOException {
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	/*if( !hasJeditInstallation() ) {
166*cdf0e10cSrcweir 		System.out.println( "No Jedit found (line195 InstUtil");
167*cdf0e10cSrcweir 		return null;
168*cdf0e10cSrcweir 	}*/
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	File theFile = null;
171*cdf0e10cSrcweir 	Properties results = new Properties();
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	StringBuffer str = new StringBuffer();
174*cdf0e10cSrcweir         str.append(System.getProperty("user.home"));
175*cdf0e10cSrcweir         str.append(File.separator);
176*cdf0e10cSrcweir 	StringBuffer thePath = new StringBuffer(str.toString());
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         String os = System.getProperty("os.name");
179*cdf0e10cSrcweir         thePath.append(".jedit");
180*cdf0e10cSrcweir 	//System.out.println( ".jedit path " + thePath );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	File jeditLogFile = new File( thePath.toString() + File.separator + "activity.log" );
183*cdf0e10cSrcweir 	if( jeditLogFile.exists() ) {
184*cdf0e10cSrcweir 		String[] jeditDetails = getJeditInstallation( jeditLogFile );
185*cdf0e10cSrcweir 		System.out.println( "getJeditLocation ) " + jeditDetails[0] );
186*cdf0e10cSrcweir 		File f = new File(jeditDetails[0]);
187*cdf0e10cSrcweir 		results.put("jEdit "+jeditDetails[1], jeditDetails[0]);
188*cdf0e10cSrcweir 		System.out.println( "jeditDetails[0] is " + jeditDetails[0]);
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 	else {
191*cdf0e10cSrcweir 		System.out.println( "Prompt user for Jedit installation path" );
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	return results;
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     private static String getNetbeansInstallation( File logFile ) {
203*cdf0e10cSrcweir 	    String installPath = "";
204*cdf0e10cSrcweir 	    try {
205*cdf0e10cSrcweir 	    BufferedReader reader = new BufferedReader(new FileReader(logFile));
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	    for (String s = reader.readLine(); s != null; s = reader.readLine()) {
208*cdf0e10cSrcweir 		s.trim();
209*cdf0e10cSrcweir 		if( s.indexOf( "IDE Install" ) != -1 ) {
210*cdf0e10cSrcweir 			int pathStart = s.indexOf( "=" ) + 2;
211*cdf0e10cSrcweir 			//System.out.println( "pathStart " + pathStart );
212*cdf0e10cSrcweir 			installPath = s.substring( pathStart, s.length() );
213*cdf0e10cSrcweir 			//System.out.println( "installPath 1" + installPath );
214*cdf0e10cSrcweir 			int pathEnd = installPath.indexOf( ";");
215*cdf0e10cSrcweir 			//System.out.println( "pathEnd " + pathEnd );
216*cdf0e10cSrcweir 			installPath = installPath.substring( 0, pathEnd ) +File.separator;
217*cdf0e10cSrcweir 			//System.out.println( "pathStart " + pathStart );
218*cdf0e10cSrcweir 			//int pathEnd = s.indexOf( ";");
219*cdf0e10cSrcweir 			//System.out.println( "pathEnd " + pathEnd );
220*cdf0e10cSrcweir 			//System.out.println( "s is " + s + " and " + s.length() + " long" );
221*cdf0e10cSrcweir 			//installPath = s.substring( pathStart, pathEnd - 1 );
222*cdf0e10cSrcweir 			installPath.trim();
223*cdf0e10cSrcweir 			break;
224*cdf0e10cSrcweir 		}
225*cdf0e10cSrcweir 	    }
226*cdf0e10cSrcweir 	    }
227*cdf0e10cSrcweir 	    catch( IOException ioe ) {
228*cdf0e10cSrcweir 		System.out.println( "Error reading Netbeans location information" );
229*cdf0e10cSrcweir             }
230*cdf0e10cSrcweir 	    //catch( FileNotFoundException fnfe ) {
231*cdf0e10cSrcweir 		//System.out.println( "NetBeans ide.log FileNotFoundException" );
232*cdf0e10cSrcweir 	    //}
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 	    return installPath;
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     private static String[] getJeditInstallation( File logFile ) {
239*cdf0e10cSrcweir 	    String[] jeditDetails = new String[2];
240*cdf0e10cSrcweir 	    try {
241*cdf0e10cSrcweir 	    BufferedReader reader = new BufferedReader(new FileReader(logFile));
242*cdf0e10cSrcweir 	    String installPath = "";
243*cdf0e10cSrcweir 	    String version = "";
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	    for (String s = reader.readLine(); s != null; s = reader.readLine()) {
246*cdf0e10cSrcweir 		s.trim();
247*cdf0e10cSrcweir 		if( s.indexOf( "jEdit home directory is" ) != -1 ) {
248*cdf0e10cSrcweir 			int pathStart = new String( "[message] jEdit: jEdit home directory is " ).length();
249*cdf0e10cSrcweir 			//System.out.println( "pathStart " + pathStart );
250*cdf0e10cSrcweir 			installPath = s.substring( pathStart, s.length() ) +File.separator;
251*cdf0e10cSrcweir 			System.out.println( "installPath 1" + installPath );
252*cdf0e10cSrcweir 			//int pathEnd = installPath.indexOf( ";");
253*cdf0e10cSrcweir 			//System.out.println( "pathEnd " + pathEnd );
254*cdf0e10cSrcweir 			//installPath = installPath.substring( 0, pathEnd ) +File.separator;
255*cdf0e10cSrcweir 			//System.out.println( "pathStart " + pathStart );
256*cdf0e10cSrcweir 			//int pathEnd = s.indexOf( ";");
257*cdf0e10cSrcweir 			//System.out.println( "pathEnd " + pathEnd );
258*cdf0e10cSrcweir 			//System.out.println( "s is " + s + " and " + s.length() + " long" );
259*cdf0e10cSrcweir 			//installPath = s.substring( pathStart, pathEnd - 1 );
260*cdf0e10cSrcweir 			installPath.trim();
261*cdf0e10cSrcweir 			//System.out.println( "installPath 2 " + installPath );
262*cdf0e10cSrcweir 			//break;
263*cdf0e10cSrcweir 			jeditDetails[0] = installPath;
264*cdf0e10cSrcweir 		}
265*cdf0e10cSrcweir 		if( s.indexOf( "jEdit: jEdit version" ) != -1 ) {
266*cdf0e10cSrcweir 			int versionStart = s.indexOf( "version" ) + 8;
267*cdf0e10cSrcweir 			System.out.println( "versionStart is: " + versionStart );
268*cdf0e10cSrcweir 			version = s.substring( versionStart, s.length() );
269*cdf0e10cSrcweir 			version.trim();
270*cdf0e10cSrcweir 			System.out.println( "jEdit version is: " + version );
271*cdf0e10cSrcweir 			jeditDetails[1] = version;
272*cdf0e10cSrcweir 		}
273*cdf0e10cSrcweir 	    }
274*cdf0e10cSrcweir 	    }
275*cdf0e10cSrcweir 	    catch( IOException ioe ) {
276*cdf0e10cSrcweir 		System.out.println( "Error reading Jedit location information" );
277*cdf0e10cSrcweir             }
278*cdf0e10cSrcweir 	    //catch( FileNotFoundException fnfe ) {
279*cdf0e10cSrcweir 		//System.out.println( "Jedit activity.log FileNotFoundException" );
280*cdf0e10cSrcweir 	    //}
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	    return jeditDetails;
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	public static File findVersionFile(File start)
288*cdf0e10cSrcweir 	{
289*cdf0e10cSrcweir 		File versionFile = null;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 		File files[] = start.listFiles(new VersionFilter());
292*cdf0e10cSrcweir 		if (files.length == 0)
293*cdf0e10cSrcweir 		{
294*cdf0e10cSrcweir 			File dirs[] = start.listFiles(new DirFilter());
295*cdf0e10cSrcweir 			for (int i=0; i< dirs.length; i++)
296*cdf0e10cSrcweir 			{
297*cdf0e10cSrcweir 				versionFile = findVersionFile(dirs[i]);
298*cdf0e10cSrcweir 				if (versionFile != null)
299*cdf0e10cSrcweir 				{
300*cdf0e10cSrcweir 					break;
301*cdf0e10cSrcweir 				}
302*cdf0e10cSrcweir 			}
303*cdf0e10cSrcweir 		}
304*cdf0e10cSrcweir 		else
305*cdf0e10cSrcweir 		{
306*cdf0e10cSrcweir 			versionFile = files[0];
307*cdf0e10cSrcweir 		}
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 		return versionFile;
310*cdf0e10cSrcweir 	}
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     public static boolean verifySversionExists(File sversionFile) {
313*cdf0e10cSrcweir         if (!sversionFile.exists())
314*cdf0e10cSrcweir             return false;
315*cdf0e10cSrcweir         return true;
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     public static Properties getOfficeVersions(File sversionFile) throws IOException {
319*cdf0e10cSrcweir         BufferedReader reader = new BufferedReader(new FileReader(sversionFile));
320*cdf0e10cSrcweir         Vector values;
321*cdf0e10cSrcweir         String sectionName = null;
322*cdf0e10cSrcweir         Properties results = new Properties();
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         for (String s = reader.readLine(); s != null; s = reader.readLine()) {
325*cdf0e10cSrcweir             s.trim();
326*cdf0e10cSrcweir             //System.out.println(s);
327*cdf0e10cSrcweir             if (s.length() == 0)
328*cdf0e10cSrcweir                 continue;
329*cdf0e10cSrcweir             if (s.charAt(0) == '[') {
330*cdf0e10cSrcweir                 sectionName = s.substring(1, s.length() - 1);
331*cdf0e10cSrcweir                 //System.out.println(sectionName);
332*cdf0e10cSrcweir                 continue;
333*cdf0e10cSrcweir             }
334*cdf0e10cSrcweir             if ((sectionName != null) && sectionName.equalsIgnoreCase("Versions")) {
335*cdf0e10cSrcweir                 int equals = s.indexOf( "=" );
336*cdf0e10cSrcweir 		String officeName = s.substring(0, equals );
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 		String instPath = s.substring(equals + 8, s.length());
339*cdf0e10cSrcweir 		String [] parts = new String[2];
340*cdf0e10cSrcweir 		parts[0] = officeName;
341*cdf0e10cSrcweir 		parts[1] = instPath + File.separator;
342*cdf0e10cSrcweir 		//System.out.println( "InstUtil officeName " + officeName );
343*cdf0e10cSrcweir 		//System.out.println( "InstUtil instPath " + instPath );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 		//String [] parts = s.split("=");
346*cdf0e10cSrcweir                 if (parts.length == 2) {
347*cdf0e10cSrcweir                     //ver.version = parts[0].trim();
348*cdf0e10cSrcweir                     //File f = new File(parts[1].trim());
349*cdf0e10cSrcweir 		    //results.put(parts[0].trim(), f.getPath());
350*cdf0e10cSrcweir 		    try {
351*cdf0e10cSrcweir                         URL url = new URL("file://" + parts[1].trim());
352*cdf0e10cSrcweir 			String opSys =System.getProperty("os.name");
353*cdf0e10cSrcweir 			if (opSys.indexOf("Windows")!=-1){
354*cdf0e10cSrcweir 				String windowsPath = URLDecoder.decode( url.getPath() );
355*cdf0e10cSrcweir 				boolean firstSlash = true;
356*cdf0e10cSrcweir 				while( windowsPath.indexOf("/") != -1 ) {
357*cdf0e10cSrcweir 					int forwardSlashPos = windowsPath.indexOf("/");
358*cdf0e10cSrcweir 					String firstPart = windowsPath.substring( 0, forwardSlashPos );
359*cdf0e10cSrcweir 					String lastPart = windowsPath.substring( forwardSlashPos + 1, windowsPath.length() );
360*cdf0e10cSrcweir 					if( firstSlash ) {
361*cdf0e10cSrcweir 						windowsPath = lastPart;
362*cdf0e10cSrcweir 						firstSlash = false;
363*cdf0e10cSrcweir 					}
364*cdf0e10cSrcweir 					else {
365*cdf0e10cSrcweir 						windowsPath = firstPart + "\\" + lastPart;
366*cdf0e10cSrcweir 					}
367*cdf0e10cSrcweir 				}
368*cdf0e10cSrcweir 				int lastSlash = windowsPath.lastIndexOf("\\");
369*cdf0e10cSrcweir 				windowsPath = windowsPath.substring( 0, lastSlash );
370*cdf0e10cSrcweir 				results.put( parts[0].trim(), windowsPath );
371*cdf0e10cSrcweir 			}
372*cdf0e10cSrcweir 			else {
373*cdf0e10cSrcweir 				//System.err.println( " InstUtil URLDecoder " + URLDecoder.decode(url.getPath()) );
374*cdf0e10cSrcweir 				results.put(parts[0].trim(), URLDecoder.decode(url.getPath()));
375*cdf0e10cSrcweir 			}
376*cdf0e10cSrcweir                         //File f = new File(url);
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 			//.sversion: OpenOffice.org 643=file:///scriptdev/neil/ScriptFrameOpenoffice1.0.1
379*cdf0e10cSrcweir 			// parts = Installation name. f.getPath = Installation path
380*cdf0e10cSrcweir                         //results.put(parts[0].trim(), f.getPath());
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir                         //results.put(parts[0].trim(), URLDecoder.decode(url.getPath()));
383*cdf0e10cSrcweir 			//results.put( parts[0].trim(), windowsPath );
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir                     }
386*cdf0e10cSrcweir                     catch (MalformedURLException eSyntax) {
387*cdf0e10cSrcweir                         //throw new IOException("Error while reading version information");
388*cdf0e10cSrcweir 			results.put(parts[0].trim(), parts[1].trim());
389*cdf0e10cSrcweir 			//System.out.println(parts[0].trim() + " : " + parts[1].trim());
390*cdf0e10cSrcweir 			System.err.println("GotHereException");
391*cdf0e10cSrcweir                     }
392*cdf0e10cSrcweir                 }
393*cdf0e10cSrcweir                 else {
394*cdf0e10cSrcweir                     System.out.println("not splitting on equals");
395*cdf0e10cSrcweir                 }
396*cdf0e10cSrcweir             }
397*cdf0e10cSrcweir         }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir         return results;
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir     public static String getJavaVersion() {
403*cdf0e10cSrcweir         return System.getProperty("java.version");
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     public static boolean isCorrectJavaVersion() {
407*cdf0e10cSrcweir         if (System.getProperty("java.version").startsWith("1.4"))
408*cdf0e10cSrcweir             return true;
409*cdf0e10cSrcweir         return false;
410*cdf0e10cSrcweir     }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     public static void main(String args[]) {
413*cdf0e10cSrcweir         InstUtil inst = new InstUtil();
414*cdf0e10cSrcweir 		File f = null;
415*cdf0e10cSrcweir         try
416*cdf0e10cSrcweir 		{
417*cdf0e10cSrcweir 			f = inst.buildSversionLocation();
418*cdf0e10cSrcweir 		}
419*cdf0e10cSrcweir 		catch (IOException e)
420*cdf0e10cSrcweir 		{
421*cdf0e10cSrcweir 			e.printStackTrace();
422*cdf0e10cSrcweir 			System.out.println(e.getMessage());
423*cdf0e10cSrcweir 		}
424*cdf0e10cSrcweir         if (!inst.verifySversionExists(f)) {
425*cdf0e10cSrcweir             System.err.println("Problem with sversion.ini");
426*cdf0e10cSrcweir         }
427*cdf0e10cSrcweir         try {
428*cdf0e10cSrcweir             Properties vers = inst.getOfficeVersions(f);
429*cdf0e10cSrcweir         } catch (IOException e) {
430*cdf0e10cSrcweir             e.printStackTrace();
431*cdf0e10cSrcweir             System.err.println(e);
432*cdf0e10cSrcweir         }
433*cdf0e10cSrcweir         System.out.println(inst.getJavaVersion());
434*cdf0e10cSrcweir         if (!inst.isCorrectJavaVersion()) {
435*cdf0e10cSrcweir             System.err.println("Not correct Java Version");
436*cdf0e10cSrcweir         }
437*cdf0e10cSrcweir     }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     public static final String [] versions = {"NetBeans 3.4", "jEdit 4.0.3", "jEdit 4.1pre5" };
440*cdf0e10cSrcweir     private static File tmpDir = null;
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir class DirFilter implements java.io.FileFilter
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir 	public boolean accept(File aFile)
448*cdf0e10cSrcweir 	{
449*cdf0e10cSrcweir 		return aFile.isDirectory();
450*cdf0e10cSrcweir 	}
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir class VersionFilter implements java.io.FileFilter
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir 	public boolean accept(File aFile)
455*cdf0e10cSrcweir 	{
456*cdf0e10cSrcweir 		if (aFile.getName().compareToIgnoreCase("sversion.ini") == 0)
457*cdf0e10cSrcweir 		{
458*cdf0e10cSrcweir 			return true;
459*cdf0e10cSrcweir 		}
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 		return false;
462*cdf0e10cSrcweir 	}
463*cdf0e10cSrcweir }
464