This commit is contained in:
Denis Molony 2021-05-04 10:02:20 +10:00
parent 2dff5a966c
commit 7d79f8f365
3 changed files with 26 additions and 13 deletions

View File

@ -0,0 +1,9 @@
package com.bytezone.diskbrowser.prodos.write;
public class FileAlreadyExistsException extends Exception
{
public FileAlreadyExistsException (String message)
{
super (message);
}
}

View File

@ -122,8 +122,8 @@ public class ProdosDisk
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public FileEntry addFile (String path, byte type, int auxType, LocalDateTime created, public FileEntry addFile (String path, byte type, int auxType, LocalDateTime created,
LocalDateTime modified, byte[] dataBuffer) LocalDateTime modified, byte[] fileBuffer, int eof)
throws DiskFullException, VolumeCatalogFullException throws DiskFullException, VolumeCatalogFullException, FileAlreadyExistsException
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (path.isBlank ()) if (path.isBlank ())
@ -170,7 +170,7 @@ public class ProdosDisk
{ {
System.out.println ("File already exists: " + path); System.out.println ("File already exists: " + path);
System.out.println (fileEntryOpt.get ()); System.out.println (fileEntryOpt.get ());
return null; // throw something? throw new FileAlreadyExistsException (fileName);
} }
// create a file entry in the current catalog block // create a file entry in the current catalog block
@ -188,7 +188,7 @@ public class ProdosDisk
fileEntry.modifiedDate = modified; fileEntry.modifiedDate = modified;
FileWriter fileWriter = new FileWriter (this); FileWriter fileWriter = new FileWriter (this);
fileWriter.writeFile (dataBuffer, dataBuffer.length); fileWriter.writeFile (fileBuffer, eof);
fileEntry.storageType = fileWriter.storageType; fileEntry.storageType = fileWriter.storageType;
fileEntry.keyPointer = fileWriter.keyPointer; fileEntry.keyPointer = fileWriter.keyPointer;
@ -197,22 +197,20 @@ public class ProdosDisk
fileEntry.write (); fileEntry.write ();
updateFileCount (fileEntry.headerPointer); 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 throws DiskFullException
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
int blockNo = allocateNextBlock (); // allocate extended key block int blockNo = allocateNextBlock (); // allocate extended key block
FileWriter fileWriter = new FileWriter (this); // create resource fork FileWriter fileWriter = new FileWriter (this); // create resource fork
fileWriter.writeFile (dataBuffer, eof); fileWriter.writeFile (fileBuffer, eof);
ExtendedKeyBlock extendedKeyBlock = new ExtendedKeyBlock (this, blockNo * BLOCK_SIZE); ExtendedKeyBlock extendedKeyBlock = new ExtendedKeyBlock (this, blockNo * BLOCK_SIZE);

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.prodos.write.DiskFullException; 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.FileEntry;
import com.bytezone.diskbrowser.prodos.write.ProdosDisk; import com.bytezone.diskbrowser.prodos.write.ProdosDisk;
import com.bytezone.diskbrowser.prodos.write.VolumeCatalogFullException; import com.bytezone.diskbrowser.prodos.write.VolumeCatalogFullException;
@ -167,12 +168,14 @@ public class NuFX
if (record.hasFile ()) if (record.hasFile ())
{ {
String fileName = volumeName.convert (record.getFileName ()); String fileName = volumeName.convert (record.getFileName ());
if (!record.isValidFileSystem ()) if (!record.isValidFileSystem ())
{ {
System.out.printf ("File %s is file system %s%n", fileName, System.out.printf ("File %s is file system %s%n", fileName,
record.getFileSystemName ()); record.getFileSystemName ());
continue; continue;
} }
// int fileSize = record.getFileSize (); // int fileSize = record.getFileSize ();
byte fileType = (byte) record.getFileType (); byte fileType = (byte) record.getFileType ();
int eof = record.getUncompressedSize (); int eof = record.getUncompressedSize ();
@ -185,9 +188,13 @@ public class NuFX
System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count, System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count,
fileName, fileType, auxType, eof, buffer.length, created, modified); fileName, fileType, auxType, eof, buffer.length, created, modified);
FileEntry fileEntry = FileEntry fileEntry;
disk.addFile (fileName, fileType, auxType, created, modified, buffer); try
if (fileEntry == null) {
fileEntry = disk.addFile (fileName, fileType, auxType, created, modified,
buffer, eof);
}
catch (FileAlreadyExistsException e)
{ {
System.out.printf ("File %s not added%n", fileName); System.out.printf ("File %s not added%n", fileName);
break; break;
@ -196,7 +203,6 @@ public class NuFX
if (record.hasResource ()) if (record.hasResource ())
{ {
buffer = record.getResourceData (); buffer = record.getResourceData ();
// System.out.println (HexFormatter.format (buffer));
disk.addResourceFork (fileEntry, buffer, buffer.length); disk.addResourceFork (fileEntry, buffer, buffer.length);
} }
} }