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

Windows codepage bugfix #899

Merged
merged 4 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class ArduinoApp {
const prebuildargs = dc.prebuild.split(" ");
const prebuildCommand = prebuildargs.shift();
try {
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
} catch (ex) {
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
return;
Expand Down Expand Up @@ -215,7 +215,7 @@ export class ArduinoApp {

const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, "--useprogrammer",
"--pref", "programmer=" + selectProgrammer, appPath];
"--pref", "programmer=" + selectProgrammer, appPath];
if (VscodeSettings.getInstance().logLevel === "verbose") {
args.push("--verbose");
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class ArduinoApp {
const prebuildargs = dc.prebuild.split(" ");
const prebuildCommand = prebuildargs.shift();
try {
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
} catch (ex) {
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
return;
Expand Down Expand Up @@ -303,7 +303,12 @@ export class ArduinoApp {
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
return true;
} catch (reason) {
arduinoChannel.error(`Exit with code=${reason.code}${os.EOL}`);
const msg = reason.code ?
`Exit with code=${reason.code}${os.EOL}` :
reason.message ?
reason.message :
JSON.stringify(reason);
arduinoChannel.error(msg);
return false;
}

Expand All @@ -315,7 +320,7 @@ export class ArduinoApp {
return;
}
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
const cppConfig = JSON.parse(cppConfigFile) as {configurations: Array<{includePath: string[], forcedInclude: string[]}>};
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> };
const libPaths = this.getDefaultPackageLibPaths();
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
const configuration = cppConfig.configurations[0];
Expand Down
10 changes: 9 additions & 1 deletion src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as path from "path";
import * as properties from "properties";
import * as vscode from "vscode";
import * as WinReg from "winreg";
import { arduinoChannel } from "./outputChannel";

const encodingMapping: object = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../misc", "codepageMapping.json"), "utf8"));

Expand Down Expand Up @@ -208,7 +209,14 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args

let codepage = "65001";
if (os.platform() === "win32") {
codepage = childProcess.execSync("chcp").toString().split(":").pop().trim();
try {
const chcp = childProcess.execSync("chcp");
codepage = chcp.toString().split(":").pop().trim();
} catch (error) {
arduinoChannel.warning(`Defaulting to code page 850 because chcp failed.\
\rEnsure your path includes %SystemRoot%\\system32\r${error.message}`);
codepage = "850";
}
}

if (outputChannel) {
Expand Down