From c103846d0073c94074ada2670650975e948238e7 Mon Sep 17 00:00:00 2001 From: two-pack Date: Sun, 23 May 2021 11:28:57 +0900 Subject: [PATCH 1/2] Get the codepage with the encoding specified in arduino.l4j.ini on win32 platform. --- src/common/util.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/common/util.ts b/src/common/util.ts index b82aa422..7c560e8f 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -207,13 +207,16 @@ export function spawn( let codepage = "65001"; if (os.platform() === "win32") { - try { - const chcp = child_process.execSync("chcp.com"); - codepage = chcp.toString().split(":").pop().trim(); - } catch (error) { - arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.\ - \rEnsure your path includes %SystemRoot%\\system32\r${error.message}`); - codepage = "850"; + codepage = getArduinoL4jCodepage(command.replace(/.exe$/i, ".l4j.ini")); + if (!codepage) { + try { + const chcp = child_process.execSync("chcp.com"); + codepage = chcp.toString().split(":").pop().trim(); + } catch (error) { + arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.\ + \rEnsure your path includes %SystemRoot%\\system32\r${error.message}`); + codepage = "850"; + } } } @@ -253,6 +256,16 @@ export function spawn( }); } +export function getArduinoL4jCodepage(filePath: string): string | undefined { + const encoding = parseConfigFile(filePath).get("-Dfile.encoding"); + if(encoding === "UTF8") { + return "65001"; + } + return Object.keys(encodingMapping).reduce((r, key) => { + return encodingMapping[key] === encoding ? key : r; + }, undefined); +} + export function decodeData(data: Buffer, codepage: string): string { if (encodingMapping.hasOwnProperty(codepage)) { return iconv.decode(data, encodingMapping[codepage]); From bb183d6940a72daa47a476196eb8da3aeeab0967 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Thu, 13 Jan 2022 13:45:40 -0800 Subject: [PATCH 2/2] Fix linting issues --- src/common/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/util.ts b/src/common/util.ts index 3248835d..c07ab330 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -258,7 +258,7 @@ export function spawn( export function getArduinoL4jCodepage(filePath: string): string | undefined { const encoding = parseConfigFile(filePath).get("-Dfile.encoding"); - if(encoding === "UTF8") { + if (encoding === "UTF8") { return "65001"; } return Object.keys(encodingMapping).reduce((r, key) => {