2003-12-12 04:21:32 +00:00
|
|
|
/*
|
|
|
|
* ac - an AppleCommander command line utility
|
|
|
|
* Copyright (C) 2002 by Robert Greene
|
|
|
|
* robgreene at users.sourceforge.net
|
2009-09-03 17:33:33 +00:00
|
|
|
* Copyright (C) 2003, 2004 by John B. Matthews
|
2008-05-16 21:23:19 +00:00
|
|
|
* matthewsj at users.sourceforge.net
|
2003-12-12 04:21:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
package com.webcodepro.applecommander.ui;
|
|
|
|
|
2006-04-16 03:28:36 +00:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2008-12-20 03:31:54 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
2004-06-09 03:58:00 +00:00
|
|
|
import java.io.IOException;
|
2008-12-20 03:31:54 +00:00
|
|
|
import java.io.OutputStream;
|
2006-04-16 03:28:36 +00:00
|
|
|
import java.util.Iterator;
|
2004-06-09 03:58:00 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
import com.webcodepro.applecommander.storage.DirectoryEntry;
|
|
|
|
import com.webcodepro.applecommander.storage.Disk;
|
|
|
|
import com.webcodepro.applecommander.storage.DiskFullException;
|
|
|
|
import com.webcodepro.applecommander.storage.FileEntry;
|
|
|
|
import com.webcodepro.applecommander.storage.FileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.FormattedDisk;
|
2006-04-16 03:28:36 +00:00
|
|
|
import com.webcodepro.applecommander.storage.FormattedDisk.DiskInformation;
|
2008-06-05 21:02:29 +00:00
|
|
|
import com.webcodepro.applecommander.storage.filters.BinaryFileFilter;
|
|
|
|
import com.webcodepro.applecommander.storage.filters.HexDumpFileFilter;
|
2006-04-16 03:28:36 +00:00
|
|
|
import com.webcodepro.applecommander.storage.os.dos33.DosFormatDisk;
|
|
|
|
import com.webcodepro.applecommander.storage.os.pascal.PascalFormatDisk;
|
2004-06-09 03:58:00 +00:00
|
|
|
import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk;
|
2003-12-26 21:40:10 +00:00
|
|
|
import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout;
|
2006-04-16 03:28:36 +00:00
|
|
|
import com.webcodepro.applecommander.storage.physical.DosOrder;
|
2003-12-26 21:40:10 +00:00
|
|
|
import com.webcodepro.applecommander.storage.physical.ImageOrder;
|
|
|
|
import com.webcodepro.applecommander.storage.physical.ProdosOrder;
|
2008-05-18 18:58:13 +00:00
|
|
|
import com.webcodepro.applecommander.util.AppleUtil;
|
2004-07-11 15:07:56 +00:00
|
|
|
import com.webcodepro.applecommander.util.TextBundle;
|
2003-12-12 04:21:32 +00:00
|
|
|
|
2008-05-27 04:07:59 +00:00
|
|
|
/**
|
2008-06-08 21:40:06 +00:00
|
|
|
* ac provides a command line interface to key AppleCommander functions. Text
|
|
|
|
* similar to this is produced in response to the -h option.
|
|
|
|
*
|
2008-05-27 04:07:59 +00:00
|
|
|
* <pre>
|
2008-06-07 00:17:52 +00:00
|
|
|
* CommandLineHelp = AppleCommander command line options [{0}]:
|
2008-06-08 21:40:06 +00:00
|
|
|
* -i <imagename> [<imagename>] display information about image(s).
|
|
|
|
* -ls <imagename> [<imagename>] list brief directory of image(s).
|
|
|
|
* -l <imagename> [<imagename>] list directory of image(s).
|
|
|
|
* -ll <imagename> [<imagename>] list detailed directory of image(s).
|
|
|
|
* -e <imagename> <filename> export file from image to stdout.
|
2008-12-20 10:52:31 +00:00
|
|
|
* -x <imagename> [<directory>] extract all files from image to directory.
|
2008-06-08 21:40:06 +00:00
|
|
|
* -g <imagename> <filename> get raw file from image to stdout.
|
|
|
|
* -p <imagename> <filename> <type> [[$|0x]<addr>] put stdin
|
2008-06-07 00:17:52 +00:00
|
|
|
* in filename on image, using file type and address [0x2000].
|
2008-06-08 21:40:06 +00:00
|
|
|
* -d <imagename> <filename> delete file from image.
|
|
|
|
* -k <imagename> <filename> lock file on image.
|
|
|
|
* -u <imagename> <filename> unlock file on image.
|
|
|
|
* -n <imagename> <volname> change volume name (ProDOS or Pascal).
|
|
|
|
* -cc65 <imagename> <filename> <type> put stdin with cc65 header
|
2008-06-07 00:17:52 +00:00
|
|
|
* in filename on image, using file type and address from header.
|
2012-04-17 02:11:39 +00:00
|
|
|
* -geos <imagename> interpret stdin as a ProDOS GEOS transfer file and place on image.
|
2008-06-08 21:40:06 +00:00
|
|
|
* -dos140 <imagename> create a 140K DOS 3.3 image.
|
|
|
|
* -pro140 <imagename> <volname> create a 140K ProDOS image.
|
|
|
|
* -pro800 <imagename> <volname> create an 800K ProDOS image.
|
|
|
|
* -pas140 <imagename> <volname> create a 140K Pascal image.
|
|
|
|
* -pas800 <imagename> <volname> create an 800K Pascal image.
|
2008-05-27 04:07:59 +00:00
|
|
|
* </pre>
|
2008-06-08 21:40:06 +00:00
|
|
|
*
|
2008-05-27 04:07:59 +00:00
|
|
|
* @author John B. Matthews
|
|
|
|
*/
|
2003-12-12 04:21:32 +00:00
|
|
|
public class ac {
|
2004-07-11 15:07:56 +00:00
|
|
|
private static TextBundle textBundle = UiBundle.getInstance();
|
2003-12-12 04:21:32 +00:00
|
|
|
|
2004-07-04 03:34:35 +00:00
|
|
|
public static void main(String[] args) {
|
2003-12-12 04:21:32 +00:00
|
|
|
try {
|
|
|
|
if (args.length == 0) {
|
|
|
|
help();
|
2008-06-05 11:54:14 +00:00
|
|
|
} else if ("-i".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2008-06-07 00:17:52 +00:00
|
|
|
getDiskInfo(args);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-ls".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2008-06-07 00:17:52 +00:00
|
|
|
showDirectory(args, FormattedDisk.FILE_DISPLAY_STANDARD);
|
2008-06-08 21:40:06 +00:00
|
|
|
} else if ("-l".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2008-06-07 00:17:52 +00:00
|
|
|
showDirectory(args, FormattedDisk.FILE_DISPLAY_NATIVE);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-ll".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2008-06-07 00:17:52 +00:00
|
|
|
showDirectory(args, FormattedDisk.FILE_DISPLAY_DETAIL);
|
2004-07-04 03:34:35 +00:00
|
|
|
} else if ("-e".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
getFile(args[1], new Name(args[2]), true);
|
2008-12-20 03:31:54 +00:00
|
|
|
} else if ("-x".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
|
|
|
getFiles(args[1], (args.length > 2 ? args[2] : ""));
|
2004-07-04 03:34:35 +00:00
|
|
|
} else if ("-g".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
getFile(args[1], new Name(args[2]), false);
|
2004-07-04 03:34:35 +00:00
|
|
|
} else if ("-p".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
putFile(args[1], new Name(args[2]), args[3],
|
2008-05-19 02:43:43 +00:00
|
|
|
(args.length > 4 ? args[4] : "0x2000"));
|
2004-07-04 03:34:35 +00:00
|
|
|
} else if ("-d".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
deleteFile(args[1], new Name(args[2]));
|
2008-06-05 11:54:14 +00:00
|
|
|
} else if ("-k".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
setFileLocked(args[1], new Name(args[2]), true);
|
2008-06-05 11:54:14 +00:00
|
|
|
} else if ("-u".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
setFileLocked(args[1], new Name(args[2]), false);
|
2008-06-05 11:54:14 +00:00
|
|
|
} else if ("-n".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
|
|
|
setDiskName(args[1], args[2]);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-cc65".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2009-09-05 03:31:43 +00:00
|
|
|
putCC65(args[1], new Name(args[2]), args[3]);
|
2012-04-12 15:44:01 +00:00
|
|
|
} else if ("-geos".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
|
|
|
putGEOS(args[1]);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-dos140".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2006-04-22 04:13:01 +00:00
|
|
|
createDosDisk(args[1], Disk.APPLE_140KB_DISK);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-pas140".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2006-04-22 04:13:01 +00:00
|
|
|
createPasDisk(args[1], args[2], Disk.APPLE_140KB_DISK);
|
2008-05-21 12:14:56 +00:00
|
|
|
} else if ("-pas800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
|
|
|
createPasDisk(args[1], args[2], Disk.APPLE_800KB_DISK);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-pro140".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2006-04-22 04:13:01 +00:00
|
|
|
createProDisk(args[1], args[2], Disk.APPLE_140KB_DISK);
|
2008-05-17 13:48:58 +00:00
|
|
|
} else if ("-pro800".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
|
2006-04-22 04:13:01 +00:00
|
|
|
createProDisk(args[1], args[2], Disk.APPLE_800KB_DISK);
|
2003-12-12 04:21:32 +00:00
|
|
|
} else {
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
2008-06-08 21:40:06 +00:00
|
|
|
System.err.println(textBundle.format("CommandLineErrorMessage", //$NON-NLS-1$
|
|
|
|
ex.getLocalizedMessage()));
|
2003-12-12 04:21:32 +00:00
|
|
|
ex.printStackTrace();
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-07 00:17:52 +00:00
|
|
|
* Put <stdin> into the file named fileName on the disk named imageName;
|
2006-04-16 03:28:36 +00:00
|
|
|
* Note: only volume level supported; input size unlimited.
|
2003-12-12 04:21:32 +00:00
|
|
|
*/
|
2009-09-05 03:31:43 +00:00
|
|
|
static void putFile(String imageName, Name name, String fileType,
|
2008-06-08 21:40:06 +00:00
|
|
|
String address) throws IOException, DiskFullException {
|
|
|
|
|
2006-04-16 03:28:36 +00:00
|
|
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
|
|
|
byte[] inb = new byte[1024];
|
|
|
|
int byteCount = 0;
|
|
|
|
while ((byteCount = System.in.read(inb)) > 0) {
|
|
|
|
buf.write(inb, 0, byteCount);
|
|
|
|
}
|
2003-12-12 04:21:32 +00:00
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[0];
|
2009-09-05 15:43:21 +00:00
|
|
|
FileEntry entry = name.createEntry(formattedDisk);
|
|
|
|
if (entry != null) {
|
|
|
|
entry.setFiletype(fileType);
|
2012-03-20 18:12:51 +00:00
|
|
|
entry.setFilename(name.name);
|
2009-09-05 15:43:21 +00:00
|
|
|
entry.setFileData(buf.toByteArray());
|
|
|
|
if (entry.needsAddress()) {
|
|
|
|
entry.setAddress(stringToInt(address));
|
|
|
|
}
|
|
|
|
formattedDisk.save();
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2008-05-17 13:48:58 +00:00
|
|
|
/**
|
2008-06-07 00:17:52 +00:00
|
|
|
* Put <stdin> into the file named fileName on the disk named imageName;
|
2008-05-17 13:48:58 +00:00
|
|
|
* Assume a cc65 style four-byte header with start address in bytes 0-1.
|
|
|
|
*/
|
2009-09-05 03:31:43 +00:00
|
|
|
static void putCC65(String imageName, Name name, String fileType)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException, DiskFullException {
|
|
|
|
|
2008-05-17 13:48:58 +00:00
|
|
|
byte[] header = new byte[4];
|
2008-05-19 02:43:43 +00:00
|
|
|
if (System.in.read(header, 0, 4) == 4) {
|
|
|
|
int address = AppleUtil.getWordValue(header, 0);
|
2009-09-05 03:31:43 +00:00
|
|
|
putFile(imageName, name, fileType, Integer.toString(address));
|
2008-05-19 02:43:43 +00:00
|
|
|
}
|
2008-05-17 13:48:58 +00:00
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2012-04-12 15:44:01 +00:00
|
|
|
/**
|
|
|
|
* Interpret <stdin> as a GEOS file and place it on the disk named imageName.
|
|
|
|
* This would only make sense for a ProDOS-formatted disk.
|
|
|
|
*/
|
|
|
|
static void putGEOS(String imageName)
|
|
|
|
throws IOException, DiskFullException {
|
|
|
|
putFile(imageName, new Name("GEOS-Should Be ProDOS"), "GEO", "0"); //$NON-NLS-2$ $NON-NLS-3$
|
|
|
|
}
|
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
|
|
|
* Delete the file named fileName from the disk named imageName.
|
|
|
|
*/
|
2009-09-05 03:31:43 +00:00
|
|
|
static void deleteFile(String imageName, Name name)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
2003-12-12 04:21:32 +00:00
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
2008-06-07 00:17:52 +00:00
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
2003-12-12 04:21:32 +00:00
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
2009-09-05 15:43:21 +00:00
|
|
|
FileEntry entry = name.getEntry(formattedDisk);
|
2003-12-12 04:21:32 +00:00
|
|
|
if (entry != null) {
|
|
|
|
entry.delete();
|
|
|
|
disk.save();
|
|
|
|
} else {
|
2004-07-04 03:34:35 +00:00
|
|
|
System.err.println(textBundle.format(
|
2009-09-05 03:31:43 +00:00
|
|
|
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
2008-06-08 21:40:06 +00:00
|
|
|
* Get the file named filename from the disk named imageName; the file is
|
|
|
|
* filtered according to its type and sent to <stdout>.
|
2003-12-12 04:21:32 +00:00
|
|
|
*/
|
2009-09-05 03:31:43 +00:00
|
|
|
static void getFile(String imageName, Name name, boolean filter)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
2003-12-12 04:21:32 +00:00
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
2008-06-07 00:17:52 +00:00
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
2003-12-12 04:21:32 +00:00
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
2009-09-05 15:43:21 +00:00
|
|
|
FileEntry entry = name.getEntry(formattedDisk);
|
2003-12-12 04:21:32 +00:00
|
|
|
if (entry != null) {
|
|
|
|
if (filter) {
|
|
|
|
FileFilter ff = entry.getSuggestedFilter();
|
2008-06-05 21:02:29 +00:00
|
|
|
if (ff instanceof BinaryFileFilter)
|
|
|
|
ff = new HexDumpFileFilter();
|
2003-12-12 04:21:32 +00:00
|
|
|
byte[] buf = ff.filter(entry);
|
|
|
|
System.out.write(buf, 0, buf.length);
|
|
|
|
} else {
|
|
|
|
byte[] buf = entry.getFileData();
|
|
|
|
System.out.write(buf, 0, buf.length);
|
|
|
|
}
|
|
|
|
} else {
|
2004-07-04 03:34:35 +00:00
|
|
|
System.err.println(textBundle.format(
|
2009-09-05 03:31:43 +00:00
|
|
|
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2008-12-20 03:31:54 +00:00
|
|
|
/**
|
|
|
|
* Extract all files in the image according to their respective filetype.
|
|
|
|
*/
|
|
|
|
static void getFiles(String imageName, String directory) throws IOException {
|
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
if (directory.length() > 0) {
|
|
|
|
// Add a final directory separator if the user didn't supply one
|
2009-09-03 17:33:33 +00:00
|
|
|
if (!directory.endsWith(File.separator))
|
|
|
|
directory = directory + File.separator;
|
2008-12-20 03:31:54 +00:00
|
|
|
}
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
|
|
|
List files = formattedDisk.getFiles();
|
|
|
|
Iterator it = files.iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
FileEntry entry = (FileEntry) it.next();
|
2012-07-06 17:13:12 +00:00
|
|
|
// FIXME: dumping files within (ProDOS) directories isn't handled. For now, ignore them.
|
|
|
|
if ((entry != null) && (!entry.isDeleted()) && (!entry.isDirectory())) {
|
2008-12-20 03:31:54 +00:00
|
|
|
FileFilter ff = entry.getSuggestedFilter();
|
|
|
|
if (ff instanceof BinaryFileFilter)
|
|
|
|
ff = new HexDumpFileFilter();
|
|
|
|
byte[] buf = ff.filter(entry);
|
|
|
|
String filename = ff.getSuggestedFileName(entry);
|
|
|
|
File file = new File(directory + filename);
|
|
|
|
OutputStream output = new FileOutputStream(file);
|
|
|
|
output.write(buf, 0, buf.length);
|
|
|
|
output.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
2008-06-08 21:40:06 +00:00
|
|
|
* Recursive routine to locate a specific file by filename; In the instance
|
|
|
|
* of a system with directories (e.g. ProDOS), this really returns the first
|
|
|
|
* file with the given filename.
|
2009-09-05 03:31:43 +00:00
|
|
|
* @deprecated
|
2003-12-12 04:21:32 +00:00
|
|
|
*/
|
|
|
|
static FileEntry getEntry(List files, String fileName) {
|
2009-09-03 17:33:33 +00:00
|
|
|
FileEntry entry = null;
|
2003-12-12 04:21:32 +00:00
|
|
|
if (files != null) {
|
2008-06-07 00:17:52 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2009-09-03 17:33:33 +00:00
|
|
|
entry = (FileEntry) files.get(i);
|
2003-12-12 04:21:32 +00:00
|
|
|
String entryName = entry.getFilename();
|
2008-06-08 21:40:06 +00:00
|
|
|
if (!entry.isDeleted() && fileName.equalsIgnoreCase(entryName)) {
|
2003-12-12 04:21:32 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
if (entry.isDirectory()) {
|
2009-09-03 17:33:33 +00:00
|
|
|
entry = getEntry(((DirectoryEntry) entry).getFiles(), fileName);
|
|
|
|
if (entry != null) {
|
|
|
|
return entry;
|
2008-06-08 21:40:06 +00:00
|
|
|
}
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
2008-06-07 00:17:52 +00:00
|
|
|
* Display a directory listing of each disk in args.
|
2003-12-12 04:21:32 +00:00
|
|
|
*/
|
2008-06-07 00:17:52 +00:00
|
|
|
static void showDirectory(String[] args, int display) throws IOException {
|
|
|
|
for (int d = 1; d < args.length; d++) {
|
2008-06-08 21:40:06 +00:00
|
|
|
try {
|
|
|
|
Disk disk = new Disk(args[d]);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
|
|
|
System.out.print(args[d] + " ");
|
|
|
|
System.out.println(formattedDisk.getDiskName());
|
|
|
|
List files = formattedDisk.getFiles();
|
|
|
|
if (files != null) {
|
|
|
|
showFiles(files, "", display); //$NON-NLS-1$
|
|
|
|
}
|
|
|
|
System.out.println(textBundle.format("CommandLineStatus", //$NON-NLS-1$
|
|
|
|
new Object[] { formattedDisk.getFormat(),
|
2008-06-07 00:17:52 +00:00
|
|
|
new Integer(formattedDisk.getFreeSpace()),
|
2008-06-08 21:40:06 +00:00
|
|
|
new Integer(formattedDisk.getUsedSpace()) }));
|
|
|
|
System.out.println();
|
|
|
|
}
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
System.out.println(args[d] + ": " + e.getMessage()); //$NON-NLS-1$
|
2008-06-07 00:17:52 +00:00
|
|
|
System.out.println();
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
2008-06-08 21:40:06 +00:00
|
|
|
* Recursive routine to display directory entries. In the instance of a
|
|
|
|
* system with directories (e.g. ProDOS), this really returns the first file
|
|
|
|
* with the given filename.
|
2003-12-12 04:21:32 +00:00
|
|
|
*/
|
2006-04-16 03:28:36 +00:00
|
|
|
static void showFiles(List files, String indent, int display) {
|
2008-06-07 00:17:52 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2003-12-12 04:21:32 +00:00
|
|
|
FileEntry entry = (FileEntry) files.get(i);
|
|
|
|
if (!entry.isDeleted()) {
|
2006-04-16 03:28:36 +00:00
|
|
|
List data = entry.getFileColumnData(display);
|
2003-12-12 04:21:32 +00:00
|
|
|
System.out.print(indent);
|
2008-06-07 00:17:52 +00:00
|
|
|
for (int d = 0; d < data.size(); d++) {
|
2003-12-12 04:21:32 +00:00
|
|
|
System.out.print(data.get(d));
|
2004-07-04 03:34:35 +00:00
|
|
|
System.out.print(" "); //$NON-NLS-1$
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
System.out.println();
|
|
|
|
}
|
|
|
|
if (entry.isDirectory()) {
|
2008-06-08 21:40:06 +00:00
|
|
|
showFiles(((DirectoryEntry) entry).getFiles(),
|
2006-04-16 03:28:36 +00:00
|
|
|
indent + " ", display); //$NON-NLS-1$
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-16 03:28:36 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-07 00:17:52 +00:00
|
|
|
* Display information about each disk in args.
|
2006-04-16 03:28:36 +00:00
|
|
|
*/
|
2008-06-07 00:17:52 +00:00
|
|
|
static void getDiskInfo(String[] args) throws IOException {
|
|
|
|
for (int d = 1; d < args.length; d++) {
|
|
|
|
Disk disk = new Disk(args[d]);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
2009-09-05 03:31:43 +00:00
|
|
|
Iterator iterator = formattedDisk.getDiskInformation().iterator();
|
2008-06-07 00:17:52 +00:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
DiskInformation diskinfo = (DiskInformation) iterator.next();
|
|
|
|
System.out.println(diskinfo.getLabel() + ": " + diskinfo.getValue());
|
2008-06-08 21:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-07 00:17:52 +00:00
|
|
|
System.out.println();
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
}
|
2006-04-16 03:28:36 +00:00
|
|
|
|
2008-06-05 11:54:14 +00:00
|
|
|
/**
|
|
|
|
* Set the lockState of the file named fileName on the disk named imageName.
|
|
|
|
* Proposed by David Schmidt.
|
|
|
|
*/
|
2009-09-05 03:31:43 +00:00
|
|
|
static void setFileLocked(String imageName, Name name,
|
2008-06-08 21:40:06 +00:00
|
|
|
boolean lockState) throws IOException {
|
2008-06-05 11:54:14 +00:00
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
for (int i = 0; i < formattedDisks.length; i++) {
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[i];
|
2009-09-05 15:43:21 +00:00
|
|
|
FileEntry entry = name.getEntry(formattedDisk);
|
2008-06-05 11:54:14 +00:00
|
|
|
if (entry != null) {
|
|
|
|
entry.setLocked(lockState);
|
|
|
|
disk.save();
|
|
|
|
} else {
|
|
|
|
System.err.println(textBundle.format(
|
2009-09-05 03:31:43 +00:00
|
|
|
"CommandLineNoMatchMessage", name.fullName)); //$NON-NLS-1$
|
2008-06-05 11:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2008-06-05 11:54:14 +00:00
|
|
|
/**
|
2008-06-08 21:40:06 +00:00
|
|
|
* Set the volume name for a given disk image. Only effective for ProDOS or
|
|
|
|
* Pascal disks; others ignored. Proposed by David Schmidt.
|
2008-06-05 11:54:14 +00:00
|
|
|
*/
|
|
|
|
static void setDiskName(String imageName, String volName)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
|
|
|
Disk disk = new Disk(imageName);
|
|
|
|
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
|
|
|
|
FormattedDisk formattedDisk = formattedDisks[0];
|
|
|
|
formattedDisk.setDiskName(volName);
|
|
|
|
formattedDisks[0].save();
|
2008-06-05 11:54:14 +00:00
|
|
|
}
|
|
|
|
|
2006-04-16 03:28:36 +00:00
|
|
|
/**
|
|
|
|
* Create a DOS disk image.
|
|
|
|
*/
|
|
|
|
static void createDosDisk(String fileName, int imageSize)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
2006-04-16 03:28:36 +00:00
|
|
|
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
|
|
|
|
ImageOrder imageOrder = new DosOrder(layout);
|
2008-06-08 21:40:06 +00:00
|
|
|
FormattedDisk[] disks = DosFormatDisk.create(fileName, imageOrder);
|
2006-04-16 03:28:36 +00:00
|
|
|
disks[0].save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Pascal disk image.
|
|
|
|
*/
|
|
|
|
static void createPasDisk(String fileName, String volName, int imageSize)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
2006-04-16 03:28:36 +00:00
|
|
|
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
|
|
|
|
ImageOrder imageOrder = new ProdosOrder(layout);
|
2008-06-08 21:40:06 +00:00
|
|
|
FormattedDisk[] disks = PascalFormatDisk.create(fileName, volName, imageOrder);
|
2006-04-16 03:28:36 +00:00
|
|
|
disks[0].save();
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
/**
|
|
|
|
* Create a ProDOS disk image.
|
|
|
|
*/
|
2006-04-16 03:28:36 +00:00
|
|
|
static void createProDisk(String fileName, String volName, int imageSize)
|
2008-06-08 21:40:06 +00:00
|
|
|
throws IOException {
|
2003-12-26 21:40:10 +00:00
|
|
|
ByteArrayImageLayout layout = new ByteArrayImageLayout(imageSize);
|
|
|
|
ImageOrder imageOrder = new ProdosOrder(layout);
|
2008-06-08 21:40:06 +00:00
|
|
|
FormattedDisk[] disks = ProdosFormatDisk.create(fileName, volName, imageOrder);
|
2003-12-12 04:21:32 +00:00
|
|
|
disks[0].save();
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
static int stringToInt(String s) {
|
|
|
|
int i = 0;
|
|
|
|
try {
|
2008-05-18 21:03:25 +00:00
|
|
|
s = s.trim().toLowerCase();
|
2008-05-22 17:30:27 +00:00
|
|
|
if (s.startsWith("$")) { // 6502, Motorola
|
2008-05-18 20:00:16 +00:00
|
|
|
i = Integer.parseInt(s.substring(1), 0x10);
|
2008-05-18 21:03:25 +00:00
|
|
|
} else if (s.startsWith("0x")) { // Java, C
|
|
|
|
i = Integer.parseInt(s.substring(2), 0x10);
|
2008-05-18 20:00:16 +00:00
|
|
|
} else {
|
2008-06-08 21:40:06 +00:00
|
|
|
i = Integer.parseInt(s);
|
2008-05-18 20:00:16 +00:00
|
|
|
}
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
i = 0x2000;
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2008-06-08 21:40:06 +00:00
|
|
|
|
2003-12-12 04:21:32 +00:00
|
|
|
static void help() {
|
2008-06-08 21:40:06 +00:00
|
|
|
System.err.println(textBundle.format(
|
|
|
|
"CommandLineHelp", AppleCommander.VERSION)); //$NON-NLS-1$
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|
|
|
|
|
2009-09-05 03:31:43 +00:00
|
|
|
private static class Name {
|
|
|
|
private String fullName;
|
|
|
|
private String name;
|
|
|
|
private String[] path;
|
|
|
|
|
|
|
|
public Name(String s) {
|
|
|
|
this.fullName = s;
|
|
|
|
if (s.startsWith("/")) {
|
|
|
|
fullName = s.substring(1, s.length());
|
|
|
|
}
|
|
|
|
this.path = s.split("/");
|
|
|
|
this.name = path[path.length - 1];
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:43:21 +00:00
|
|
|
public FileEntry getEntry(FormattedDisk formattedDisk) {
|
|
|
|
List files = formattedDisk.getFiles();
|
2009-09-05 03:31:43 +00:00
|
|
|
FileEntry entry = null;
|
|
|
|
for (int i = 0; i < path.length - 1; i++) {
|
|
|
|
String dirName = path[i];
|
|
|
|
for (int j = 0; j < files.size(); j++) {
|
|
|
|
entry = (FileEntry) files.get(j);
|
|
|
|
String entryName = entry.getFilename();
|
|
|
|
if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) {
|
|
|
|
files = ((DirectoryEntry) entry).getFiles();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < files.size(); i++) {
|
|
|
|
entry = (FileEntry) files.get(i);
|
|
|
|
String entryName = entry.getFilename();
|
|
|
|
if (!entry.isDeleted() && name.equalsIgnoreCase(entryName)) {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:43:21 +00:00
|
|
|
public FileEntry createEntry(FormattedDisk formattedDisk) throws DiskFullException {
|
|
|
|
if (path.length == 1) {
|
|
|
|
return formattedDisk.createFile();
|
|
|
|
}
|
|
|
|
List files = formattedDisk.getFiles();
|
2009-09-05 03:31:43 +00:00
|
|
|
DirectoryEntry dir = null;
|
|
|
|
for (int i = 0; i < path.length - 1; i++) {
|
|
|
|
String dirName = path[i];
|
|
|
|
for (int j = 0; j < files.size(); j++) {
|
|
|
|
FileEntry entry = (FileEntry) files.get(j);
|
|
|
|
String entryName = entry.getFilename();
|
|
|
|
if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) {
|
|
|
|
dir = (DirectoryEntry) entry;
|
|
|
|
files = dir.getFiles();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-05 15:43:21 +00:00
|
|
|
if (dir != null) {
|
|
|
|
return dir.createFile();
|
|
|
|
} else {
|
|
|
|
System.err.println(textBundle.format(
|
|
|
|
"CommandLineNoMatchMessage", fullName)); //$NON-NLS-1$
|
|
|
|
return null;
|
|
|
|
}
|
2009-09-05 03:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-12 04:21:32 +00:00
|
|
|
}
|