fixed DateTime bug

This commit is contained in:
Denis Molony 2022-08-10 18:06:43 +10:00
parent 3f2f1bfbca
commit 82381a6a47
5 changed files with 33 additions and 46 deletions

View File

@ -177,7 +177,7 @@ public class DiskFactory
}
catch (Exception e)
{
// e.printStackTrace ();
// e.printStackTrace ();
if (e.getMessage () == null)
System.out.println (e);
else

View File

@ -9,8 +9,7 @@ import com.bytezone.diskbrowser.utilities.Utility;
public class MasterHeader
// -----------------------------------------------------------------------------------//
{
private static final byte[] NuFile =
{ 0x4E, (byte) 0xF5, 0x46, (byte) 0xE9, 0x6C, (byte) 0xE5 };
private static final byte[] NuFile = { 0x4E, (byte) 0xF5, 0x46, (byte) 0xE9, 0x6C, (byte) 0xE5 };
private static final byte[] BIN2 = { 0x0A, 0x47, 0x4C };
private final int crc;
@ -35,15 +34,6 @@ public class MasterHeader
if (Utility.isMagic (buffer, ptr, NuFile))
break;
// internet.shk has 0x2000 bytes of text at the start
// if (Utility.isMagic (buffer, 0x2000, NuFile))
// {
// System.out.println ("found it");
// ptr = 0x2000;
// bin2 = true;
// break;
// }
if (isBin2 (buffer, ptr))
{
binary2Header = new Binary2Header (buffer, 0);

View File

@ -21,8 +21,7 @@ public class NuFX
// -----------------------------------------------------------------------------------//
{
private static final String UNDERLINE =
"------------------------------------------------------"
+ "-----------------------";
"------------------------------------------------------" + "-----------------------";
private MasterHeader masterHeader;
private final byte[] buffer;
private final boolean debug = false;
@ -182,14 +181,14 @@ public class NuFX
}
if (debug)
System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count,
fileName, fileType, auxType, eof, buffer.length, created, modified);
System.out.printf ("%3d %-35s %02X %,7d %,7d %,7d %s %s%n", ++count, fileName,
fileType, auxType, eof, buffer.length, created, modified);
FileEntry fileEntry;
try
{
fileEntry = disk.addFile (fileName, fileType, auxType, created, modified,
buffer, eof);
fileEntry =
disk.addFile (fileName, fileType, auxType, created, modified, buffer, eof);
}
catch (FileAlreadyExistsException e)
{
@ -267,8 +266,8 @@ public class NuFX
volumeName.volumeName, masterHeader.getCreated2 (), masterHeader.getModified2 (),
masterHeader.getTotalRecords ()));
text.append (" Name Type Auxtyp Archived"
+ " Fmat Size Un-Length\n");
text.append (
" Name Type Auxtyp Archived" + " Fmat Size Un-Length\n");
text.append (String.format ("%s%n", UNDERLINE));

View File

@ -7,7 +7,8 @@ import static com.bytezone.diskbrowser.prodos.ProdosConstants.TREE;
// Assumptions:
// - file does not already exist
// - disk has no interleave
// - disk is not interleaved
// - blocks are 512 contiguous bytes
// -----------------------------------------------------------------------------------//
public class FileWriter
// -----------------------------------------------------------------------------------//
@ -99,30 +100,23 @@ public class FileWriter
private int getActualBlockNo (int logicalBlockNo) throws DiskFullException
// ---------------------------------------------------------------------------------//
{
int actualBlockNo = 0;
switch (storageType)
{
case TREE:
actualBlockNo =
masterIndexBlock.get (logicalBlockNo / 0x100).getPosition (logicalBlockNo % 0x100);
break;
return masterIndexBlock.get (logicalBlockNo / 0x100).getPosition (logicalBlockNo % 0x100);
case SAPLING:
if (logicalBlockNo < 0x100)
actualBlockNo = indexBlock.getPosition (logicalBlockNo);
return indexBlock.getPosition (logicalBlockNo);
break;
case SEEDLING:
if (logicalBlockNo == 0)
actualBlockNo = keyPointer;
return keyPointer;
break;
}
if (actualBlockNo == 0)
actualBlockNo = register (logicalBlockNo);
return actualBlockNo;
return register (logicalBlockNo);
}
// ---------------------------------------------------------------------------------//

View File

@ -1,5 +1,6 @@
package com.bytezone.diskbrowser.utilities;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@ -7,12 +8,11 @@ import java.time.format.DateTimeFormatter;
public class DateTime
// -----------------------------------------------------------------------------------//
{
private static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec" };
private static String[] days = { "", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" };
private static final DateTimeFormatter dtf =
DateTimeFormatter.ofPattern ("dd-LLL-yy HH:mm");
private static String[] months =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
private static String[] days =
{ "", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern ("dd-LLL-yy HH:mm");
private final int second;
private final int minute;
@ -40,8 +40,8 @@ public class DateTime
public String format ()
// ---------------------------------------------------------------------------------//
{
return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second,
days[weekDay], day, months[month], year);
return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second, days[weekDay], day,
months[month], year);
}
// ---------------------------------------------------------------------------------//
@ -56,10 +56,15 @@ public class DateTime
public LocalDateTime getLocalDateTime ()
// ---------------------------------------------------------------------------------//
{
int adjustedYear = year + (year > 70 ? 1900 : 2000);
if (day < 0 || day > 30)
try
{
int adjustedYear = year + (year > 70 ? 1900 : 2000);
return LocalDateTime.of (adjustedYear, month + 1, day + 1, hour, minute);
}
catch (DateTimeException e)
{
return null;
return LocalDateTime.of (adjustedYear, month + 1, day + 1, hour, minute);
}
}
// ---------------------------------------------------------------------------------//
@ -67,8 +72,7 @@ public class DateTime
public String toString ()
// ---------------------------------------------------------------------------------//
{
return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour
+ ", year=" + year + ", day=" + day + ", month=" + month + ", weekDay=" + weekDay
+ "]";
return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour + ", year=" + year
+ ", day=" + day + ", month=" + month + ", weekDay=" + weekDay + "]";
}
}