Skip to content

Commit

Permalink
Merge pull request #125 from github0null/dev
Browse files Browse the repository at this point in the history
[fixed] Enum serialport failed when use `65001` code-page in windows os.
  • Loading branch information
github0null authored May 10, 2022
2 parents 7965940 + 1c9e0ae commit 719425e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

***

### [v3.5.3]
### [v3.5.4]

**Fixed**:
- Duplicated include path items: `.eide/deps` in project.
- Can not parse old version `JLinkDevices.xml`.
- Enum serialport failed when use `65001` code-page in windows os.

**Optimized**:
- Optimize cpptools config provider for `gcc` family compilers.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/github0null/eide/blob/master/README.md",
"license": "MIT",
"description": "A mcu development environment for 8051/AVR/STM8/Cortex-M/RISC-V",
"version": "3.5.3",
"version": "3.5.4",
"preview": false,
"engines": {
"vscode": "^1.63.0"
Expand Down Expand Up @@ -60,7 +60,7 @@
"readme": "https://github.com/github0null/eide/blob/master/README.md",
"bugs": {
"url": "https://github.com/github0null/eide/issues",
"email": "[email protected]"
"email": "[email protected]"
},
"repository": {
"url": "https://github.com/github0null/eide.git",
Expand Down
20 changes: 20 additions & 0 deletions src/CodeConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ export enum CodeType {

export class CodeConverter {

static trimUtf8BomHeader(str: string | Buffer): string {

if (str instanceof Buffer) {
if (str[0] == 0xef &&
str[1] == 0xbb &&
str[2] == 0xbf) {
str = str.subarray(3);
}
return str.toString();
}

if (str.charCodeAt(0) == 0xef &&
str.charCodeAt(1) == 0xbb &&
str.charCodeAt(2) == 0xbf) {
return str.substr(3);
}

return str;
}

private getCodeType(bomHead: Buffer): CodeType {

let codeType: CodeType;
Expand Down
5 changes: 3 additions & 2 deletions src/ResManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SettingManager } from "./SettingManager";
import * as utility from './utility'
import { CmdLineHandler } from "./CmdLineHandler";
import * as yaml from 'yaml';
import { CodeConverter } from "./CodeConverter";

let resManager: ResManager | undefined;

Expand Down Expand Up @@ -165,8 +166,8 @@ export class ResManager extends events.EventEmitter {
enumSerialPort(): string[] {
try {
const cmd = `${this.getMonoName()} "${this.getSerialPortExe().path}"`;
const data = ChildProcess.execSync(cmd, { env: process.env }).toString();
const portList: string[] = JSON.parse(data);
const data = ChildProcess.execSync(cmd, { env: process.env });
const portList: string[] = JSON.parse(CodeConverter.trimUtf8BomHeader(data));
if (!Array.isArray(portList)) { throw Error("get current port list error !"); }
return portList;
} catch (error) {
Expand Down

0 comments on commit 719425e

Please sign in to comment.