1. Switch CommandLauncher from a console application to a windows application so that no windows pop up during install.
2. Handle spaces in files names.
This commit is contained in:
@@ -52,6 +52,8 @@ public class InitConfigFile
|
||||
final static int ERROR_MISSING_TEMPLATE_FILE_PARAM = -27;
|
||||
final static int ERROR_MISSING_OUTPUT_FILE_PARAM = -28;
|
||||
final static int ERROR_BAD_PROPERTY_PARAM = -29;
|
||||
final static int ERROR_UNABLE_TO_OPEN_TEMPLATE = -30;
|
||||
final static int ERROR_FILEWRITER_CREATE_FAILED = -31;
|
||||
|
||||
final static String TEMPLATE_FILE_PARAM = "template=";
|
||||
final static String OUTPUT_FILE_PARAM = "output=";
|
||||
@@ -65,21 +67,24 @@ public class InitConfigFile
|
||||
File fileTemplate;
|
||||
File fileOutput;
|
||||
File file;
|
||||
FileWriter fw;
|
||||
//FileWriter fw;
|
||||
RandomAccessFile raf;
|
||||
String[] rgsSearchFor;
|
||||
String[] rgsReplaceWith;
|
||||
String sInstallDir;
|
||||
String sTemplate;
|
||||
String sOutput;
|
||||
int rc;
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
InitConfigFile p = new InitConfigFile(args);
|
||||
System.exit(p.rc);
|
||||
}
|
||||
|
||||
InitConfigFile(String[] args)
|
||||
{
|
||||
int rc = ERROR_NO_ERROR;
|
||||
rc = ERROR_NO_ERROR;
|
||||
|
||||
properties = new Properties();
|
||||
fileProperties = null;
|
||||
@@ -90,13 +95,10 @@ public class InitConfigFile
|
||||
try
|
||||
{
|
||||
file = new File("c:\\test.log");
|
||||
fw = new FileWriter(file);
|
||||
//fw = new FileWriter(file);
|
||||
|
||||
log("Here we go: " + args.length);
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + args[i]);
|
||||
}
|
||||
raf = new RandomAccessFile(file, "rw");
|
||||
raf.seek(raf.length());
|
||||
|
||||
// Process the arguments
|
||||
if (ERROR_NO_ERROR == (rc = processArgs(args)))
|
||||
@@ -117,32 +119,55 @@ public class InitConfigFile
|
||||
{
|
||||
try
|
||||
{
|
||||
log(rc);
|
||||
fw.flush();
|
||||
fw.close();
|
||||
log(rc, " " + sOutput + "\n\n\n");
|
||||
//raf.flush();
|
||||
raf.close();
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
}
|
||||
}
|
||||
System.exit(rc);
|
||||
}
|
||||
|
||||
int processArgs(String[] args)
|
||||
int processArgs(String[] argsOld)
|
||||
{
|
||||
String sProperties;
|
||||
File fileInstallDir = null;
|
||||
int i;
|
||||
int iEquals;
|
||||
String sKey;
|
||||
String sValue;
|
||||
int iOld;
|
||||
int i;
|
||||
String args[] = new String[argsOld.length];
|
||||
int iNew;
|
||||
|
||||
log("Original arg count " + argsOld.length);
|
||||
for (i = 0; i < argsOld.length; i++)
|
||||
{
|
||||
log("Arg " + i + " = " + argsOld[i] + "\r\n");
|
||||
}
|
||||
|
||||
// Validate the number of parameters
|
||||
if (args.length < 3)
|
||||
if (argsOld.length < 2)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMS;
|
||||
}
|
||||
|
||||
iNew = -1;
|
||||
for (iOld = 0; iOld < argsOld.length; iOld++)
|
||||
{
|
||||
if (0 <= argsOld[iOld].indexOf("="))
|
||||
{
|
||||
iNew++;
|
||||
args[iNew] = argsOld[iOld];
|
||||
for (i = iOld + 1; i < argsOld.length && (-1 == argsOld[i].indexOf("=")); i++)
|
||||
{
|
||||
args[iNew] += " " + argsOld[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("New arg count " + args.length);
|
||||
for (i = 0; i < args.length; i++)
|
||||
{
|
||||
log("arg[" + i + "] = " +args[i]);
|
||||
@@ -171,6 +196,7 @@ public class InitConfigFile
|
||||
return ERROR_INSTALL_DIR_NOT_A_DIR;
|
||||
}
|
||||
|
||||
log("Adding property (key = " + INSTALL_DIR_PROPERTY + " - value = " + sInstallDir);
|
||||
properties.setProperty(INSTALL_DIR_PROPERTY, sInstallDir);
|
||||
}
|
||||
|
||||
@@ -246,6 +272,7 @@ public class InitConfigFile
|
||||
}
|
||||
sKey = args[i].substring(0, iEquals);
|
||||
sValue = args[i].substring(iEquals + 1);
|
||||
log("Adding property (key = " + sKey + " - value = " + sValue);
|
||||
properties.setProperty(sKey, sValue);
|
||||
}
|
||||
}
|
||||
@@ -287,6 +314,7 @@ public class InitConfigFile
|
||||
rgsSearchFor = new String[properties.size()];
|
||||
rgsReplaceWith = new String[properties.size()];
|
||||
|
||||
log("property count = " + properties.size());
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
sKey = (String)e.nextElement();
|
||||
@@ -323,7 +351,7 @@ public class InitConfigFile
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return -40;
|
||||
return ERROR_UNABLE_TO_OPEN_TEMPLATE;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -332,7 +360,7 @@ public class InitConfigFile
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return -41;
|
||||
return ERROR_FILEWRITER_CREATE_FAILED;
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -454,6 +482,12 @@ public class InitConfigFile
|
||||
case ERROR_UNABLE_TO_READ_PROPERTIES:
|
||||
sMessage = "Unable to read properties file";
|
||||
break;
|
||||
case ERROR_UNABLE_TO_OPEN_TEMPLATE:
|
||||
sMessage = "Unable to open template";
|
||||
break;
|
||||
case ERROR_FILEWRITER_CREATE_FAILED:
|
||||
sMessage = "FileWriter create failed";
|
||||
break;
|
||||
default:
|
||||
sMessage = "Unknown error: " + err;
|
||||
break;
|
||||
@@ -470,7 +504,7 @@ public class InitConfigFile
|
||||
{
|
||||
try
|
||||
{
|
||||
fw.write(this.getClass().getName() + ": " + s + "\r\n");
|
||||
raf.writeUTF(this.getClass().getName() + ": " + s + "\r\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user