[Scummvm-git-logs] scummvm-web master -> 26ba196db17c3d3b3f39b8ef7f78b29f4cdc3884

djsrv dservilla at gmail.com
Fri Nov 5 05:25:41 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-web' repo located at https://github.com/scummvm/scummvm-web .

Summary:
26ba196db1 DUMPER: Add Mac Japanese to Roman fallback


Commit: 26ba196db17c3d3b3f39b8ef7f78b29f4cdc3884
    https://github.com/scummvm/scummvm-web/commit/26ba196db17c3d3b3f39b8ef7f78b29f4cdc3884
Author: djsrv (dservilla at gmail.com)
Date: 2021-11-05T01:24:48-04:00

Commit Message:
DUMPER: Add Mac Japanese to Roman fallback

Changed paths:
    dumper-companion/src/Dumper.tsx
    dumper-companion/src/encoding.ts
    dumper-companion/src/hfs/directory.ts


diff --git a/dumper-companion/src/Dumper.tsx b/dumper-companion/src/Dumper.tsx
index 4ef5d33f..e32735ed 100644
--- a/dumper-companion/src/Dumper.tsx
+++ b/dumper-companion/src/Dumper.tsx
@@ -12,6 +12,8 @@ export type State = {
     busy: boolean;
     unicode: boolean;
     logs: ComponentChild[];
+    dumpPercent: number;
+    lastLogWasDumpPercent: boolean;
 };
 
 export default class Dumper extends Component<Props, State> {
@@ -23,7 +25,9 @@ export default class Dumper extends Component<Props, State> {
             lang: Language.EN,
             unicode: true,
             busy: false,
-            logs: []
+            logs: [],
+            dumpPercent: -1,
+            lastLogWasDumpPercent: false
         };
     }
 
@@ -69,15 +73,24 @@ export default class Dumper extends Component<Props, State> {
         if (msg instanceof Error) {
             msg = msg.toString();
         }
-        this.setState(({ logs }) => ({ logs: [...logs, <li>{msg}</li>] }), callback);
+        this.setState(({ logs }) => ({
+            logs: [...logs, <li>{msg}</li>],
+            lastLogWasDumpPercent: false
+        }), callback);
     }
 
-    replaceLastLog(msg: ComponentChild | Error, callback?: () => void): void {
-        console.log(msg);
-        if (msg instanceof Error) {
-            msg = msg.toString();
+    updateDumpPercent(percent: number, callback?: () => void): void {
+        if (percent !== this.state.dumpPercent) {
+            const msg = `Dumping volume... ${percent}%`;
+            console.log(msg);
+            this.setState(({ logs, lastLogWasDumpPercent }) => ({
+                logs: lastLogWasDumpPercent
+                    ? [...logs.slice(0, -1), <li>{msg}</li>]
+                    : [...logs, <li>{msg}</li>],
+                dumpPercent: percent,
+                lastLogWasDumpPercent: true
+            }), callback);
         }
-        this.setState(({ logs }) => ({ logs: [...logs.slice(0, -1), <li>{msg}</li>] }), callback);
     }
 
     handleImage(e: Event): void {
@@ -115,21 +128,21 @@ export default class Dumper extends Component<Props, State> {
                 this.dumpVolume(volume);
             } catch (err) {
                 this.log(err);
-                this.setState(() => ({ busy: false }));
+                this.setState(() => ({ busy: false, dumpPercent: -1 }));
             }
         });
     }
 
     dumpVolume(volume: Volume): void {
-        this.log('Dumping volume... 0%', async () => {
+        this.updateDumpPercent(0, async () => {
             try {
                 const zipFS = new fs.FS();
-                volume.dumpToZip(zipFS.root, this.state.lang, !this.state.unicode);
+                volume.dumpToZip(zipFS.root, this.state.lang, !this.state.unicode, this.log.bind(this));
                 const blob = await zipFS.exportBlob({
                     level: 0,
                     onprogress: (index, max) => {
                         const percent = Math.floor(index / max * 100);
-                        this.replaceLastLog(`Dumping volume... ${percent}%`);
+                        this.updateDumpPercent(percent);
                     }
                 });
                 const volumeURL = URL.createObjectURL(blob);
@@ -140,7 +153,7 @@ export default class Dumper extends Component<Props, State> {
             } catch (err) {
                 this.log(err);
             }
-            this.setState(() => ({ busy: false }));
+            this.setState(() => ({ busy: false, dumpPercent: -1 }));
         });
     }
 }
diff --git a/dumper-companion/src/encoding.ts b/dumper-companion/src/encoding.ts
index 27c1946a..3a6f69e7 100644
--- a/dumper-companion/src/encoding.ts
+++ b/dumper-companion/src/encoding.ts
@@ -23,7 +23,7 @@ export function getLanguages(): string[] {
 }
 
 
-export function decodeLanguage(str: Uint8Array, lang: Language): string {
+export function decodeLanguage(str: Uint8Array, lang: Language, log: (string) => void): string {
     switch (lang) {
     case Language.DA:
     case Language.NL:
@@ -38,7 +38,7 @@ export function decodeLanguage(str: Uint8Array, lang: Language): string {
     case Language.SE:
         return decodeMacRoman(str);
     case Language.JP:
-        return decodeMacJapanese(str);
+        return decodeMacJapanese(str, log);
     }
 }
 
@@ -90,8 +90,8 @@ function needsPunycode(str: string) {
 }
 
 
-export function encodeFileName(str: Uint8Array, lang: Language, puny: boolean): string {
-    const unicodeStr = decodeLanguage(str, lang);
+export function encodeFileName(str: Uint8Array, lang: Language, puny: boolean, log: (string) => void): string {
+    const unicodeStr = decodeLanguage(str, lang, log);
 
     const forcePunycode = needsPunycode(unicodeStr);
     if (puny || forcePunycode) {
@@ -183,7 +183,7 @@ const macJapaneseMap = {
     'ed': ['ァ',,'ィ',,'ゥ',,'ェ',,'ォ',,,,,,,,,,,,,,,,,,,,,,,,,,'ッ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'ャ',,'ュ',,'ョ',,,,,,,'ヮ',,,,,,,'ヵ','ヶ']
 };
 
-export function decodeMacJapanese(str: Uint8Array): string {
+export function decodeMacJapanese(str: Uint8Array, log: (string) => void): string {
     let res = '';
     for (let i = 0; i < str.length; i++) {
         const hi = str[i];
@@ -194,15 +194,19 @@ export function decodeMacJapanese(str: Uint8Array): string {
         } else if ((0x81 <= hi && hi <= 0x9F) || (0xE0 <= hi && hi <= 0xFC)) { // two-byte sequence
             i++;
             if (i >= str.length) {
-                throw new Error('Mac Japanese sequence missing second byte');
-            }
-            const lo = str[i];
-            const hiKey = hi.toString(16);
-            const loKey = lo - 0x40;
-            if (macJapaneseMap[hiKey] == null || macJapaneseMap[hiKey][loKey] == null) {
-                throw new Error(`No mapping for Mac Japanese sequence 0x${byteToHex(hi)}${byteToHex(lo)}`);
+                log(`Warning: Mac Japanese sequence 0x${byteToHex(hi)}XX missing second byte, decoding as Mac Roman`);
+                return decodeMacRoman(str);
+            } else {
+                const lo = str[i];
+                const hiKey = hi.toString(16);
+                const loKey = lo - 0x40;
+                if (macJapaneseMap[hiKey] == null || macJapaneseMap[hiKey][loKey] == null) {
+                    log(`Warning: No mapping for Mac Japanese sequence 0x${byteToHex(hi)}${byteToHex(lo)}, decoding as Mac Roman`);
+                    return decodeMacRoman(str);
+                } else {
+                    res += macJapaneseMap[hiKey][loKey];
+                }
             }
-            res += macJapaneseMap[hiKey][loKey];
         } else if (hi === 0xA0) { // no-break space
             res += '\u00A0';
         } else if (hi >= 0xA1 && hi <= 0xDF) { // Katakana
diff --git a/dumper-companion/src/hfs/directory.ts b/dumper-companion/src/hfs/directory.ts
index c0776bdc..7507ed2e 100644
--- a/dumper-companion/src/hfs/directory.ts
+++ b/dumper-companion/src/hfs/directory.ts
@@ -85,11 +85,11 @@ export class AbstractFolder {
         return res;
     }
 
-    dumpToZip(zipDir: any, lang: Language, puny: boolean): void {
+    dumpToZip(zipDir: any, lang: Language, puny: boolean, log: (string) => void): void {
         for (const [name, child] of this.items()) {
-            const encodedName = encodeFileName(name, lang, puny);
+            const encodedName = encodeFileName(name, lang, puny, log);
             if (child instanceof AbstractFolder) {
-                child.dumpToZip(zipDir.addDirectory(encodedName), lang, puny);
+                child.dumpToZip(zipDir.addDirectory(encodedName), lang, puny, log);
             } else {
                 zipDir.addUint8Array(encodedName, child.toBinary(name));
             }




More information about the Scummvm-git-logs mailing list