Java file -- D:\ToCD\JavaSrc\com\cager\guids\VBProject.java
Produced by JavaCCtoHTML program
package com.cager.guids;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.*;
public class VBProject
{
private File vbp;
private File projectDir;
private ComDll outputDll;
private ComDll compatDll;
private String compatMode;
public VBProject(File vbp) throws FileNotFoundException, IOException
{
this.vbp = vbp;
this.projectDir = vbp.getParentFile();
BufferedReader br = new BufferedReader(new FileReader(vbp));
try
{
String str;
String exeName = null;
String exePath = null;
String compatExe = null;
String compatMode = null;
while ((str = br.readLine()) != null)
{
StringTokenizer tokens = new StringTokenizer(str, "=");
if (tokens.countTokens() == 2)
{
String param = tokens.nextToken().toLowerCase();
String value = remove(tokens.nextToken(), '"');
if (param.equals("exename32"))
{
exeName = value;
}
else if (param.equals("path32"))
{
exePath = value;
}
else if (param.equals("compatibleexe32"))
{
compatExe = value;
}
else if (param.equals("compatiblemode"))
{
compatMode = value;
}
}
}
if (false)
{
System.out.println("exeName " + exeName);
System.out.println("exePath " + exePath);
System.out.println("compatExe " + compatExe);
System.out.println("compatMode " + compatMode);
}
if (exeName == null || exePath == null || compatExe == null || compatMode == null)
throw new IOException("Invalid VBP file " + vbp.getCanonicalPath());
File exeDir = new File(exePath);
if (exeDir.isAbsolute())
this.outputDll = new ComDll(exeDir, exeName);
else
this.outputDll = new ComDll(new File(projectDir, exePath), exeName);
this.compatDll = new ComDll(projectDir, compatExe);
this.compatMode = compatMode;
}
catch (IOException e)
{
throw e;
}
finally
{
br.close();
}
if (true)
{
System.out.println("projectDir " + projectDir.getCanonicalFile());
System.out.println("outputDll " + outputDll.getCanonicalFile());
System.out.println("compatDll " + compatDll.getCanonicalFile());
}
}
public ComDll getOutputDll()
{
return outputDll;
}
public ComDll getCompatDll()
{
return compatDll;
}
public void compile() throws IOException
{
String[] argv = {"vb6", "/m", vbp.getAbsolutePath()};
Process p = Runtime.getRuntime().exec(argv);
while (true)
{
try
{
int ret = p.waitFor();
System.out.println("vb6 " + ret);
if (ret != 0)
throw new IOException("Could not compile " + vbp.getAbsolutePath());
break;
}
catch (InterruptedException e)
{
}
}
}
public void regenerateCompat() throws IOException
{
if (outputDll.exists())
{
outputDll.unregister();
outputDll.delete();
}
setCompatMode("1");
try
{
compile();
outputDll.unregister();
outputDll.applyGuidMap(compatDll.getGuidMap());
if (!compatDll.delete())
{
System.out.println("Could not delete compat");
}
if (!outputDll.renameTo(compatDll))
throw new IOException("Could not rename " + outputDll.getAbsoluteFile() + " to " + compatDll.getAbsoluteFile());
}
finally
{
setCompatMode("2");
}
}
public String getCompatMode()
{
return compatMode;
}
public void setCompatMode(String mode) throws IOException
{
if (mode.equals(compatMode))
return;
compatMode = mode;
File bak = new File(projectDir, vbp.getName() + ".bak");
bak.delete();
if (!vbp.renameTo(bak))
throw new IOException("Could not rename " + vbp.getAbsoluteFile() + " to " + bak.getAbsoluteFile());
BufferedReader br = new BufferedReader(new FileReader(bak));
BufferedWriter bw = new BufferedWriter(new FileWriter(vbp));
String str;
while ((str = br.readLine()) != null)
{
StringTokenizer tokens = new StringTokenizer(str, "=");
if (tokens.countTokens() == 2)
{
String param = tokens.nextToken().toLowerCase();
if (param.equals("compatiblemode"))
{
bw.write("CompatibleMode=\"" + mode + "\"");
bw.newLine();
continue;
}
}
bw.write(str);
bw.newLine();
}
br.close();
bw.close();
}
private String remove(String str, char c)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++)
if (str.charAt(i) != c)
sb.append(str.charAt(i));
return new String(sb);
}
}