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,
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);

View File

@ -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);
}
}