cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
karveajit
Level 3

What's the problem with this Wizardbean?

Hello,

I've written a WizardBean which is registered in Custom bean gallery also.
Here is the code of that Bean:

[CODE]package myWizardBeans;

import java.io.*;
import java.util.*;
import com.installshield.wizard.*;
import com.installshield.util.*;
import javax.swing.*;

public class IsMATLABInstalled extends WizardAction {

public void execute(WizardBeanEvent event){
String strMATLABpath = null;
FileOutputStream fos = null;
try
{
File file = new File("c:\\Log\\Test.txt");
fos = new FileOutputStream(file);

String retValue = getRegistryEntryUsingRegedit("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Matlab.Application\\CurVer","");
fos.write(content.getBytes(retValue));
if(retValue != null)
{
String mFileValue = getRegistryEntryUsingRegedit("HKEY_CLASSES_ROOT\\mfile","FriendlyTypeName");
fos.write(content.getBytes(mFileValue));
if(mFileValue != null)
{
int iPos = mFileValue.indexOf("bin");
if(iPos > 0)
{
strMATLABpath = mFileValue.substring(0,iPos-1);
fos.write(content.getBytes(strMATLABpath));
strMATLABpath = strMATLABpath.replaceFirst("@","");
fos.write(content.getBytes(strMATLABpath));
}

}
}
if (strMATLABpath != null) {
System.setProperty("MATLABinstalledpath", strMATLABpath);
return;
} else {
System.setProperty("MATLABinstalledpath", "NotFound");
return;
}
fos.close();
} catch(Exception e) // File read exception
{
logEvent(this,"Error reading input file",e);
return;
}
finally{
if ( fos != null )
fos.close();
}
}

private static String getTempDir()
{

String temp = null;

temp = System.getProperty("java.io.tmpdir");
if ((temp != null) && (temp.indexOf(" ") >= 0))
{
temp = null;
}

if (temp == null)
{
temp = System.getProperty("user.home") + "\\temp";
if ((temp != null) && (temp.indexOf(" ") >= 0))
{
temp = null;
}
}

if (temp == null)
{
temp = "\\temp";
}

// strip off '\' at end if necessary
if (temp.endsWith("\\"))
{
temp = temp.substring(0, temp.length()-1);
}

return temp;

}
private static String getRegistryEntryUsingRegedit(String keyBase, String key)
{

String value = null;

try
{

String keyFile = getTempDir() + "\\tcr.reg";

File file = new File(keyFile);
file.delete();

// Create command array to write registry keyBase to keyFile
String[] commandArray = new String[]
{
"regedit.exe",
"/e",
keyFile,
keyBase
};

// Run the command and wait for it
Runtime r = Runtime.getRuntime();
Process p = r.exec(commandArray);
p.waitFor();

if (file.exists())
{
// Load contents of the registry key file into a string of proper char encoding
FileInputStream fis = new FileInputStream(file);
int len = (int) file.length();
byte[] buff = new byte[len];
fis.read(buff);
fis.close();
file.delete();
String contents = null;
// The char encoding of regedit output file is os dependent
String os = System.getProperty("os.name", "");
if (os.indexOf("NT") != -1)
{
// user running NT, so use default encoding
contents = new String(buff);
}
else
{
contents = new String(buff, "UTF-16");
}


int index = contents.indexOf("[HKEY_");
if (index != -1)
{
index = contents.indexOf("]\r\n");
if (index != -1)
{
index++;
contents = contents.substring(index, contents.length());
}
}

// Load the properties from the contents string
Properties props = new Properties();
props.load(new ByteArrayInputStream(contents.getBytes()));

// Get the property value we are after
value = props.getProperty(key, "");
if (value == null || value.length() == 0)
{
key = "\"" + key + "\""; // regedit encloses keys in quotes
value = props.getProperty(key, "");
}
if (value != null && value.length() > 0)
{
// remove enclosing quotes
value = value.substring(1, value.length()-1);
}
}

}
catch (Exception e)
{
// problem loading properties
e.printStackTrace();
}

return value;
}

}[/CODE]

After few manipulations, I'm setting a System property, MATLABinstalledpath, which i'm using in Copy file bean like this:
$J(MATLABinstalledpath)

But, the files are not getting copied at that location. Also, I'm writing log stmt in the wizard bean to check whether all the variables are getting set properly but that file is also not getting created.

Can anyone please let me know how to use Wizardbean? What I am missing?

Thanks,
Ajit
Labels (1)
0 Kudos
(1) Reply
RobertDickau
Flexera Alumni

Dividing it into smaller parts, can you read the registry with a Windows Get Registry Value action, and parse that string in a simpler custom bean (instead of having to worry about an intermediate file)?
0 Kudos