[Scummvm-git-logs] scummvm master -> e6c582fe0f107fef643a04ae11a9dc8d8d105d00

sev- sev at scummvm.org
Tue Jul 27 16:38:39 UTC 2021


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

Summary:
91d747ac5b COMMON: Initial code for punycode decoding
73fd4a44e6 DEVTOOLS: Remove ambiguity in escaping 0x81 in dumper companion
56f7af8d2e COMMON: Fix punycode decoding and implement reverse utility for escaped filenames
a655cff203 COMMON: Added auxiliary methods for punycode
191bc979a9 COMMON: Always return the original string on failed punycode decoding
8789bdfd67 COMMON: Reworked encode_punycode to String
81b7702722 DEVTOOLS: Do not encode "'" to punycode
cd3f703988 COMMON: Fix punycode encoding
3b2d55f36e DIRECTOR: Use original file names for The Apartment
0b1c95aadf JANITORIAL: Remove trailing whitespaces
f3145d0fb6 COMMON: Decode filenames from Punycode upon returning
96bb4d2d53 COMMON: Added more auxiliary method to Punycode
2fce9db178 DIRECTOR: Do not convert '/' in paths
e6429a1213 COMMON: Fix punycode encoding
92517fc3f5 DEVTOOLS: Synchronize encoding for punycode in different tool modes
530354492a COMMON: Fix encode_punycode to match the perl code
e6c582fe0f DIRECTOR: Make movie file names printable


Commit: 91d747ac5bc43ba573b6bcb5b03cf7189e30426f
    https://github.com/scummvm/scummvm/commit/91d747ac5bc43ba573b6bcb5b03cf7189e30426f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:48+02:00

Commit Message:
COMMON: Initial code for punycode decoding

Changed paths:
  A common/punycode.cpp
  A common/punycode.h
    common/module.mk


diff --git a/common/module.mk b/common/module.mk
index 7dd158de89..4ac4ba5d58 100644
--- a/common/module.mk
+++ b/common/module.mk
@@ -28,6 +28,7 @@ MODULE_OBJS := \
 	mutex.o \
 	osd_message_queue.o \
 	platform.o \
+	punycode.o \
 	quicktime.o \
 	random.o \
 	rational.o \
diff --git a/common/punycode.cpp b/common/punycode.cpp
new file mode 100644
index 0000000000..cec656f025
--- /dev/null
+++ b/common/punycode.cpp
@@ -0,0 +1,286 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/**
+ * Copyright (C) 2011 by Ben Noordhuis <info at bnoordhuis.nl>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "common/punycode.h"
+#include "common/util.h"
+
+namespace Common {
+
+/* punycode parameters, see http://tools.ietf.org/html/rfc3492#section-5 */
+#define BASE 36
+#define TMIN 1
+#define TMAX 26
+#define SKEW 38
+#define DAMP 700
+#define INITIAL_N 128
+#define INITIAL_BIAS 72
+
+static uint32_t adapt_bias(uint32_t delta, unsigned n_points, int is_first) {
+	uint32_t k;
+
+	delta /= is_first ? DAMP : 2;
+	delta += delta / n_points;
+
+	/* while delta > 455: delta /= 35 */
+	for (k = 0; delta > ((BASE - TMIN) * TMAX) / 2; k += BASE) {
+		delta /= (BASE - TMIN);
+	}
+
+	return k + (((BASE - TMIN + 1) * delta) / (delta + SKEW));
+}
+
+static char encode_digit(int c) {
+	assert(c >= 0 && c <= BASE - TMIN);
+	if (c > 25) {
+		return c + 22; /* '0'..'9' */
+	} else {
+		return c + 'a'; /* 'a'..'z' */
+	}
+}
+
+/* Encode as a generalized variable-length integer. Returns number of bytes written. */
+static size_t encode_var_int(const size_t bias, const size_t delta, char *const dst, size_t dstlen) {
+	size_t i, k, q, t;
+
+	i = 0;
+	k = BASE;
+	q = delta;
+
+	while (i < dstlen) {
+		if (k <= bias) {
+			t = TMIN;
+		} else if (k >= bias + TMAX) {
+			t = TMAX;
+		} else {
+			t = k - bias;
+		}
+
+		if (q < t) {
+			break;
+		}
+
+		dst[i++] = encode_digit(t + (q - t) % (BASE - t));
+
+		q = (q - t) / (BASE - t);
+		k += BASE;
+	}
+
+	if (i < dstlen) {
+		dst[i++] = encode_digit(q);
+	}
+
+	return i;
+}
+
+static size_t decode_digit(uint32_t v) {
+	if (Common::isDigit(v)) {
+		return 22 + (v - '0');
+	}
+	if (Common::isLower(v)) {
+		return v - 'a';
+	}
+	if (Common::isUpper(v)) {
+		return v - 'A';
+	}
+	return SIZE_MAX;
+}
+
+size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *const dst, size_t *const dstlen) {
+	size_t b, h;
+	size_t delta, bias;
+	size_t m, n;
+	size_t si, di;
+
+	for (si = 0, di = 0; si < srclen && di < *dstlen; si++) {
+		if (src[si] < 128) {
+			dst[di++] = src[si];
+		}
+	}
+
+	b = h = di;
+
+	/* Write out delimiter if any basic code points were processed. */
+	if (di > 0 && di < *dstlen) {
+		dst[di++] = '-';
+	}
+
+	n = INITIAL_N;
+	bias = INITIAL_BIAS;
+	delta = 0;
+
+	for (; h < srclen && di < *dstlen; n++, delta++) {
+		/* Find next smallest non-basic code point. */
+		for (m = SIZE_MAX, si = 0; si < srclen; si++) {
+			if (src[si] >= n && src[si] < m) {
+				m = src[si];
+			}
+		}
+
+		if ((m - n) > (SIZE_MAX - delta) / (h + 1)) {
+			/* OVERFLOW */
+			assert(0 && "OVERFLOW");
+			goto fail;
+		}
+
+		delta += (m - n) * (h + 1);
+		n = m;
+
+		for (si = 0; si < srclen; si++) {
+			if (src[si] < n) {
+				if (++delta == 0) {
+					/* OVERFLOW */
+					assert(0 && "OVERFLOW");
+					goto fail;
+				}
+			}
+			else if (src[si] == n) {
+				di += encode_var_int(bias, delta, &dst[di], *dstlen - di);
+				bias = adapt_bias(delta, h + 1, h == b);
+				delta = 0;
+				h++;
+			}
+		}
+	}
+
+fail:
+	/* Tell the caller how many bytes were written to the output buffer. */
+	*dstlen = di;
+
+	/* Return how many Unicode code points were converted. */
+	return si;
+}
+
+String punycode_decode(const String src1) {
+	if (!src1.hasPrefix("xn--"))
+		return src1;
+
+	String src(src1.c_str()[4]); // Skip the prefix for simplification
+
+	int srclen = src1.size();
+	String dst;
+
+	/* Ensure that the input contains only ASCII characters. */
+	for (int si = 0; si < srclen; si++) {
+		if (src[si] & 0x80) {
+			return dst;
+		}
+	}
+
+	size_t di = src.rfind('-');
+
+	if (di == String::npos)
+		return src;
+
+	for (int i = 0; i < di; i++) {
+		dst += src[i];
+	}
+
+	size_t b = di;
+	int i = 0;
+	int n = INITIAL_N;
+	int bias = INITIAL_BIAS;
+
+	for (int si = b + (b > 0 ? 1 : 0); si < srclen; di++) {
+		int org_i = i;
+
+		for (int w = 1, k = BASE; true; k += BASE) {
+			int digit = decode_digit(src[si++]);
+
+			if (digit == SIZE_MAX) {
+				goto fail;
+			}
+
+			if (digit > (SIZE_MAX - i) / w) {
+				/* OVERFLOW */
+				assert(0 && "OVERFLOW");
+				goto fail;
+			}
+
+			i += digit * w;
+			int t;
+
+			if (k <= bias) {
+				t = TMIN;
+			} else if (k >= bias + TMAX) {
+				t = TMAX;
+			} else {
+				t = k - bias;
+			}
+
+			if (digit < t) {
+				break;
+			}
+
+			if (w > SIZE_MAX / (BASE - t)) {
+				/* OVERFLOW */
+				assert(0 && "OVERFLOW");
+				goto fail;
+			}
+
+			w *= BASE - t;
+		}
+
+		bias = adapt_bias(i - org_i, di + 1, org_i == 0);
+
+		if (i / (di + 1) > SIZE_MAX - n) {
+			/* OVERFLOW */
+			assert(0 && "OVERFLOW");
+			goto fail;
+		}
+
+		n += i / (di + 1);
+		i %= (di + 1);
+
+		String dst1(dst.c_str(), i);
+		dst1 += n;
+		dst1 += String(dst.c_str()[i + 1]);
+		i++;
+	}
+
+fail:
+
+	return dst;
+}
+
+} // end of namespace Common
diff --git a/common/punycode.h b/common/punycode.h
new file mode 100644
index 0000000000..83cb9fcc16
--- /dev/null
+++ b/common/punycode.h
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+ /**
+ * Copyright (C) 2011 by Ben Noordhuis <info at bnoordhuis.nl>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef COMMON_PUNYCODE_H
+#define COMMON_PUNYCODE_H
+
+#include "common/str.h"
+
+namespace Common {
+
+/**
+ * Convert Unicode to Punycode. Returns the number of Unicode characters that were converted.
+ */
+size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *const dst, size_t *const dstlen);
+
+/**
+ * Convert Punycode to Unicode. Returns the number of bytes that were converted.
+ */
+String punycode_decode(const String src);
+
+} // end of namespace Common
+
+#endif


Commit: 73fd4a44e6949fc23310cf0a0352fef5e947efa7
    https://github.com/scummvm/scummvm/commit/73fd4a44e6949fc23310cf0a0352fef5e947efa7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:48+02:00

Commit Message:
DEVTOOLS: Remove ambiguity in escaping 0x81 in dumper companion

Changed paths:
    devtools/dumper-companion.pl


diff --git a/devtools/dumper-companion.pl b/devtools/dumper-companion.pl
index 452d92685f..796a0e295a 100644
--- a/devtools/dumper-companion.pl
+++ b/devtools/dumper-companion.pl
@@ -121,7 +121,7 @@ sub processIso($) {
 
 				if ($::opt_e) {
 					# make 0x81 an escape symbol
-					$decfname =~ s/\x81/\x81\x81/g;
+					$decfname =~ s/\x81/\x81\x79/g;
 					# escape non-printables, '/', "'" and '"'
 					$decfname =~ s/([\x00-\x1f\/'"])/\x81@{[chr(ord($1) + 0x80)]}/g;
 


Commit: 56f7af8d2e97c361e6c5904d974ade9889bde912
    https://github.com/scummvm/scummvm/commit/56f7af8d2e97c361e6c5904d974ade9889bde912
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
COMMON: Fix punycode decoding and implement reverse utility for escaped filenames

Changed paths:
    common/punycode.cpp
    common/punycode.h


diff --git a/common/punycode.cpp b/common/punycode.cpp
index cec656f025..69a6e6ccca 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -115,7 +115,7 @@ static size_t encode_var_int(const size_t bias, const size_t delta, char *const
 
 static size_t decode_digit(uint32_t v) {
 	if (Common::isDigit(v)) {
-		return 22 + (v - '0');
+		return 26 + (v - '0');
 	}
 	if (Common::isLower(v)) {
 		return v - 'a';
@@ -195,9 +195,8 @@ String punycode_decode(const String src1) {
 	if (!src1.hasPrefix("xn--"))
 		return src1;
 
-	String src(src1.c_str()[4]); // Skip the prefix for simplification
-
-	int srclen = src1.size();
+	String src(&src1.c_str()[4]); // Skip the prefix for simplification
+	int srclen = src.size();
 	String dst;
 
 	/* Ensure that the input contains only ASCII characters. */
@@ -207,7 +206,7 @@ String punycode_decode(const String src1) {
 		}
 	}
 
-	size_t di = src.rfind('-');
+	size_t di = src.findLastOf('-');
 
 	if (di == String::npos)
 		return src;
@@ -273,8 +272,9 @@ String punycode_decode(const String src1) {
 		i %= (di + 1);
 
 		String dst1(dst.c_str(), i);
-		dst1 += n;
-		dst1 += String(dst.c_str()[i + 1]);
+		dst1 += (char )n;
+		dst1 += String(&dst.c_str()[i]);
+		dst = dst1;
 		i++;
 	}
 
@@ -283,4 +283,24 @@ fail:
 	return dst;
 }
 
+String punycode_decodefilename(const String src1) {
+	String dst;
+	String src = punycode_decode(src1);
+
+	for (int i = 0; i < src.size(); i++) {
+		if ((byte)src[i] == 0x81 && i + 1 < src.size()) {
+			i++;
+			if (src[i] == 0x79)
+				dst += 0x81;
+			else
+				dst += src[i] - 0x80;
+		} else {
+			dst + src[i];
+		}
+	}
+
+	return dst;
+}
+
+
 } // end of namespace Common
diff --git a/common/punycode.h b/common/punycode.h
index 83cb9fcc16..a700269e00 100644
--- a/common/punycode.h
+++ b/common/punycode.h
@@ -49,15 +49,21 @@
 namespace Common {
 
 /**
- * Convert Unicode to Punycode. Returns the number of Unicode characters that were converted.
+ * Convert Binary to Punycode. Returns the encoded string.
  */
 size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *const dst, size_t *const dstlen);
 
 /**
- * Convert Punycode to Unicode. Returns the number of bytes that were converted.
+ * Convert Punycode to Binary. Returns the decoded string
  */
 String punycode_decode(const String src);
 
+/**
+ * Convert Punycode filename to Binary using special 0x81 escape character. Returns the decoded string
+ */
+String punycode_decodefilename(const String src1);
+
+
 } // end of namespace Common
 
 #endif


Commit: a655cff2034816ea8b2bf95cf0663515fb440e57
    https://github.com/scummvm/scummvm/commit/a655cff2034816ea8b2bf95cf0663515fb440e57
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
COMMON: Added auxiliary methods for punycode

Changed paths:
    common/punycode.cpp
    common/punycode.h


diff --git a/common/punycode.cpp b/common/punycode.cpp
index 69a6e6ccca..d956a7e86d 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -73,7 +73,7 @@ static uint32_t adapt_bias(uint32_t delta, unsigned n_points, int is_first) {
 static char encode_digit(int c) {
 	assert(c >= 0 && c <= BASE - TMIN);
 	if (c > 25) {
-		return c + 22; /* '0'..'9' */
+		return c + 26; /* '0'..'9' */
 	} else {
 		return c + 'a'; /* 'a'..'z' */
 	}
@@ -191,6 +191,20 @@ fail:
 	return si;
 }
 
+bool punycode_hasprefix(const String src) {
+	return src.hasPrefix("xn--");
+}
+
+bool punycode_needEncode(const String src) {
+	for (int si = 0; si < src.size(); si++) {
+		if (src[si] & 0x80 || src[si] < 0x20) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
 String punycode_decode(const String src1) {
 	if (!src1.hasPrefix("xn--"))
 		return src1;
diff --git a/common/punycode.h b/common/punycode.h
index a700269e00..5baad9ea70 100644
--- a/common/punycode.h
+++ b/common/punycode.h
@@ -63,6 +63,9 @@ String punycode_decode(const String src);
  */
 String punycode_decodefilename(const String src1);
 
+bool punycode_hasprefix(const String src);
+
+bool punycode_needEncode(const String src);
 
 } // end of namespace Common
 


Commit: 191bc979a97a107eb28cf3c458c997cb306e3e30
    https://github.com/scummvm/scummvm/commit/191bc979a97a107eb28cf3c458c997cb306e3e30
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
COMMON: Always return the original string on failed punycode decoding

Changed paths:
    common/fs.cpp
    common/punycode.cpp


diff --git a/common/fs.cpp b/common/fs.cpp
index c3b2290bfa..388998c094 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -21,6 +21,7 @@
  */
 
 #include "common/system.h"
+#include "common/punycode.h"
 #include "common/textconsole.h"
 #include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs-factory.h"
@@ -290,6 +291,9 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String&
 		String lowercaseName = name;
 		lowercaseName.toLowercase();
 
+		// We transparently decode any punycode-named files
+		lowercaseName = punycode_decodefilename(lowercaseName);
+
 		// since the hashmap is case insensitive, we need to check for clashes when caching
 		if (it->isDirectory()) {
 			if (!_flat && _subDirCache.contains(lowercaseName)) {
diff --git a/common/punycode.cpp b/common/punycode.cpp
index d956a7e86d..569dcadca2 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -43,6 +43,7 @@
  */
 
 #include "common/punycode.h"
+#include "common/debug.h"
 #include "common/util.h"
 
 namespace Common {
@@ -211,12 +212,11 @@ String punycode_decode(const String src1) {
 
 	String src(&src1.c_str()[4]); // Skip the prefix for simplification
 	int srclen = src.size();
-	String dst;
 
 	/* Ensure that the input contains only ASCII characters. */
 	for (int si = 0; si < srclen; si++) {
 		if (src[si] & 0x80) {
-			return dst;
+			return src1;
 		}
 	}
 
@@ -225,6 +225,8 @@ String punycode_decode(const String src1) {
 	if (di == String::npos)
 		return src;
 
+	String dst;
+
 	for (int i = 0; i < di; i++) {
 		dst += src[i];
 	}
@@ -241,13 +243,14 @@ String punycode_decode(const String src1) {
 			int digit = decode_digit(src[si++]);
 
 			if (digit == SIZE_MAX) {
-				goto fail;
+				warning("punycode_decode: incorrect digit");
+				return src1;
 			}
 
 			if (digit > (SIZE_MAX - i) / w) {
 				/* OVERFLOW */
-				assert(0 && "OVERFLOW");
-				goto fail;
+				warning("punycode_decode: overflow1");
+				return src1;
 			}
 
 			i += digit * w;
@@ -267,8 +270,8 @@ String punycode_decode(const String src1) {
 
 			if (w > SIZE_MAX / (BASE - t)) {
 				/* OVERFLOW */
-				assert(0 && "OVERFLOW");
-				goto fail;
+				warning("punycode_decode: overflow2");
+				return src1;
 			}
 
 			w *= BASE - t;
@@ -278,8 +281,8 @@ String punycode_decode(const String src1) {
 
 		if (i / (di + 1) > SIZE_MAX - n) {
 			/* OVERFLOW */
-			assert(0 && "OVERFLOW");
-			goto fail;
+				warning("punycode_decode: overflow3");
+			return src1;
 		}
 
 		n += i / (di + 1);
@@ -292,8 +295,6 @@ String punycode_decode(const String src1) {
 		i++;
 	}
 
-fail:
-
 	return dst;
 }
 
@@ -301,6 +302,11 @@ String punycode_decodefilename(const String src1) {
 	String dst;
 	String src = punycode_decode(src1);
 
+	// Check if the string did not change which could be
+	// also on decoding failure
+	if (src == src1)
+		return src;
+
 	for (int i = 0; i < src.size(); i++) {
 		if ((byte)src[i] == 0x81 && i + 1 < src.size()) {
 			i++;


Commit: 8789bdfd676c50e4fd8207036ff07a10e8899f3e
    https://github.com/scummvm/scummvm/commit/8789bdfd676c50e4fd8207036ff07a10e8899f3e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
COMMON: Reworked encode_punycode to String

Changed paths:
    common/punycode.cpp
    common/punycode.h


diff --git a/common/punycode.cpp b/common/punycode.cpp
index 569dcadca2..e87a474e98 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -81,14 +81,14 @@ static char encode_digit(int c) {
 }
 
 /* Encode as a generalized variable-length integer. Returns number of bytes written. */
-static size_t encode_var_int(const size_t bias, const size_t delta, char *const dst, size_t dstlen) {
-	size_t i, k, q, t;
+static String encode_var_int(const size_t bias, const size_t delta) {
+	size_t k, q, t;
+	String dst;
 
-	i = 0;
 	k = BASE;
 	q = delta;
 
-	while (i < dstlen) {
+	while (true) {
 		if (k <= bias) {
 			t = TMIN;
 		} else if (k >= bias + TMAX) {
@@ -101,17 +101,15 @@ static size_t encode_var_int(const size_t bias, const size_t delta, char *const
 			break;
 		}
 
-		dst[i++] = encode_digit(t + (q - t) % (BASE - t));
+		dst += encode_digit(t + (q - t) % (BASE - t));
 
 		q = (q - t) / (BASE - t);
 		k += BASE;
 	}
 
-	if (i < dstlen) {
-		dst[i++] = encode_digit(q);
-	}
+	dst += encode_digit(q);
 
-	return i;
+	return dst;
 }
 
 static size_t decode_digit(uint32_t v) {
@@ -127,30 +125,32 @@ static size_t decode_digit(uint32_t v) {
 	return SIZE_MAX;
 }
 
-size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *const dst, size_t *const dstlen) {
-	size_t b, h;
-	size_t delta, bias;
-	size_t m, n;
-	size_t si, di;
+String punycode_encode(String src) {
+	int srclen = src.size();
+	int di = 0, si;
+	String dst;
 
-	for (si = 0, di = 0; si < srclen && di < *dstlen; si++) {
-		if (src[si] < 128) {
-			dst[di++] = src[si];
+	for (si = 0; si < srclen; si++) {
+		if ((byte)src[si] < 128) {
+			dst += src[si];
+			di++;
 		}
 	}
 
-	b = h = di;
+	int b = di, h = di;
 
 	/* Write out delimiter if any basic code points were processed. */
-	if (di > 0 && di < *dstlen) {
-		dst[di++] = '-';
+	if (di > 0) {
+		dst += '-';
+		di++;
 	}
 
-	n = INITIAL_N;
-	bias = INITIAL_BIAS;
-	delta = 0;
+	int n = INITIAL_N;
+	int bias = INITIAL_BIAS;
+	int delta = 0;
+	int m;
 
-	for (; h < srclen && di < *dstlen; n++, delta++) {
+	for (; h < srclen; n++, delta++) {
 		/* Find next smallest non-basic code point. */
 		for (m = SIZE_MAX, si = 0; si < srclen; si++) {
 			if (src[si] >= n && src[si] < m) {
@@ -176,7 +176,7 @@ size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *con
 				}
 			}
 			else if (src[si] == n) {
-				di += encode_var_int(bias, delta, &dst[di], *dstlen - di);
+				dst += encode_var_int(bias, delta);
 				bias = adapt_bias(delta, h + 1, h == b);
 				delta = 0;
 				h++;
@@ -185,11 +185,8 @@ size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *con
 	}
 
 fail:
-	/* Tell the caller how many bytes were written to the output buffer. */
-	*dstlen = di;
-
 	/* Return how many Unicode code points were converted. */
-	return si;
+	return dst;
 }
 
 bool punycode_hasprefix(const String src) {
@@ -298,6 +295,24 @@ String punycode_decode(const String src1) {
 	return dst;
 }
 
+String punycode_encodefilename(const String src) {
+	String dst;
+
+	for (int i = 0; i < src.size(); i++) {
+		if ((byte)src[i] == 0x81) {	// In case we have our escape character present
+			dst += '\x81';
+			dst += '\x79';
+		// [\x00-\x1f\/":]
+		} else if (src[i] == '/' || src[i] == '"' || src[i] == ':' || (byte)src[i] < 0x20) {
+			dst += src[i] + 0x80;
+		} else {
+			dst += src[i];
+		}
+	}
+
+	return dst;
+}
+
 String punycode_decodefilename(const String src1) {
 	String dst;
 	String src = punycode_decode(src1);
@@ -315,12 +330,11 @@ String punycode_decodefilename(const String src1) {
 			else
 				dst += src[i] - 0x80;
 		} else {
-			dst + src[i];
+			dst += src[i];
 		}
 	}
 
 	return dst;
 }
 
-
 } // end of namespace Common
diff --git a/common/punycode.h b/common/punycode.h
index 5baad9ea70..0fa1e949dd 100644
--- a/common/punycode.h
+++ b/common/punycode.h
@@ -51,13 +51,15 @@ namespace Common {
 /**
  * Convert Binary to Punycode. Returns the encoded string.
  */
-size_t punycode_encode(const uint32_t *const src, const size_t srclen, char *const dst, size_t *const dstlen);
+String punycode_encode(const String src);
 
 /**
  * Convert Punycode to Binary. Returns the decoded string
  */
 String punycode_decode(const String src);
 
+String punycode_encodefilename(const String src1);
+
 /**
  * Convert Punycode filename to Binary using special 0x81 escape character. Returns the decoded string
  */


Commit: 81b7702722837fac92379fe16eab6c756eecfbd7
    https://github.com/scummvm/scummvm/commit/81b7702722837fac92379fe16eab6c756eecfbd7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
DEVTOOLS: Do not encode "'" to punycode

Changed paths:
    devtools/dumper-companion.pl


diff --git a/devtools/dumper-companion.pl b/devtools/dumper-companion.pl
index 796a0e295a..e916047f97 100644
--- a/devtools/dumper-companion.pl
+++ b/devtools/dumper-companion.pl
@@ -122,8 +122,8 @@ sub processIso($) {
 				if ($::opt_e) {
 					# make 0x81 an escape symbol
 					$decfname =~ s/\x81/\x81\x79/g;
-					# escape non-printables, '/', "'" and '"'
-					$decfname =~ s/([\x00-\x1f\/'"])/\x81@{[chr(ord($1) + 0x80)]}/g;
+					# escape non-printables, '/', '"' and ':'
+					$decfname =~ s/([\x00-\x1f\/":])/\x81@{[chr(ord($1) + 0x80)]}/g;
 
 					if ($decfname =~ /[\x80-\xff]/) {
 						$decfname = encode_punycode $decfname;


Commit: cd3f7039886af6b94eb2f67e319825ea72387543
    https://github.com/scummvm/scummvm/commit/cd3f7039886af6b94eb2f67e319825ea72387543
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
COMMON: Fix punycode encoding

Changed paths:
    common/punycode.cpp


diff --git a/common/punycode.cpp b/common/punycode.cpp
index e87a474e98..b79e6f2964 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -56,6 +56,7 @@ namespace Common {
 #define DAMP 700
 #define INITIAL_N 128
 #define INITIAL_BIAS 72
+#define SMAX 0x7fff
 
 static uint32_t adapt_bias(uint32_t delta, unsigned n_points, int is_first) {
 	uint32_t k;
@@ -122,27 +123,26 @@ static size_t decode_digit(uint32_t v) {
 	if (Common::isUpper(v)) {
 		return v - 'A';
 	}
-	return SIZE_MAX;
+	return SMAX;
 }
 
 String punycode_encode(String src) {
 	int srclen = src.size();
-	int di = 0, si;
+	int h = 0, si;
 	String dst;
 
 	for (si = 0; si < srclen; si++) {
 		if ((byte)src[si] < 128) {
 			dst += src[si];
-			di++;
+			h++;
 		}
 	}
 
-	int b = di, h = di;
+	int b = h;
 
 	/* Write out delimiter if any basic code points were processed. */
-	if (di > 0) {
+	if (!dst.empty()) {
 		dst += '-';
-		di++;
 	}
 
 	int n = INITIAL_N;
@@ -152,30 +152,29 @@ String punycode_encode(String src) {
 
 	for (; h < srclen; n++, delta++) {
 		/* Find next smallest non-basic code point. */
-		for (m = SIZE_MAX, si = 0; si < srclen; si++) {
-			if (src[si] >= n && src[si] < m) {
-				m = src[si];
+		for (m = SMAX, si = 0; si < srclen; si++) {
+			if ((byte)src[si] >= n && (byte)src[si] < m) {
+				m = (byte)src[si];
 			}
 		}
 
-		if ((m - n) > (SIZE_MAX - delta) / (h + 1)) {
+		if ((m - n) > (SMAX - delta) / (h + 1)) {
 			/* OVERFLOW */
-			assert(0 && "OVERFLOW");
-			goto fail;
+			warning("punycode_encode: overflow1");
+			return src;
 		}
 
 		delta += (m - n) * (h + 1);
 		n = m;
 
 		for (si = 0; si < srclen; si++) {
-			if (src[si] < n) {
+			if ((byte)src[si] < n) {
 				if (++delta == 0) {
 					/* OVERFLOW */
-					assert(0 && "OVERFLOW");
-					goto fail;
+					warning("punycode_encode: overflow2");
+					return src;
 				}
-			}
-			else if (src[si] == n) {
+			} else if ((byte)src[si] == n) {
 				dst += encode_var_int(bias, delta);
 				bias = adapt_bias(delta, h + 1, h == b);
 				delta = 0;
@@ -184,7 +183,6 @@ String punycode_encode(String src) {
 		}
 	}
 
-fail:
 	/* Return how many Unicode code points were converted. */
 	return dst;
 }
@@ -239,12 +237,12 @@ String punycode_decode(const String src1) {
 		for (int w = 1, k = BASE; true; k += BASE) {
 			int digit = decode_digit(src[si++]);
 
-			if (digit == SIZE_MAX) {
+			if (digit == SMAX) {
 				warning("punycode_decode: incorrect digit");
 				return src1;
 			}
 
-			if (digit > (SIZE_MAX - i) / w) {
+			if (digit > (SMAX - i) / w) {
 				/* OVERFLOW */
 				warning("punycode_decode: overflow1");
 				return src1;
@@ -265,7 +263,7 @@ String punycode_decode(const String src1) {
 				break;
 			}
 
-			if (w > SIZE_MAX / (BASE - t)) {
+			if (w > SMAX / (BASE - t)) {
 				/* OVERFLOW */
 				warning("punycode_decode: overflow2");
 				return src1;
@@ -276,7 +274,7 @@ String punycode_decode(const String src1) {
 
 		bias = adapt_bias(i - org_i, di + 1, org_i == 0);
 
-		if (i / (di + 1) > SIZE_MAX - n) {
+		if (i / (di + 1) > SMAX - n) {
 			/* OVERFLOW */
 				warning("punycode_decode: overflow3");
 			return src1;
@@ -310,7 +308,7 @@ String punycode_encodefilename(const String src) {
 		}
 	}
 
-	return dst;
+	return punycode_encode(dst);
 }
 
 String punycode_decodefilename(const String src1) {


Commit: 3b2d55f36e033fba7bfbbe72c12d6c865614b3a3
    https://github.com/scummvm/scummvm/commit/3b2d55f36e033fba7bfbbe72c12d6c865614b3a3
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
DIRECTOR: Use original file names for The Apartment

Changed paths:
    engines/director/detection_tables.h


diff --git a/engines/director/detection_tables.h b/engines/director/detection_tables.h
index b9a09ec0c8..3846c6f9b0 100644
--- a/engines/director/detection_tables.h
+++ b/engines/director/detection_tables.h
@@ -1007,9 +1007,9 @@ static const DirectorGameDescription gameDescriptions[] = {
 	},
 
 	// Original filename is "•Main Menu" for all
-	MACGAME1("theapartment", "D2", "Main Menu", "fc56c179cb8c6d4938e61ee61fd0032c", 48325, 200),
-	MACGAME1("theapartment", "D3", "Main Menu", "9e838fe1a6af7992d656ca325e38dee5", 47911, 300),
-	MACGAME1("theapartment", "D4", "Main Menu", "ff86181f03fe6eb060f65a985ca0580d", 160612, 400),
+	MACGAME1("theapartment", "D2", "\xa5Main Menu", "fc56c179cb8c6d4938e61ee61fd0032c", 48325, 200),
+	MACGAME1("theapartment", "D3", "\xa5Main Menu", "9e838fe1a6af7992d656ca325e38dee5", 47911, 300),
+	MACGAME1("theapartment", "D4", "\xa5Main Menu", "ff86181f03fe6eb060f65a985ca0580d", 160612, 400),
 
 //////////////////////////////////////////////////
 //


Commit: 0b1c95aadfb031d1f8323e56e6bb1633e0ba5bfa
    https://github.com/scummvm/scummvm/commit/0b1c95aadfb031d1f8323e56e6bb1633e0ba5bfa
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:49+02:00

Commit Message:
JANITORIAL: Remove trailing whitespaces

Changed paths:
    engines/director/detection_tables.h


diff --git a/engines/director/detection_tables.h b/engines/director/detection_tables.h
index 3846c6f9b0..e44afd17ad 100644
--- a/engines/director/detection_tables.h
+++ b/engines/director/detection_tables.h
@@ -259,7 +259,7 @@ static const PlainGameDescriptor directorGames[] = {
 	{ "sajaklucky",			"Pat Sajak's Lucky Letters" },
 	{ "screamingmetal",		"Screaming Metal" },
 	{ "searchlearn",     	"Search & Learn Adventures" },
-	{ "secretkeys",     	"Search for the Secret Keys with Mickey" },	
+	{ "secretkeys",     	"Search for the Secret Keys with Mickey" },
 	{ "secretpaths1",		"Secret Paths in the Forest" },
 	{ "shr1st2nd",			"Schoolhouse Rock!: 1st & 2nd Grade Essentials" },
 	{ "shr3rd4th",			"Schoolhouse Rock!: 3rd & 4th Grade Essentials" },
@@ -938,7 +938,7 @@ static const PlainGameDescriptor directorGames[] = {
 	{ "thebody",			"The Body: Five doors plus" },
 	{ "thelegs",			"The Legs ~Get a LEG up~" },
 	{ "venus",				"Venus Photo CD-ROM" },
-	{ "vvalerie1",			"Virtual Valerie" },	
+	{ "vvalerie1",			"Virtual Valerie" },
 	{ "vvalerie2",			"Virtual Valerie 2" },
 	{ "vveronika",			"Virtual Veronika" },
 	{ "vpeepshow",			"Virtual Peep Show" },
@@ -1175,7 +1175,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 	WINDEMO1("bookshelf94", "Demo", "BS94DEMO.EXE", "7c8230a804abf9353b05627a675b5ffb", 375300, 310),
 
 	WINDEMO1("bpmc", "", "BPMC.EXE", "1998188253fc8657198e3e78efe823a8", 370291, 313),
-	
+
 	// Original v3.5.1 demo filename is BusinessManager.デモ
 	MACDEMO1_l("businessmanager", "v3.5.1 Demo", "BusinessManager.Demo", "f5277c53bacd27936158dd3867e587e2", 2102528, Common::JA_JPN, 311),
 	MACDEMO1_l("businessmanager", "Demo", "BusinessManager.Demo", "f5277c53bacd27936158dd3867e587e2", 392603, Common::JA_JPN, 311),
@@ -1471,7 +1471,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 
 	MACGAME1("murderbrett", "", "The Environmental Surfer", "2ce360c9ea2da80a2c6d1040b0ad92dd", 384469, 300),
 	WINGAME1("murderbrett", "", "BRETTP.EXE", "65d06b5fef155a2473434571aff5bc29", 370010, 300),
-	
+
 	MACGAME1("murdermagic", "", "The Magic Death", "a8788e8b79dccc582b9818ec63734bed", 736754, 300),
 	WINGAME1("murdermagic", "", "MAGIC.EXE", "7c8230a804abf9353b05627a675b5ffb", 375298, 300),
 
@@ -1525,7 +1525,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 			Common::EN_ANY,
 			Common::kPlatformMacintosh,
 			(ADGF_CD|ADGF_MACRESFORK),
-			GUIO1(GUIO_NOASPECT)	
+			GUIO1(GUIO_NOASPECT)
 		},
 		GID_GENERIC,
 		311
@@ -1716,7 +1716,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 			Common::EN_ANY,
 			Common::kPlatformMacintosh,
 			(ADGF_CD|ADGF_MACRESFORK),
-			GUIO1(GUIO_NOASPECT)			
+			GUIO1(GUIO_NOASPECT)
 		},
 		GID_GENERIC,
 		313
@@ -2159,7 +2159,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 	WINGAME2_l("horrortour1", "", "HORROR.EXE", "b16ecf8ebc02142c742b8a9acc935d52", 752425,
 								  "HORROR.DAT", "42f0450d970a95f0dd47727988996ce9", 450, Common::ZH_TWN, 404),
 
-	MACGAME1_l("horrortour1", "", "HorrorTour(7M)", "b7e69c37b7355022d400c14aa97c5d54", 483443, Common::JA_JPN, 404),	
+	MACGAME1_l("horrortour1", "", "HorrorTour(7M)", "b7e69c37b7355022d400c14aa97c5d54", 483443, Common::JA_JPN, 404),
 	WINGAME1_l("horrortour1", "", "HORROR.EXE", "b16ecf8ebc02142c742b8a9acc935d52", 752425, Common::JA_JPN, 404),
 	MACGAME1_l("horrortour2", "", "ZEDDAS PowerPC", "da7d3f1d85bdb99518b586c40d2a673e", 60013, Common::JA_JPN, 400),
 	WINGAME1_l("horrortour2", "", "HT2.EXE", "499d8545ee2325b18d3f09fb2c0fc26e", 698029, Common::JA_JPN, 400),
@@ -2425,7 +2425,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 	MACGAME2("operafatal", "",	 "OPERA FATAL", "f5033f237ad1b1639fc46d01a82ac380", 285566,
 							     "SPRINT.Dxr",  "3e86f01eeac5fa3349c5177378997a7f", 694912, 400),
 	MACGAME2_l("operafatal", "", "OPERA FATAL",	"f5033f237ad1b1639fc46d01a82ac380", 285566,
-								 "SPRINT.Dxr",	"3eb6f5568c9ced258059e2cfd30751c5", 479616, Common::IT_ITA, 400),	
+								 "SPRINT.Dxr",	"3eb6f5568c9ced258059e2cfd30751c5", 479616, Common::IT_ITA, 400),
 
 	MACDEMO1("orgotto", "Demo", "ORGOTTO", "0c7bbb4b24823e5ab871cb4c1d6f3710", 484351, 404),
 	WINDEMO1("orgotto", "Demo", "ORGOTTO.EXE", "f9272ef143c610ebd4dcb8301aa9b678", 760137, 404),
@@ -2526,7 +2526,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 	MACDEMO1("redshift", "1994 Demo", "RSDEMO.MAC", "4f7ff33ce95ed9f42befdae4f9b6b690", 292244, 403),
 
 	MACGAME1_l("renderorgan", "", "RenderOrgan", "0c7bbb4b24823e5ab871cb4c1d6f3710", 505374, Common::JA_JPN, 404),
-	WINGAME1_l("renderorgan", "", "743.EXE", "7a59a30b6b2db921f6d354cd74faf09a", 697963, Common::JA_JPN, 404),	
+	WINGAME1_l("renderorgan", "", "743.EXE", "7a59a30b6b2db921f6d354cd74faf09a", 697963, Common::JA_JPN, 404),
 
 	// Original filename is ラインの黄金CD
 	MACDEMO1_l("rheingold", "Demo", "Das Rheingold CD", "b7e69c37b7355022d400c14aa97c5d54", 484351, Common::JA_JPN, 404),
@@ -3730,7 +3730,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 								  "movie.dxr",	   "b8dc39b080e4892913c2d302fec39567", 50907991, 800),
 
 	MACDEMO1("balto2", "Trailer", "MacBolto", "08c9ea94f6469e71ae0c71987bbf6323", 155737, 850),
-	WINDEMO1("balto2", "Trailer", "Balto.exe", "c163f36141579ee374f7b4b2bddee95a", 2309044, 850),	
+	WINDEMO1("balto2", "Trailer", "Balto.exe", "c163f36141579ee374f7b4b2bddee95a", 2309044, 850),
 
 	MACGAME1_l("bamse1", "", "Spillerom", "a44511b8ff0e46b4f9c85dd1cb58d458", 199093, Common::DA_DAN, 851),
 	MACGAME1_l("bamse2", "", "Bamses egen", "a44511b8ff0e46b4f9c85dd1cb58d458", 157079, Common::DA_DAN, 851),
@@ -3739,7 +3739,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 
 	MACGAME1("barbrapunzel", "", "Rapunzel", "08c9ea94f6469e71ae0c71987bbf6323", 213604, 850),
 	MACDEMO1("barbrapunzel", "Trailer", "Trailer", "08c9ea94f6469e71ae0c71987bbf6323", 155737, 850),
-	WINGAME1("barbrapunzel", "", "Rapunzel.exe", "c163f36141579ee374f7b4b2bddee95a", 2116696, 850),	
+	WINGAME1("barbrapunzel", "", "Rapunzel.exe", "c163f36141579ee374f7b4b2bddee95a", 2116696, 850),
 	WINDEMO2("barbrapunzel", "Trailer", "Trailer.exe", "c163f36141579ee374f7b4b2bddee95a", 2303378,
 										"Trailer.mov", "c23add499f206fb3f8e088cf315c2783", 17393683, 850),
 
@@ -4142,7 +4142,7 @@ static const DirectorGameDescription gameDescriptions[] = {
 	MACDEMO1_l("immorale", "Demo", "Helmut Newton & Eri Ishida", "f5277c53bacd27936158dd3867e587e2", 390241, Common::JA_JPN, 311),
 	MACGAME1("isswim98", "",	   "Inside Sports Swimsuit 98",	 "4577dd3eadc467a986ab172d90871b22", 304156, 404),
 	WINGAME1("isswim98", "",	   "ISSWIM98.EXE",				 "24de9da2e30d07ba98d2fd6259afd16c", 753801, 404),
-	MACDEMO1_l("legs", "Demo",	   "LEGS Vol.1",				 "f5277c53bacd27936158dd3867e587e2", 548017, Common::JA_JPN, 311), 
+	MACDEMO1_l("legs", "Demo",	   "LEGS Vol.1",				 "f5277c53bacd27936158dd3867e587e2", 548017, Common::JA_JPN, 311),
 
 	// Touring Engine Ver 1.00. Original filename is MacPlaymateâ„¢
 	MACGAME1("macplaymate1", "",  "MacPlaymate",	"4bdad2173d739dcaca1241afe88c7aef", 33851, 0),


Commit: f3145d0fb6815c6c35f402834933d25fe8bbcf2f
    https://github.com/scummvm/scummvm/commit/f3145d0fb6815c6c35f402834933d25fe8bbcf2f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
COMMON: Decode filenames from Punycode upon returning

Changed paths:
    common/fs.cpp


diff --git a/common/fs.cpp b/common/fs.cpp
index 388998c094..e120055a38 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -94,7 +94,8 @@ String FSNode::getDisplayName() const {
 
 String FSNode::getName() const {
 	assert(_realNode);
-	return _realNode->getName();
+	// We transparently decode any punycode-named files
+	return punycode_decodefilename(_realNode->getName());
 }
 
 FSNode FSNode::getParent() const {
@@ -291,9 +292,6 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String&
 		String lowercaseName = name;
 		lowercaseName.toLowercase();
 
-		// We transparently decode any punycode-named files
-		lowercaseName = punycode_decodefilename(lowercaseName);
-
 		// since the hashmap is case insensitive, we need to check for clashes when caching
 		if (it->isDirectory()) {
 			if (!_flat && _subDirCache.contains(lowercaseName)) {


Commit: 96bb4d2d530c2bdb71112ff0352103de3ffb0363
    https://github.com/scummvm/scummvm/commit/96bb4d2d530c2bdb71112ff0352103de3ffb0363
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
COMMON: Added more auxiliary method to Punycode

Changed paths:
    common/punycode.cpp
    common/punycode.h


diff --git a/common/punycode.cpp b/common/punycode.cpp
index b79e6f2964..b1e294773e 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -44,6 +44,7 @@
 
 #include "common/punycode.h"
 #include "common/debug.h"
+#include "common/tokenizer.h"
 #include "common/util.h"
 
 namespace Common {
@@ -311,6 +312,19 @@ String punycode_encodefilename(const String src) {
 	return punycode_encode(dst);
 }
 
+String punycode_encodepath(const String src) {
+	StringTokenizer tok(src, "/");
+	String res;
+
+	while (!tok.empty()) {
+		res += punycode_encodefilename(tok.nextToken());
+		if (!tok.empty())
+			res += '/';
+	}
+
+	return res;
+}
+
 String punycode_decodefilename(const String src1) {
 	String dst;
 	String src = punycode_decode(src1);
@@ -335,4 +349,17 @@ String punycode_decodefilename(const String src1) {
 	return dst;
 }
 
+String punycode_decodepath(const String src) {
+	StringTokenizer tok(src, "/");
+	String res;
+
+	while (!tok.empty()) {
+		res += punycode_decodefilename(tok.nextToken());
+		if (!tok.empty())
+			res += '/';
+	}
+
+	return res;
+}
+
 } // end of namespace Common
diff --git a/common/punycode.h b/common/punycode.h
index 0fa1e949dd..63838657bb 100644
--- a/common/punycode.h
+++ b/common/punycode.h
@@ -59,12 +59,18 @@ String punycode_encode(const String src);
 String punycode_decode(const String src);
 
 String punycode_encodefilename(const String src1);
+String punycode_encodepath(const String src);
 
 /**
  * Convert Punycode filename to Binary using special 0x81 escape character. Returns the decoded string
  */
 String punycode_decodefilename(const String src1);
 
+/**
+ * Convert path with '/' as separators from Punycode
+ */
+String punycode_decodepath(const String src);
+
 bool punycode_hasprefix(const String src);
 
 bool punycode_needEncode(const String src);


Commit: 2fce9db17855d6136e056b98b871c78ec9f6144f
    https://github.com/scummvm/scummvm/commit/2fce9db17855d6136e056b98b871c78ec9f6144f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
DIRECTOR: Do not convert '/' in paths

Changed paths:
    engines/director/util.cpp


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 20b2bf61ca..b845e93d44 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -248,8 +248,6 @@ Common::String convertPath(Common::String &path) {
 	while (idx != path.size()) {
 		if (path[idx] == ':')
 			res += '\\';
-		else if (path[idx] == '/')
-			res += ':';
 		else
 			res += path[idx];
 


Commit: e6429a1213a2cda4109d832e547734f49c1d73ef
    https://github.com/scummvm/scummvm/commit/e6429a1213a2cda4109d832e547734f49c1d73ef
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
COMMON: Fix punycode encoding

Changed paths:
    common/punycode.cpp


diff --git a/common/punycode.cpp b/common/punycode.cpp
index b1e294773e..abd61f0324 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -142,8 +142,10 @@ String punycode_encode(String src) {
 	int b = h;
 
 	/* Write out delimiter if any basic code points were processed. */
-	if (!dst.empty()) {
-		dst += '-';
+	if (h != srclen) {
+		dst = String::format("xn--%s-", dst.c_str());
+	} else {
+		return src;
 	}
 
 	int n = INITIAL_N;
@@ -303,7 +305,8 @@ String punycode_encodefilename(const String src) {
 			dst += '\x79';
 		// [\x00-\x1f\/":]
 		} else if (src[i] == '/' || src[i] == '"' || src[i] == ':' || (byte)src[i] < 0x20) {
-			dst += src[i] + 0x80;
+			dst += '\x81';
+			dst += (byte)src[i] + 0x80;
 		} else {
 			dst += src[i];
 		}
@@ -340,7 +343,7 @@ String punycode_decodefilename(const String src1) {
 			if (src[i] == 0x79)
 				dst += 0x81;
 			else
-				dst += src[i] - 0x80;
+				dst += (byte)src[i] - 0x80;
 		} else {
 			dst += src[i];
 		}


Commit: 92517fc3f592024a1f758dc574c67684fcf9d686
    https://github.com/scummvm/scummvm/commit/92517fc3f592024a1f758dc574c67684fcf9d686
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
DEVTOOLS: Synchronize encoding for punycode in different tool modes

Changed paths:
    devtools/dumper-companion.pl


diff --git a/devtools/dumper-companion.pl b/devtools/dumper-companion.pl
index e916047f97..8439972bc3 100644
--- a/devtools/dumper-companion.pl
+++ b/devtools/dumper-companion.pl
@@ -95,8 +95,8 @@ sub processIso($) {
 			if ($::opt_e) {
 				# make 0x81 an escape symbol
 				$dir =~ s/\x81/\x81\x81/g;
-				# escape non-printables, '/', "'" and '"'
-				$dir =~ s/([\x00-\x1f\/'"])/\x81@{[chr(ord($1) + 0x80)]}/g;
+				# escape non-printables, '/', '"' and ":"
+				$dir =~ s/([\x00-\x1f\/":])/\x81@{[chr(ord($1) + 0x80)]}/g;
 
 				if ($dir =~ /[\x80-\xff]/) {
 					$dir = encode_punycode $dir;


Commit: 530354492a5137c0c48bcae051e0348f83511771
    https://github.com/scummvm/scummvm/commit/530354492a5137c0c48bcae051e0348f83511771
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
COMMON: Fix encode_punycode to match the perl code

Changed paths:
    common/punycode.cpp


diff --git a/common/punycode.cpp b/common/punycode.cpp
index abd61f0324..197d123213 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -76,9 +76,9 @@ static uint32_t adapt_bias(uint32_t delta, unsigned n_points, int is_first) {
 static char encode_digit(int c) {
 	assert(c >= 0 && c <= BASE - TMIN);
 	if (c > 25) {
-		return c + 26; /* '0'..'9' */
+		return c + 0x30 - 26; /* '0'..'9' */
 	} else {
-		return c + 'a'; /* 'a'..'z' */
+		return c + 0x61; /* 'a'..'z' */
 	}
 }
 


Commit: e6c582fe0f107fef643a04ae11a9dc8d8d105d00
    https://github.com/scummvm/scummvm/commit/e6c582fe0f107fef643a04ae11a9dc8d8d105d00
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-07-27T18:14:50+02:00

Commit Message:
DIRECTOR: Make movie file names printable

Changed paths:
    engines/director/window.cpp


diff --git a/engines/director/window.cpp b/engines/director/window.cpp
index 9f706638f9..3e282904e9 100644
--- a/engines/director/window.cpp
+++ b/engines/director/window.cpp
@@ -518,7 +518,7 @@ bool Window::step() {
 		case kPlayNotStarted:
 			{
 				debug(0, "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
-				debug(0, "@@@@   Loading movie '%s' in '%s'", _currentMovie->getMacName().c_str(), _currentPath.c_str());
+				debug(0, "@@@@   Loading movie '%s' in '%s'", toPrintable(_currentMovie->getMacName()).c_str(), _currentPath.c_str());
 				debug(0, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
 
 				bool goodMovie = _currentMovie->loadArchive();




More information about the Scummvm-git-logs mailing list