diff --git a/src/com/bytezone/diskbrowser/prodos/write/FileAlreadyExistsException.java b/src/com/bytezone/diskbrowser/prodos/write/FileAlreadyExistsException.java new file mode 100644 index 0000000..4f53b98 --- /dev/null +++ b/src/com/bytezone/diskbrowser/prodos/write/FileAlreadyExistsException.java @@ -0,0 +1,9 @@ +package com.bytezone.diskbrowser.prodos.write; + +public class FileAlreadyExistsException extends Exception +{ + public FileAlreadyExistsException (String message) + { + super (message); + } +} diff --git a/src/com/bytezone/diskbrowser/prodos/write/ProdosDisk.java b/src/com/bytezone/diskbrowser/prodos/write/ProdosDisk.java index 314b193..8c1eee8 100644 --- a/src/com/bytezone/diskbrowser/prodos/write/ProdosDisk.java +++ b/src/com/bytezone/diskbrowser/prodos/write/ProdosDisk.java @@ -122,8 +122,8 @@ public class ProdosDisk // ---------------------------------------------------------------------------------// public FileEntry addFile (String path, byte type, int auxType, LocalDateTime created, - LocalDateTime modified, byte[] dataBuffer) - throws DiskFullException, VolumeCatalogFullException + LocalDateTime modified, byte[] fileBuffer, int eof) + throws DiskFullException, VolumeCatalogFullException, FileAlreadyExistsException // ---------------------------------------------------------------------------------// { if (path.isBlank ()) @@ -170,7 +170,7 @@ public class ProdosDisk { System.out.println ("File already exists: " + path); System.out.println (fileEntryOpt.get ()); - return null; // throw something? + throw new FileAlreadyExistsException (fileName); } // create a file entry in the current catalog block @@ -188,7 +188,7 @@ public class ProdosDisk fileEntry.modifiedDate = modified; FileWriter fileWriter = new FileWriter (this); - fileWriter.writeFile (dataBuffer, dataBuffer.length); + fileWriter.writeFile (fileBuffer, eof); fileEntry.storageType = fileWriter.storageType; fileEntry.keyPointer = fileWriter.keyPointer; @@ -197,22 +197,20 @@ public class ProdosDisk fileEntry.write (); updateFileCount (fileEntry.headerPointer); - - return fileEntry; } - return null; // should be impossible + return fileEntry; } // ---------------------------------------------------------------------------------// - public void addResourceFork (FileEntry fileEntry, byte[] dataBuffer, int eof) + public void addResourceFork (FileEntry fileEntry, byte[] fileBuffer, int eof) throws DiskFullException // ---------------------------------------------------------------------------------// { int blockNo = allocateNextBlock (); // allocate extended key block FileWriter fileWriter = new FileWriter (this); // create resource fork - fileWriter.writeFile (dataBuffer, eof); + fileWriter.writeFile (fileBuffer, eof); ExtendedKeyBlock extendedKeyBlock = new ExtendedKeyBlock (this, blockNo * BLOCK_SIZE); diff --git a/src/com/bytezone/diskbrowser/utilities/NuFX.java b/src/com/bytezone/diskbrowser/utilities/NuFX.java index 00bafaf..a646339 100644 --- a/src/com/bytezone/diskbrowser/utilities/NuFX.java +++ b/src/com/bytezone/diskbrowser/utilities/NuFX.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; import com.bytezone.diskbrowser.prodos.write.DiskFullException; +import com.bytezone.diskbrowser.prodos.write.FileAlreadyExistsException; import com.bytezone.diskbrowser.prodos.write.FileEntry; import com.bytezone.diskbrowser.prodos.write.ProdosDisk; import com.bytezone.diskbrowser.prodos.write.VolumeCatalogFullException; @@ -167,12 +168,14 @@ public class NuFX if (record.hasFile ()) { String fileName = volumeName.convert (record.getFileName ()); + if (!record.isValidFileSystem ()) { System.out.printf ("File %s is file system %s%n", fileName, record.getFileSystemName ()); continue; } + // int fileSize = record.getFileSize (); byte fileType = (byte) record.getFileType (); int eof = record.getUncompressedSize (); @@ -185,9 +188,13 @@ public class NuFX System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count, fileName, fileType, auxType, eof, buffer.length, created, modified); - FileEntry fileEntry = - disk.addFile (fileName, fileType, auxType, created, modified, buffer); - if (fileEntry == null) + FileEntry fileEntry; + try + { + fileEntry = disk.addFile (fileName, fileType, auxType, created, modified, + buffer, eof); + } + catch (FileAlreadyExistsException e) { System.out.printf ("File %s not added%n", fileName); break; @@ -196,7 +203,6 @@ public class NuFX if (record.hasResource ()) { buffer = record.getResourceData (); - // System.out.println (HexFormatter.format (buffer)); disk.addResourceFork (fileEntry, buffer, buffer.length); } }