From 06c76ed1c3602fc76b9d7c3794e837e0f99ecebf Mon Sep 17 00:00:00 2001 From: Rob Greene Date: Sat, 25 Jun 2022 20:04:27 -0500 Subject: [PATCH] Adding support for GS/OS mixed case names. #84 --- .../storage/os/prodos/ProdosFileEntry.java | 160 ++++++++++-------- .../os/prodos/ProdosFileEntryTest.java | 69 ++++++++ 2 files changed, 159 insertions(+), 70 deletions(-) create mode 100644 lib/ac-api/src/test/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFileEntryTest.java diff --git a/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFileEntry.java b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFileEntry.java index 060391d..d2e10e6 100644 --- a/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFileEntry.java +++ b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/os/prodos/ProdosFileEntry.java @@ -24,6 +24,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.function.Function; import com.webcodepro.applecommander.storage.DiskFullException; import com.webcodepro.applecommander.storage.FileEntry; @@ -61,13 +62,14 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry { /** * Return the name of this file. - * This handles normal files, deleted files, and AppleWorks files - which use - * the AUXTYPE attribute to indicate upper/lowercase in the filename. + * This handles normal files, deleted files, AppleWorks files - which use + * the AUXTYPE attribute to indicate upper/lowercase in the filename, and + * GS/OS casing which is in the ProDOS version flags. + * Note that we don't do mixed case for deleted files. */ public String getFilename() { - String fileName; if (isDeleted()) { - fileName = AppleUtil.getString(readFileEntry(), 1, 15); + String fileName = AppleUtil.getString(readFileEntry(), 1, 15); StringBuffer buf = new StringBuffer(); for (int i=0; i> 8), 7-(i%8)); - } - if (lowerCase) { - char ch = mixedCase.charAt(i); - if (ch == '.') { - mixedCase.setCharAt(i, ' '); - } else { - mixedCase.setCharAt(i, Character.toLowerCase(ch)); - } - } - } - fileName = mixedCase.toString(); - } - // GS/OS upper/lower case mix - if ((getMinimumProdosVersion() & 0x80) != 0) { - int flags = getMinimumProdosVersion() << 8 | getProdosVersion(); - int bit = 1 << 14; // 1st bit in 16 bit number is enablement flag, so skipping it - StringBuffer mixedCase = new StringBuffer(fileName); - for (int i=0; i<16 && i bitPosition) { + StringBuffer mixedCase = new StringBuffer(original); + for (int i=0; i>= 1; - } - fileName = mixedCase.toString(); - } - return fileName; + } + } + return mixedCase.toString(); } /** @@ -137,31 +137,51 @@ public class ProdosFileEntry extends ProdosCommonEntry implements FileEntry { /** * Set the name of this file. + * This handles normal files, deleted files, AppleWorks files - which use + * the AUXTYPE attribute to indicate upper/lowercase in the filename, and + * GS/OS casing which is in the ProDOS version flags. */ public void setFilename(String filename) { - byte[] fileEntry = readFileEntry(); - if (isDeleted()) { - AppleUtil.setString(fileEntry, 1, filename.toUpperCase(), 15); - } else { - AppleUtil.setProdosString(fileEntry, 0, filename.toUpperCase(), 15); - } + // 1. Set the upper/lowercase flags if (isAppleWorksFile()) { - byte lowByte = 0; - byte highByte = 0; - for (int i=0; i> 8); + setProdosVersion(flags); + + // 2. Set the filename details as the result should be all uppercase. + byte[] fileEntry = readFileEntry(); + if (isDeleted()) { + AppleUtil.setString(fileEntry, 1, filename.toUpperCase(), 15); + } else { + AppleUtil.setProdosString(fileEntry, 0, filename.toUpperCase(), 15); + } writeFileEntry(fileEntry); } + static int setMixedCaseFlags(StringBuilder filename, Function bitPosition) { + int flags = 0; + for (int i=0; i