From c2f7690442c903c43c9ee907f685a05902f74cb7 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Fri, 4 Sep 2020 18:03:13 -0700
Subject: [PATCH] Compel UTF8 encoding so the powershell trick works even with
 files that don't have valid names in the current codepage

---
 devTools/concatFiles.bat | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/devTools/concatFiles.bat b/devTools/concatFiles.bat
index b2efe3feb26..dfbe2df9988 100644
--- a/devTools/concatFiles.bat
+++ b/devTools/concatFiles.bat
@@ -1,6 +1,10 @@
 @echo off
 :: Concatenates files from dir %1 specified with wildcard %2 and outputs result to %3
 
+:: temporary codepage change to avoid mojibake
+FOR /f "tokens=2 delims=:." %%x IN ('CHCP') DO SET _cp=%%x
+CHCP 65001 > NUL
+
 :: TODO Proper temp file instead of bin\list.txt
 IF EXIST %3 DEL %3
 SET _LISTFILE="bin\list.txt"
@@ -12,7 +16,7 @@ sort /O %_LISTFILE% %_LISTFILE%
 :: If we have powershell available, strip the absolute path information
 :: If not, fail silently (which is fine, but will leak path information into the built file)
 powershell -command "" 2> NUL
-IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw) -replace [regex]::escape('%CD%'),'' -replace '\"','' ^| set-content -path %_LISTFILE%"
+IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw -encoding utf8) -replace [regex]::escape('%CD%'),'' -replace '\"','' ^| set-content -encoding utf8 -path %_LISTFILE%"
 
 :: Append the files
 (FOR /F "usebackq delims=" %%F IN (`type "%_LISTFILE%"`) DO (
@@ -22,3 +26,4 @@ IF %ERRORLEVEL% EQU 0 powershell -command "(get-content -path %_LISTFILE% -raw)
 )
 
 DEL %_LISTFILE%
+CHCP %_CP% > NUL
\ No newline at end of file
-- 
GitLab