Fix: 修复electron环境下ampy读取文件时的中文乱码问题
This commit is contained in:
@@ -23,6 +23,7 @@ class AmpyFS extends FS {
|
|||||||
#ampy_ = null;
|
#ampy_ = null;
|
||||||
#port_ = '';
|
#port_ = '';
|
||||||
#baud_ = 115200;
|
#baud_ = 115200;
|
||||||
|
#decoder_ = new TextDecoder('utf8');
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -58,7 +59,7 @@ class AmpyFS extends FS {
|
|||||||
try {
|
try {
|
||||||
const output = await this.#ampy_.get(this.#port_, this.#baud_, filePath);
|
const output = await this.#ampy_.get(this.#port_, this.#baud_, filePath);
|
||||||
stdout = output.stdout;
|
stdout = output.stdout;
|
||||||
stdout = stdout.replaceAll('\r\r', '\r');
|
stdout = this.#decoder_.decode(this.#ampy_.unhexlify(stdout));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
Debug.error(error);
|
Debug.error(error);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class AmpyExt extends Ampy {
|
|||||||
ampy: this.AMPY_PATH
|
ampy: this.AMPY_PATH
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#exec_ = util.promisify(child_process.exec);
|
#exec_ = util.promisify(child_process.exec);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import platform
|
|||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
import serial.serialutil
|
import serial.serialutil
|
||||||
|
import binascii
|
||||||
import click
|
import click
|
||||||
import dotenv
|
import dotenv
|
||||||
|
|
||||||
@@ -157,9 +157,11 @@ def get(remote_file, local_file):
|
|||||||
contents = board_files.get(remote_file)
|
contents = board_files.get(remote_file)
|
||||||
# Print the file out if no local file was provided, otherwise save it.
|
# Print the file out if no local file was provided, otherwise save it.
|
||||||
if local_file is None:
|
if local_file is None:
|
||||||
print(contents.decode("utf-8"))
|
contents = str(contents)[2:-1]
|
||||||
|
print(contents, end='')
|
||||||
else:
|
else:
|
||||||
local_file.write(contents)
|
value = binascii.unhexlify(contents)
|
||||||
|
local_file.write(value.decode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
import ast
|
import ast
|
||||||
import textwrap
|
import textwrap
|
||||||
import binascii
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pyboard import PyboardError
|
from pyboard import PyboardError
|
||||||
@@ -84,7 +83,7 @@ class Files(object):
|
|||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
raise ex
|
raise ex
|
||||||
self._pyboard.exit_raw_repl()
|
self._pyboard.exit_raw_repl()
|
||||||
return binascii.unhexlify(out)
|
return out
|
||||||
|
|
||||||
def ls(self, directory="/", long_format=True, recursive=False, exit_repl=True):
|
def ls(self, directory="/", long_format=True, recursive=False, exit_repl=True):
|
||||||
"""List the contents of the specified directory (or root if none is
|
"""List the contents of the specified directory (or root if none is
|
||||||
|
|||||||
Reference in New Issue
Block a user