fixed DateTime bug
This commit is contained in:
parent
3f2f1bfbca
commit
82381a6a47
|
@ -177,7 +177,7 @@ public class DiskFactory
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// e.printStackTrace ();
|
// e.printStackTrace ();
|
||||||
if (e.getMessage () == null)
|
if (e.getMessage () == null)
|
||||||
System.out.println (e);
|
System.out.println (e);
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,8 +9,7 @@ import com.bytezone.diskbrowser.utilities.Utility;
|
||||||
public class MasterHeader
|
public class MasterHeader
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final byte[] NuFile =
|
private static final byte[] NuFile = { 0x4E, (byte) 0xF5, 0x46, (byte) 0xE9, 0x6C, (byte) 0xE5 };
|
||||||
{ 0x4E, (byte) 0xF5, 0x46, (byte) 0xE9, 0x6C, (byte) 0xE5 };
|
|
||||||
private static final byte[] BIN2 = { 0x0A, 0x47, 0x4C };
|
private static final byte[] BIN2 = { 0x0A, 0x47, 0x4C };
|
||||||
|
|
||||||
private final int crc;
|
private final int crc;
|
||||||
|
@ -35,15 +34,6 @@ public class MasterHeader
|
||||||
if (Utility.isMagic (buffer, ptr, NuFile))
|
if (Utility.isMagic (buffer, ptr, NuFile))
|
||||||
break;
|
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))
|
if (isBin2 (buffer, ptr))
|
||||||
{
|
{
|
||||||
binary2Header = new Binary2Header (buffer, 0);
|
binary2Header = new Binary2Header (buffer, 0);
|
||||||
|
|
|
@ -21,8 +21,7 @@ public class NuFX
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static final String UNDERLINE =
|
private static final String UNDERLINE =
|
||||||
"------------------------------------------------------"
|
"------------------------------------------------------" + "-----------------------";
|
||||||
+ "-----------------------";
|
|
||||||
private MasterHeader masterHeader;
|
private MasterHeader masterHeader;
|
||||||
private final byte[] buffer;
|
private final byte[] buffer;
|
||||||
private final boolean debug = false;
|
private final boolean debug = false;
|
||||||
|
@ -182,14 +181,14 @@ public class NuFX
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
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,
|
||||||
fileName, fileType, auxType, eof, buffer.length, created, modified);
|
fileType, auxType, eof, buffer.length, created, modified);
|
||||||
|
|
||||||
FileEntry fileEntry;
|
FileEntry fileEntry;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileEntry = disk.addFile (fileName, fileType, auxType, created, modified,
|
fileEntry =
|
||||||
buffer, eof);
|
disk.addFile (fileName, fileType, auxType, created, modified, buffer, eof);
|
||||||
}
|
}
|
||||||
catch (FileAlreadyExistsException e)
|
catch (FileAlreadyExistsException e)
|
||||||
{
|
{
|
||||||
|
@ -267,8 +266,8 @@ public class NuFX
|
||||||
volumeName.volumeName, masterHeader.getCreated2 (), masterHeader.getModified2 (),
|
volumeName.volumeName, masterHeader.getCreated2 (), masterHeader.getModified2 (),
|
||||||
masterHeader.getTotalRecords ()));
|
masterHeader.getTotalRecords ()));
|
||||||
|
|
||||||
text.append (" Name Type Auxtyp Archived"
|
text.append (
|
||||||
+ " Fmat Size Un-Length\n");
|
" Name Type Auxtyp Archived" + " Fmat Size Un-Length\n");
|
||||||
|
|
||||||
text.append (String.format ("%s%n", UNDERLINE));
|
text.append (String.format ("%s%n", UNDERLINE));
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ import static com.bytezone.diskbrowser.prodos.ProdosConstants.TREE;
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
// - file does not already exist
|
// - file does not already exist
|
||||||
// - disk has no interleave
|
// - disk is not interleaved
|
||||||
|
// - blocks are 512 contiguous bytes
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
public class FileWriter
|
public class FileWriter
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
@ -99,30 +100,23 @@ public class FileWriter
|
||||||
private int getActualBlockNo (int logicalBlockNo) throws DiskFullException
|
private int getActualBlockNo (int logicalBlockNo) throws DiskFullException
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int actualBlockNo = 0;
|
|
||||||
|
|
||||||
switch (storageType)
|
switch (storageType)
|
||||||
{
|
{
|
||||||
case TREE:
|
case TREE:
|
||||||
actualBlockNo =
|
return masterIndexBlock.get (logicalBlockNo / 0x100).getPosition (logicalBlockNo % 0x100);
|
||||||
masterIndexBlock.get (logicalBlockNo / 0x100).getPosition (logicalBlockNo % 0x100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
if (logicalBlockNo < 0x100)
|
if (logicalBlockNo < 0x100)
|
||||||
actualBlockNo = indexBlock.getPosition (logicalBlockNo);
|
return indexBlock.getPosition (logicalBlockNo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEDLING:
|
case SEEDLING:
|
||||||
if (logicalBlockNo == 0)
|
if (logicalBlockNo == 0)
|
||||||
actualBlockNo = keyPointer;
|
return keyPointer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actualBlockNo == 0)
|
return register (logicalBlockNo);
|
||||||
actualBlockNo = register (logicalBlockNo);
|
|
||||||
|
|
||||||
return actualBlockNo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bytezone.diskbrowser.utilities;
|
package com.bytezone.diskbrowser.utilities;
|
||||||
|
|
||||||
|
import java.time.DateTimeException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@ -7,12 +8,11 @@ import java.time.format.DateTimeFormatter;
|
||||||
public class DateTime
|
public class DateTime
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private static String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
|
private static String[] months =
|
||||||
"Aug", "Sep", "Oct", "Nov", "Dec" };
|
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||||
private static String[] days = { "", "Sunday", "Monday", "Tuesday", "Wednesday",
|
private static String[] days =
|
||||||
"Thursday", "Friday", "Saturday" };
|
{ "", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
|
||||||
private static final DateTimeFormatter dtf =
|
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern ("dd-LLL-yy HH:mm");
|
||||||
DateTimeFormatter.ofPattern ("dd-LLL-yy HH:mm");
|
|
||||||
|
|
||||||
private final int second;
|
private final int second;
|
||||||
private final int minute;
|
private final int minute;
|
||||||
|
@ -40,8 +40,8 @@ public class DateTime
|
||||||
public String format ()
|
public String format ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second,
|
return String.format ("%02d:%02d:%02d %s %d %s %d", hour, minute, second, days[weekDay], day,
|
||||||
days[weekDay], day, months[month], year);
|
months[month], year);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -56,10 +56,15 @@ public class DateTime
|
||||||
public LocalDateTime getLocalDateTime ()
|
public LocalDateTime getLocalDateTime ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int adjustedYear = year + (year > 70 ? 1900 : 2000);
|
try
|
||||||
if (day < 0 || day > 30)
|
{
|
||||||
|
int adjustedYear = year + (year > 70 ? 1900 : 2000);
|
||||||
|
return LocalDateTime.of (adjustedYear, month + 1, day + 1, hour, minute);
|
||||||
|
}
|
||||||
|
catch (DateTimeException e)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
return LocalDateTime.of (adjustedYear, month + 1, day + 1, hour, minute);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -67,8 +72,7 @@ public class DateTime
|
||||||
public String toString ()
|
public String toString ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour
|
return "DateTime [second=" + second + ", minute=" + minute + ", hour=" + hour + ", year=" + year
|
||||||
+ ", year=" + year + ", day=" + day + ", month=" + month + ", weekDay=" + weekDay
|
+ ", day=" + day + ", month=" + month + ", weekDay=" + weekDay + "]";
|
||||||
+ "]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue