Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 466a669

Browse files
authored
Merge pull request #1271 from two-pack/use-l4j-encoding
Fix for #1203 Using the codepage with arduino.l4j.ini on win32
2 parents c5b03c9 + 604b3f0 commit 466a669

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/common/util.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,16 @@ export function spawn(
207207

208208
let codepage = "65001";
209209
if (os.platform() === "win32") {
210-
try {
211-
const chcp = child_process.execSync("chcp.com");
212-
codepage = chcp.toString().split(":").pop().trim();
213-
} catch (error) {
214-
arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.\
215-
\rEnsure your path includes %SystemRoot%\\system32\r${error.message}`);
216-
codepage = "850";
210+
codepage = getArduinoL4jCodepage(command.replace(/.exe$/i, ".l4j.ini"));
211+
if (!codepage) {
212+
try {
213+
const chcp = child_process.execSync("chcp.com");
214+
codepage = chcp.toString().split(":").pop().trim();
215+
} catch (error) {
216+
arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.\
217+
\rEnsure your path includes %SystemRoot%\\system32\r${error.message}`);
218+
codepage = "850";
219+
}
217220
}
218221
}
219222

@@ -253,6 +256,16 @@ export function spawn(
253256
});
254257
}
255258

259+
export function getArduinoL4jCodepage(filePath: string): string | undefined {
260+
const encoding = parseConfigFile(filePath).get("-Dfile.encoding");
261+
if (encoding === "UTF8") {
262+
return "65001";
263+
}
264+
return Object.keys(encodingMapping).reduce((r, key) => {
265+
return encodingMapping[key] === encoding ? key : r;
266+
}, undefined);
267+
}
268+
256269
export function decodeData(data: Buffer, codepage: string): string {
257270
if (Object.prototype.hasOwnProperty.call(encodingMapping, codepage)) {
258271
return iconv.decode(data, encodingMapping[codepage]);

0 commit comments

Comments
 (0)