/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2002 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; import com.webcodepro.applecommander.util.AppleUtil; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * Represents a ProDOS file entry on disk. *

* Date created: Oct 5, 2002 6:01:15 PM * @author: Rob Greene */ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry { /** * Constructor for ProdosFileEntry. */ public ProdosFileEntry(ProdosFormatDisk disk, int block, int offset) { super(disk, block, offset); } /** * Return the name of this file. * This handles normal files, deleted files, and AppleWorks files - which use * the AUXTYPE attribute to indicate upper/lower-case in the filename. */ public String getFilename() { String fileName; if (isDeleted()) { fileName = AppleUtil.getString(readFileEntry(), 1, 15); StringBuffer buf = new StringBuffer(); for (int i=0; i> 8), 7-(i%8)); } if (lowerCase) { char ch = mixedCase.charAt(i); if (ch == '.') { mixedCase.setCharAt(i, ' '); } else { mixedCase.setCharAt(i, Character.toLowerCase(ch)); } } } fileName = mixedCase.toString(); } return fileName; } /** * Return the maximum filename length. */ public int getMaximumFilenameLength() { return 15; } /** * Set the name of this file. */ public void setFilename(String filename) { byte[] fileEntry = readFileEntry(); if (isDeleted()) { AppleUtil.setString(fileEntry, 1, filename.toUpperCase(), 15); } else { AppleUtil.setProdosString(fileEntry, 0, filename.toUpperCase(), 15); } if (isAppleWorksFile()) { byte lowByte = 0; byte highByte = 0; for (int i=0; i " : dateFormat.format(getLastModificationDate())); list.add(getCreationDate() == null ? " " : dateFormat.format(getCreationDate())); numberFormat.setMinimumIntegerDigits(1); list.add(numberFormat.format(getEofPosition())); if ("TXT".equals(getFiletype()) && getAuxiliaryType() > 0) { numberFormat.setMinimumIntegerDigits(1); list.add("L=" + numberFormat.format(getAuxiliaryType()).trim()); } else if (("BIN".equals(getFiletype()) || "BAS".equals(getFiletype()) || "VAR".equals(getFiletype()) || "SYS".equals(getFiletype())) && getAuxiliaryType() > 0) { list.add("A=$" + AppleUtil.getFormattedWord(getAuxiliaryType())); } else { list.add(""); } break; case FormattedDisk.FILE_DISPLAY_DETAIL: list.add(isLocked() ? "*" : " "); list.add(getFilename()); list.add(isDeleted() ? "Deleted" : ""); String permissions = ""; if (canDestroy()) permissions+= "Destroy "; if (canRead()) permissions+= "Read "; if (canRename()) permissions+= "Rename "; if (canWrite()) permissions+= "Write "; list.add(permissions); list.add(getFiletype()); list.add(isDirectory() ? "Directory" : ""); numberFormat.setMinimumIntegerDigits(3); list.add(numberFormat.format(getBlocksUsed())); list.add(getLastModificationDate() == null ? " " : dateFormat.format(getLastModificationDate())); list.add(getCreationDate() == null ? " " : dateFormat.format(getCreationDate())); numberFormat.setMinimumIntegerDigits(1); list.add(numberFormat.format(getEofPosition())); if ("TXT".equals(getFiletype()) && getAuxiliaryType() > 0) { numberFormat.setMinimumIntegerDigits(1); list.add("L=" + numberFormat.format(getAuxiliaryType()).trim()); } else if (("BIN".equals(getFiletype()) || "BAS".equals(getFiletype()) || "VAR".equals(getFiletype()) || "SYS".equals(getFiletype())) && getAuxiliaryType() > 0) { list.add("A=$" + AppleUtil.getFormattedWord(getAuxiliaryType())); } else { list.add("$" + AppleUtil.getFormattedWord(getAuxiliaryType())); } list.add(AppleUtil.getFormattedWord(getHeaderPointer())); list.add(AppleUtil.getFormattedWord(getKeyPointer())); list.add(isSaplingFile() ? "Sapling" : isSeedlingFile() ? "Seedling" : isTreeFile() ? "Tree" : "Unknown"); list.add(hasChanged() ? "Changed" : ""); numberFormat.setMinimumIntegerDigits(1); list.add(numberFormat.format(getMinimumProdosVersion())); list.add(numberFormat.format(getProdosVersion())); break; default: // FILE_DISPLAY_STANDARD list.add(getFilename()); list.add(getFiletype()); list.add(numberFormat.format(getSize())); list.add(isLocked() ? "Locked" : ""); break; } return list; } /** * Get file data. This handles any operating-system specific issues. * Currently, the disk itself handles this. */ public byte[] getFileData() { return getDisk().getFileData(this); } /** * Set the file data. This is essentially the save operation. * Specifically, if the filetype is binary, the length and * address need to be set. If the filetype is applesoft or * integer basic, the start address needs to be set. */ public void setFileData(byte[] data) throws DiskFullException { getDisk().setFileData(this, data); } /** * Get the suggested FileFilter. This appears to be operating system * specific, so each operating system needs to implement some manner * of guessing the appropriate filter. */ public FileFilter getSuggestedFilter() { if ("TXT".equals(getFiletype()) || "SRC".equals(getFiletype())) { return new TextFileFilter(); } else if ("AWP".equals(getFiletype())) { return new AppleWorksWordProcessorFileFilter(); } else if ("ADB".equals(getFiletype())) { return new AppleWorksDataBaseFileFilter(); } else if ("ASP".equals(getFiletype())) { return new AppleWorksSpreadSheetFileFilter(); } else if ("BAS".equals(getFiletype())) { return new ApplesoftFileFilter(); } else if ("INT".equals(getFiletype())) { // supposedly not available in ProDOS, however return new IntegerBasicFileFilter(); } else if ("PNT".equals(getFiletype())) { if (getAuxiliaryType() == 0x0001) { GraphicsFileFilter filter = new GraphicsFileFilter(); filter.setMode(GraphicsFileFilter.MODE_SHR); return filter; } } else if ("PIC".equals(getFiletype())) { if (getAuxiliaryType() == 0x0000) { GraphicsFileFilter filter = new GraphicsFileFilter(); filter.setMode(GraphicsFileFilter.MODE_SHR); return filter; } } else if ("BIN".equals(getFiletype())) { int size = getSize(); // the minimum size is guessed a bit - I don't remember, but maybe there // are 8 spare bytes at the end of the graphics screen GraphicsFileFilter filter = new GraphicsFileFilter(); if (size >= 8185 && size <= 8192) { filter.setMode(GraphicsFileFilter.MODE_HGR_COLOR); return filter; } else if (size >= 16377 && size <= 16384) { filter.setMode(GraphicsFileFilter.MODE_DHR_COLOR); return filter; } // fall through to BinaryFileFilter... } return new BinaryFileFilter(); } /** * Indicates if this filetype requires an address component. * Note that the FormattedDisk also has this method - normally, * this will defer to the method on FormattedDisk, as it will be * more generic. */ public boolean needsAddress() { return getDisk().needsAddress(getFiletype()); } /** * Set the address that this file loads at. */ public void setAddress(int address) { byte[] fileEntry = readFileEntry(); setAuxiliaryType(fileEntry, address); writeFileEntry(fileEntry); } }