Added changes per John Matthews fixes for AppleCommander 1.2.3.

See http://www.wright.edu/~john.matthews/ac.html.
This commit is contained in:
Robert Greene 2003-12-04 04:10:49 +00:00
parent 9709fe8a03
commit 070c3d8b63
5 changed files with 51 additions and 15 deletions

View File

@ -254,6 +254,15 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
return AppleUtil.getWordValue(readFileEntry(), 0x25);
}
/**
* Set the block number of the block for the directory which describes this file.
*/
public void setHeaderPointer(int headerPointer) {
byte[] entry = readFileEntry();
AppleUtil.setWordValue(entry, 0x25, headerPointer);
writeFileEntry(entry);
}
/**
* Identify if this file is locked.
*/
@ -296,7 +305,19 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry {
*/
public void delete() {
getDisk().freeBlocks(this);
setStorageType(0);
//decrement file count in header block
int headerBlock = getHeaderPointer();
byte[] data = getDisk().readBlock(headerBlock);
int fileCount = AppleUtil.getWordValue(data, 0x25);
if (fileCount != 0) fileCount--;
AppleUtil.setWordValue(data, 0x25, fileCount);
getDisk().writeBlock(headerBlock, data);
//clear storage type and name length
data = readFileEntry();
data[0] = 0;
writeFileEntry(data);
}
/**

View File

@ -127,6 +127,7 @@ filetype.f9=P16
filetype.fa=INT
filetype.fb=IVR
filetype.fc=BAS
filetype.fc.address=true
filetype.fd=VAR
filetype.fe=REL
filetype.ff=SYS

View File

@ -189,6 +189,7 @@ public class ProdosFormatDisk extends FormattedDisk {
throws DiskFullException {
int blockNumber = directory.getFileEntryBlock();
int headerBlock = blockNumber;
while (blockNumber != 0) {
byte[] block = readBlock(blockNumber);
int offset = 4;
@ -197,6 +198,7 @@ public class ProdosFormatDisk extends FormattedDisk {
if ((value & 0xf0) == 0) {
ProdosFileEntry fileEntry =
new ProdosFileEntry(this, blockNumber, offset);
fileEntry.setKeyPointer(0); //may have been recycled
fileEntry.setCreationDate(new Date());
fileEntry.setProdosVersion(0);
fileEntry.setMinimumProdosVersion(0);
@ -204,7 +206,8 @@ public class ProdosFormatDisk extends FormattedDisk {
fileEntry.setCanRead(true);
fileEntry.setCanRename(true);
fileEntry.setCanWrite(true);
fileEntry.setSaplingFile();
fileEntry.setSeedlingFile();
fileEntry.setHeaderPointer(headerBlock);
fileEntry.setFilename("BLANK");
directory.incrementFileCount();
return fileEntry;

View File

@ -19,6 +19,9 @@
*/
package com.webcodepro.applecommander.storage;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
/**
* Filter the given file data for text.
* <p>
@ -34,28 +37,31 @@ public class TextFileFilter implements FileFilter {
}
/**
* Process the given FileEntry and return a byte array with filtered data.
* @see com.webcodepro.applecommander.storage.FileFilter#filter(byte[])
* Process the given FileEntry and return a byte array
* with filtered data; use PrintWriter to get platform
* agnostic line endings.
*/
public byte[] filter(FileEntry fileEntry) {
byte[] fileData = fileEntry.getFileData();
byte[] workingData = new byte[fileData.length];
int position = 0;
for (int i=0; i<fileData.length; i++) {
byte byt = fileData[i];
if (byt != 0) {
if ((byt & 0x80) != 0) { // high bit set
workingData[position++] = (byte)(byt & 0x7f);
int offset = 0;
ByteArrayOutputStream byteArray = new
ByteArrayOutputStream(fileData.length);
PrintWriter printWriter = new PrintWriter(byteArray, true);
while (offset < fileData.length) {
char c = (char)(fileData[offset] & 0x7f);
if (c != 0) {
if (c == 0x0d) { //Apple line end
printWriter.println();
} else {
workingData[position++] = byt;
printWriter.print(c);
}
}
offset++;
}
byte[] filteredData = new byte[position];
System.arraycopy(workingData, 0, filteredData, 0, filteredData.length);
return filteredData;
return byteArray.toByteArray();
}
/**
* Give suggested file name.
*/

View File

@ -333,6 +333,11 @@ public class AppleUtil {
year = gc.get(GregorianCalendar.YEAR);
minute = gc.get(GregorianCalendar.MINUTE);
hour = gc.get(GregorianCalendar.HOUR_OF_DAY);
if (year >= 2000) {
year -= 2000;
} else {
year -= 1900;
}
}
int ymd = ((year & 0x7f) << 9) | ((month & 0xf) << 5) | (day & 0x1f);
int hm = ((hour & 0x1f) << 8) | (minute & 0x3f);