[Scummvm-git-logs] scummvm-web master -> 5620eda7992159984a5df1cc3b12dd687d98ad87

djsrv dservilla at gmail.com
Fri Nov 5 01:38:30 UTC 2021


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

Summary:
19e57ddb7c DUMPER: Fix noscript message margin
ee2c4a105c DUMPER: Add missing semicolons
5620eda799 DUMPER: Add punycoder


Commit: 19e57ddb7ce2a71479c9460a58f87eae632e50ee
    https://github.com/scummvm/scummvm-web/commit/19e57ddb7ce2a71479c9460a58f87eae632e50ee
Author: djsrv (dservilla at gmail.com)
Date: 2021-11-04T17:42:00-04:00

Commit Message:
DUMPER: Fix noscript message margin

Changed paths:
    public_html/html/dumper-companion.html


diff --git a/public_html/html/dumper-companion.html b/public_html/html/dumper-companion.html
index 448bc85c..6e713105 100644
--- a/public_html/html/dumper-companion.html
+++ b/public_html/html/dumper-companion.html
@@ -21,12 +21,12 @@
       </p>
       <p>THIS WORKS ENTIRELY IN YOUR WEB BROWSER. NO DATA IS TRANSFERRED TO ANY SERVER.</p>
     </div>
-    <div id="app"></div>
-    <noscript>
-      <div class="box">
-        <p>Dumper Companion requires JavaScript.</p>
-      </div>
-    </noscript>
+    <div id="app">
+      <noscript>
+        <div class="box">
+          <p>Dumper Companion requires JavaScript.</p>
+        </div>
+      </noscript>
     </div>
   </main>
   <script src="/js/dumper-companion.js"></script>


Commit: ee2c4a105cdf220337b24ebeab65b3d570bcd90f
    https://github.com/scummvm/scummvm-web/commit/ee2c4a105cdf220337b24ebeab65b3d570bcd90f
Author: djsrv (dservilla at gmail.com)
Date: 2021-11-04T18:00:41-04:00

Commit Message:
DUMPER: Add missing semicolons

Changed paths:
    dumper-companion/src/DumperCompanionApp.tsx


diff --git a/dumper-companion/src/DumperCompanionApp.tsx b/dumper-companion/src/DumperCompanionApp.tsx
index 5096bf73..bff91262 100644
--- a/dumper-companion/src/DumperCompanionApp.tsx
+++ b/dumper-companion/src/DumperCompanionApp.tsx
@@ -3,7 +3,7 @@ import { fs } from '@zip.js/zip.js/lib/zip-fs.js';
 import { Volume } from './hfs/main';
 import { Language, getLanguages } from './encoding';
 
-export type Props = {}
+export type Props = {};
 
 export type State = {
     image: File;
@@ -12,7 +12,7 @@ export type State = {
     busy: boolean;
     unicode: boolean;
     logs: ComponentChild[];
-}
+};
 
 export default class DumperCompanionApp extends Component<Props, State> {
     constructor() {


Commit: 5620eda7992159984a5df1cc3b12dd687d98ad87
    https://github.com/scummvm/scummvm-web/commit/5620eda7992159984a5df1cc3b12dd687d98ad87
Author: djsrv (dservilla at gmail.com)
Date: 2021-11-04T21:17:49-04:00

Commit Message:
DUMPER: Add punycoder

Changed paths:
  A dumper-companion/src/App.tsx
  A dumper-companion/src/Dumper.tsx
  A dumper-companion/src/Punycoder.tsx
  A dumper-companion/src/index.tsx
  R dumper-companion/src/DumperCompanionApp.tsx
  R dumper-companion/src/app.tsx
    dumper-companion/src/encoding.ts
    dumper-companion/style.css
    dumper-companion/webpack.config.js
    public_html/html/dumper-companion.html


diff --git a/dumper-companion/src/App.tsx b/dumper-companion/src/App.tsx
new file mode 100644
index 00000000..3a119e5d
--- /dev/null
+++ b/dumper-companion/src/App.tsx
@@ -0,0 +1,16 @@
+import { Component, ComponentChild } from 'preact';
+import Dumper from './Dumper';
+import Punycoder from './Punycoder';
+
+export type Props = {};
+
+export type State = {};
+
+export default class App extends Component<Props, State> {
+    render(): ComponentChild {
+        return <div class="app">
+            <Dumper/>
+            <Punycoder/>
+        </div>;
+    }
+}
diff --git a/dumper-companion/src/DumperCompanionApp.tsx b/dumper-companion/src/Dumper.tsx
similarity index 97%
rename from dumper-companion/src/DumperCompanionApp.tsx
rename to dumper-companion/src/Dumper.tsx
index bff91262..4ef5d33f 100644
--- a/dumper-companion/src/DumperCompanionApp.tsx
+++ b/dumper-companion/src/Dumper.tsx
@@ -14,7 +14,7 @@ export type State = {
     logs: ComponentChild[];
 };
 
-export default class DumperCompanionApp extends Component<Props, State> {
+export default class Dumper extends Component<Props, State> {
     constructor() {
         super();
         this.state = {
@@ -32,7 +32,7 @@ export default class DumperCompanionApp extends Component<Props, State> {
     }
 
     render(): ComponentChild {
-        return <div class="io">
+        return <div class="dumper">
             <div class="in box">
                 <h2>Input</h2>
 
diff --git a/dumper-companion/src/Punycoder.tsx b/dumper-companion/src/Punycoder.tsx
new file mode 100644
index 00000000..c2833f64
--- /dev/null
+++ b/dumper-companion/src/Punycoder.tsx
@@ -0,0 +1,67 @@
+import { Component, ComponentChild } from 'preact';
+import * as punycode from 'punycode/';
+import { escapeString, unescapeString } from './encoding';
+
+export type Props = {};
+
+export type State = {
+    text: string;
+};
+
+export default class Punycoder extends Component<Props, State> {
+    constructor() {
+        super();
+        this.state = {
+            text: ''
+        };
+    }
+
+    render(): ComponentChild {
+        return <div class="punycoder box">
+            <h2>Punycoder</h2>
+            <p>
+                For platforms that don't support Unicode file names, ScummVM uses
+                a variant of <a href="https://en.wikipedia.org/wiki/Punycode">Punycode</a>.
+                You can use this to manually encode/decode file names:
+            </p>
+            <div>
+                <input type="text" placeholder="File name" value={this.state.text} onInput={this.handleText.bind(this)}></input>
+                <button onClick={this.encode.bind(this)}>Encode</button>
+                <button onClick={this.decode.bind(this)}>Decode</button>
+            </div>
+        </div>;
+    }
+
+    handleText(e: Event): void {
+        const text = (e.target as HTMLInputElement).value;
+        this.setState(() => ({ text }));
+    }
+
+    encode(): void {
+        this.setState({
+            text: 'xn--' + punycode.encode(escapeString(this.state.text))
+        });
+    }
+
+    decode(): void {
+        if (!this.state.text.startsWith("xn--")) {
+            this.invalidPunycode();
+            return;
+        }
+
+        const input = this.state.text.slice(4);
+        try {
+            this.setState({
+                text: unescapeString(punycode.decode(input))
+            });
+        } catch (e) {
+            this.invalidPunycode();
+        }
+    }
+
+    invalidPunycode(): void {
+        this.setState({
+            text: 'Invalid Punycode!'
+        });
+    }
+}
diff --git a/dumper-companion/src/app.tsx b/dumper-companion/src/app.tsx
deleted file mode 100644
index d4c4755f..00000000
--- a/dumper-companion/src/app.tsx
+++ /dev/null
@@ -1,4 +0,0 @@
-import { render } from 'preact';
-import DumperCompanionApp from './DumperCompanionApp';
-
-render(<DumperCompanionApp/>, document.getElementById('app'));
diff --git a/dumper-companion/src/encoding.ts b/dumper-companion/src/encoding.ts
index 7b3ed33c..27c1946a 100644
--- a/dumper-companion/src/encoding.ts
+++ b/dumper-companion/src/encoding.ts
@@ -43,7 +43,7 @@ export function decodeLanguage(str: Uint8Array, lang: Language): string {
 }
 
 
-function escapeString(str: string): string {
+export function escapeString(str: string): string {
     let res = '';
     for (const ch of str) {
         if (ch == '\x81') {
@@ -60,6 +60,24 @@ function escapeString(str: string): string {
     return res;
 }
 
+export function unescapeString(str: string): string {
+    const chars = Array.from(str);
+    let res = '';
+    for (let i = 0; i < chars.length; i++) {
+        if (chars[i] == '\x81' && i + 1 < chars.length) {
+            i++;
+            if (chars[i] == '\x79') {
+                res += '\x81';
+            } else {
+                res += String.fromCodePoint(codePoint(chars[i]) - 0x80);
+            }
+        } else {
+            res += chars[i] ;
+        }
+    }
+    return res;
+}
+
 function needsPunycode(str: string) {
     // Windows file names cannot end with space or period
     if (str.endsWith(' ') || str.endsWith('.'))
diff --git a/dumper-companion/src/index.tsx b/dumper-companion/src/index.tsx
new file mode 100644
index 00000000..c0c40989
--- /dev/null
+++ b/dumper-companion/src/index.tsx
@@ -0,0 +1,4 @@
+import { render } from 'preact';
+import App from './App';
+
+render(<App/>, document.getElementById('app-container'));
diff --git a/dumper-companion/style.css b/dumper-companion/style.css
index 1c253a54..786b1d1e 100644
--- a/dumper-companion/style.css
+++ b/dumper-companion/style.css
@@ -10,7 +10,7 @@ h2 {
     margin: 0;
 }
 
-p, .in div {
+p, .box div {
     display: block;
     margin-top: 0.75em;
     margin-bottom: 0;
@@ -47,6 +47,11 @@ main {
     grid-gap: 20px;
 }
 
+.app {
+    display: grid;
+    grid-gap: 20px;
+}
+
 .box {
     background-color: #eee;
     border: 1px solid #000;
@@ -54,7 +59,7 @@ main {
     padding: 20px;
 }
 
-.io {
+.dumper {
     display: grid;
     grid: auto-flow / 1fr 1fr;
     grid-gap: 20px;
@@ -85,3 +90,11 @@ input[type="checkbox"] {
     margin-bottom: 0;
     padding: 0;
 }
+
+.punycoder input[type="text"] {
+    width: 360px;
+}
+
+.punycoder button {
+    margin-left: 8px;
+}
diff --git a/dumper-companion/webpack.config.js b/dumper-companion/webpack.config.js
index 696369ac..a1d54e93 100644
--- a/dumper-companion/webpack.config.js
+++ b/dumper-companion/webpack.config.js
@@ -2,7 +2,7 @@ const TerserPlugin = require('terser-webpack-plugin');
 
 module.exports = {
   context: __dirname + "/src",
-  entry: "./app.tsx",
+  entry: "./index.tsx",
   output: {
     path: __dirname,
     filename: "index.js"
diff --git a/public_html/html/dumper-companion.html b/public_html/html/dumper-companion.html
index 6e713105..71420b8d 100644
--- a/public_html/html/dumper-companion.html
+++ b/public_html/html/dumper-companion.html
@@ -21,7 +21,7 @@
       </p>
       <p>THIS WORKS ENTIRELY IN YOUR WEB BROWSER. NO DATA IS TRANSFERRED TO ANY SERVER.</p>
     </div>
-    <div id="app">
+    <div id="app-container">
       <noscript>
         <div class="box">
           <p>Dumper Companion requires JavaScript.</p>




More information about the Scummvm-git-logs mailing list