String path2jardir, path2tracelib;
String infile_name, outfile_name, jar_path;
String option4jar;
File infile, outfile, jar_file;
InputLog slog_ins;
RuntimeExecCommand exec_cmd;
SwingProcessWorker conv_worker;
ProgressAction conv_progress;
// Check the validity of the Input File
infile_name = cmd_infile.getText();
infile = new File( infile_name );
if ( ! infile.exists() ) {
Dialogs.error( top_window,
infile_name + " does not exist!\n"
+ "No conversion will take place." );
return null;
}
if ( infile.isDirectory() ) {
Dialogs.error( top_window,
infile_name + " is a directory!\n"
+ "No conversion will take place." );
return null;
}
if ( ! infile.canRead() ) {
Dialogs.error( top_window,
"File " + infile_name + " is NOT readable!\n"
+ "No conversion will take place." );
return null;
}
slog_ins = null;
try {
slog_ins = new InputLog( infile_name );
} catch ( NullPointerException nperr ) {
slog_ins = null;
} catch ( Exception err ) {
slog_ins = null;
}
if ( slog_ins != null && slog_ins.isSLOG2() ) {
Dialogs.error( top_window,
infile_name + " is already a SLOG-2 file!\n"
+ "No conversion will take place." );
cmd_outfile.setText( infile_name );
return null;
}
// Check the validity of the Output File
outfile_name = cmd_outfile.getText();
outfile = new File( outfile_name );
if ( outfile.exists() ) {
if ( outfile.isDirectory() ) {
Dialogs.error( top_window,
outfile_name + " is a directory!\n"
+ "No conversion will take place." );
return null;
}
if ( ! outfile.canWrite() ) {
Dialogs.error( top_window,
"File " + outfile_name + " cannot be written!\n"
+ "No conversion will take place." );
return null;
}
if ( ! Dialogs.confirm( top_window,
outfile_name + " already exists! "
+ "Do you want to overwrite it ?" ) ) {
Dialogs.info( top_window,
"Please change the output filename "
+ "and restart the conversion again.",
null );
return null;
}
outfile.delete();
}
convertor = (String) cmd_pulldown.getSelectedItem();
// Set the path to the jar file
path2jardir = cmd_path2jardir.getText();
jar_path = ConvertorConst.getDefaultJarPath( path2jardir, convertor );
jar_file = new File( jar_path );
if ( ! jar_file.exists() ) {
Dialogs.error( top_window, jar_path + " does not exist!" );
return null;
}
exec_cmd = new RuntimeExecCommand();
exec_cmd.addWholeString( cmd_path2jvm.getText() );
exec_cmd.addTokenizedString( cmd_option4jvm.getText() );
path2tracelib = cmd_path2tracelib.getText();
if ( path2tracelib != null && path2tracelib.length() > 0 )
exec_cmd.addWholeString( "-Djava.library.path=" + path2tracelib );
exec_cmd.addWholeString( "-jar" );
exec_cmd.addWholeString( jar_path );
option4jar = cmd_option4jar.getText();
if ( option4jar != null && option4jar.length() > 0 )
exec_cmd.addTokenizedString( option4jar );
exec_cmd.addWholeString( "-o" );
exec_cmd.addWholeString( outfile_name );
exec_cmd.addWholeString( infile_name );
/*
Start a SwingWorker thread to execute the process:
Prepare a progress action for the JProgressBar for the SwingWorker
*/
conv_progress = new ProgressAction( cmd_outfile_size, cmd_progress );
conv_progress.initialize( infile, outfile );
conv_worker = new SwingProcessWorker( this, cmd_textarea );
conv_worker.initialize( exec_cmd.toStringArray(), conv_progress );
conv_worker.start();
return conv_worker;
}