/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2002-2022 by Robert Greene * robgreene at users.sourceforge.net * * 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.storage.os.gutenberg; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; 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; import com.webcodepro.applecommander.storage.StorageBundle; import com.webcodepro.applecommander.storage.filters.GutenbergFileFilter; import com.webcodepro.applecommander.util.AppleUtil; import com.webcodepro.applecommander.util.TextBundle; /** * Represents a Gutenberg word processing file entry on disk. *
* Date created: Dec 17, 2008 04:29:23 PM
* @author David Schmidt
*/
public class GutenbergFileEntry implements FileEntry {
private TextBundle textBundle = StorageBundle.getInstance();
/**
* Indicates the length in bytes of the DOS file entry field.
*/
public static final int FILE_DESCRIPTIVE_ENTRY_LENGTH = 16;
/**
* Holds the disk the FileEntry is attached to.
*/
private GutenbergFormatDisk disk;
/**
* Track of the FileEntry location.
*/
private int track;
/**
* Sector of the FileEntry location.
*/
private int sector;
/**
* Offset into sector of FileEntry location.
*/
private int offset;
/**
* Constructor for GutenbergFileEntry.
*/
public GutenbergFileEntry(GutenbergFormatDisk disk, int track, int sector, int offset) {
super();
this.disk = disk;
this.track = track;
this.sector = sector;
this.offset = offset;
}
/**
* Read the FileEntry from the disk image.
*/
protected byte[] readFileEntry() {
byte[] sectorData = disk.readSector(track, sector);
byte[] fileEntry = new byte[FILE_DESCRIPTIVE_ENTRY_LENGTH];
System.arraycopy(sectorData, offset, fileEntry, 0, fileEntry.length);
return fileEntry;
}
/**
* Write the FileEntry to the disk image.
*/
protected void writeFileEntry(byte[] fileEntry) {
if (fileEntry.length != FILE_DESCRIPTIVE_ENTRY_LENGTH) {
throw new IllegalArgumentException(textBundle.
format("GutenbergFileEntry.GutenbergFileEntryLengthError", //$NON-NLS-1$
FILE_DESCRIPTIVE_ENTRY_LENGTH));
}
byte[] sectorData = disk.readSector(track, sector);
System.arraycopy(fileEntry, 0, sectorData, offset, fileEntry.length);
disk.writeSector(track, sector, sectorData);
}
/**
* Return the maximum filename length.
*/
public int getMaximumFilenameLength() {
return 12;
}
/**
* Return the name of this file.
* @see com.webcodepro.applecommander.storage.FileEntry#getFilename()
*/
public String getFilename() {
return AppleUtil.getString(readFileEntry(), 0, getMaximumFilenameLength()).trim();
}
/**
* Set the name of this file.
*/
public void setFilename(String filename) {
byte[] data = readFileEntry();
AppleUtil.setString(data, 0, filename.toUpperCase(), getMaximumFilenameLength());
writeFileEntry(data);
}
/**
* Return the filetype of this file.
* @see com.webcodepro.applecommander.storage.FileEntry#getFiletype()
*/
public String getFiletype() {
return "T"; // Only one file type... text //$NON-NLS-1$
}
/**
* Set the filetype (typeless - unused)
*/
public void setFiletype(String filetype) {
}
/**
* Identify if this file is locked.
* @see com.webcodepro.applecommander.storage.FileEntry#isLocked()
*/
public boolean isLocked() {
return true;
}
/**
* Set the lock indicator (unused)
*/
public void setLocked(boolean lock) {
}
/**
* Compute the size of this file (in bytes).
* @see com.webcodepro.applecommander.storage.FileEntry#getSize()
*/
public int getSize() {
// Nothing special, just compute from number of sectors
int size = getSectorsUsed() * Disk.SECTOR_SIZE;
return size;
}
/**
* Compute the number of sectors used.
*/
public int getSectorsUsed() {
// Follow the chain of sectors to find the end.
int track = getTrack();
int sector = getSector();
int sectors = 0;
while (track < 128) {
byte[] sectorData = disk.readSector(track, sector);
track = AppleUtil.getUnsignedByte(sectorData[0x04]);
sector = AppleUtil.getUnsignedByte(sectorData[0x05]);
sectors++;
}
return sectors;
}
/**
* Set the number of sectors used.
*/
public void setSectorsUsed(int sectorsUsed) {
}
/**
* Identify if this is a directory file.
* @see com.webcodepro.applecommander.storage.FileEntry#isDirectory()
*/
public boolean isDirectory() {
return false;
}
/**
* Identify if this file has been deleted.
* @see com.webcodepro.applecommander.storage.FileEntry#isDeleted()
*/
public boolean isDeleted() {
return AppleUtil.getUnsignedByte(readFileEntry()[0x0d]) == 0x40;
}
/**
* Delete this file.
*/
public void delete() {
}
/**
* Get the standard file column header information.
* This default implementation is intended only for standard mode.
* displayMode is specified in FormattedDisk.
*/
public List