Allow extraction to a file name for the ant task

This commit is contained in:
2012-10-11 11:38:55 +00:00
parent 6526cf3e0b
commit b52df7745b
2 changed files with 26 additions and 6 deletions

View File

@ -19,7 +19,9 @@ package com.webcodepro.applecommander.ui;
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
@ -63,9 +65,14 @@ public class AntTask extends Task
} }
else if (_command.equals("e") || _command.equals("g")) else if (_command.equals("e") || _command.equals("g"))
{ {
PrintStream outfile = System.out;
try try
{ {
com.webcodepro.applecommander.ui.ac.getFile(_imageName, _fileName, _command.equals("e")); if (_output != null)
{
outfile = new PrintStream(new FileOutputStream(_output));
}
com.webcodepro.applecommander.ui.ac.getFile(_imageName, _fileName, _command.equals("e"), outfile);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -251,6 +258,11 @@ public class AntTask extends Task
_input = input; _input = input;
} }
public void setOutput(String output)
{
_output = output;
}
public void setImageName(String imageName) public void setImageName(String imageName)
{ {
_imageName = imageName; _imageName = imageName;
@ -298,6 +310,8 @@ public class AntTask extends Task
String _input = null; String _input = null;
String _output = null;
String _command = null; String _command = null;
String _imageName = null; String _imageName = null;

View File

@ -28,6 +28,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -99,11 +100,11 @@ public class ac {
} else if ("-ll".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ } else if ("-ll".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL); showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL);
} else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ } else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFile(args[1], args[2], true); getFile(args[1], args[2], true, System.out);
} else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ } else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFiles(args[1], (args.length > 2 ? args[2] : "")); getFiles(args[1], (args.length > 2 ? args[2] : ""));
} else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ } else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
getFile(args[1], args[2], false); getFile(args[1], args[2], false, System.out);
} else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$ } else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
putFile(args[1], new Name(args[2]), args[3], putFile(args[1], new Name(args[2]), args[3],
(args.length > 4 ? args[4] : "0x2000")); (args.length > 4 ? args[4] : "0x2000"));
@ -206,7 +207,10 @@ public class ac {
entry.setAddress(stringToInt(address)); entry.setAddress(stringToInt(address));
} }
formattedDisk.save(); formattedDisk.save();
} else {
throw new IOException("Unable to create entry...");
} }
} }
else else
throw new IOException(textBundle.get("CommandLineSDKReadOnly")); //$NON-NLS-1$ throw new IOException(textBundle.get("CommandLineSDKReadOnly")); //$NON-NLS-1$
@ -278,11 +282,13 @@ public class ac {
* Get the file named filename from the disk named imageName; the file is * Get the file named filename from the disk named imageName; the file is
* filtered according to its type and sent to <stdout>. * filtered according to its type and sent to <stdout>.
*/ */
static void getFile(String imageName, String fileName, boolean filter) static void getFile(String imageName, String fileName, boolean filter, PrintStream out)
throws IOException { throws IOException {
Disk disk = new Disk(imageName); Disk disk = new Disk(imageName);
Name name = new Name(fileName); Name name = new Name(fileName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks(); FormattedDisk[] formattedDisks = disk.getFormattedDisks();
if (out == null)
out = System.out;
for (int i = 0; i < formattedDisks.length; i++) { for (int i = 0; i < formattedDisks.length; i++) {
FormattedDisk formattedDisk = formattedDisks[i]; FormattedDisk formattedDisk = formattedDisks[i];
FileEntry entry = name.getEntry(formattedDisk); FileEntry entry = name.getEntry(formattedDisk);
@ -292,10 +298,10 @@ public class ac {
if (ff instanceof BinaryFileFilter) if (ff instanceof BinaryFileFilter)
ff = new HexDumpFileFilter(); ff = new HexDumpFileFilter();
byte[] buf = ff.filter(entry); byte[] buf = ff.filter(entry);
System.out.write(buf, 0, buf.length); out.write(buf, 0, buf.length);
} else { } else {
byte[] buf = entry.getFileData(); byte[] buf = entry.getFileData();
System.out.write(buf, 0, buf.length); out.write(buf, 0, buf.length);
} }
} else { } else {
System.err.println(textBundle.format( System.err.println(textBundle.format(