feat(core): micropython 板卡文件管理 右键菜单添加 剪切 、复制 和 粘贴 选项
This commit is contained in:
@@ -125,9 +125,29 @@ class AmpyFS extends FS {
|
||||
return this.rename(oldFilePath, newFilePath);
|
||||
}
|
||||
|
||||
// async moveFile(oldFilePath, newFilePath) {}
|
||||
async moveFile(oldFilePath, newFilePath) {
|
||||
return this.rename(oldFilePath, newFilePath);
|
||||
}
|
||||
|
||||
// async copyFile(oldFilePath, newFilePath) {}
|
||||
async copyFile(oldFilePath, newFilePath) {
|
||||
let stdout = '', error = null, ampy = null;
|
||||
try {
|
||||
ampy = await this.getAmpy();
|
||||
await ampy.enter();
|
||||
stdout = await ampy.cpfile(oldFilePath, newFilePath);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
Debug.error(error);
|
||||
}
|
||||
try {
|
||||
await ampy.exit();
|
||||
await ampy.dispose();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
Debug.error(error);
|
||||
}
|
||||
return [error, stdout];
|
||||
}
|
||||
|
||||
async deleteFile(filePath) {
|
||||
let stdout = '', error = null, ampy = null;
|
||||
@@ -206,9 +226,29 @@ class AmpyFS extends FS {
|
||||
return this.rename(oldFolderPath, newFolderPath);
|
||||
}
|
||||
|
||||
// async moveDirectory(oldFolderPath, newFolderPath) {}
|
||||
async moveDirectory(oldFolderPath, newFolderPath) {
|
||||
return this.rename(oldFolderPath, newFolderPath);
|
||||
}
|
||||
|
||||
// async copyDirectory(oldFolderPath, newFolderPath) {}
|
||||
async copyDirectory(oldFolderPath, newFolderPath) {
|
||||
let stdout = '', error = null, ampy = null;
|
||||
try {
|
||||
ampy = await this.getAmpy();
|
||||
await ampy.enter();
|
||||
stdout = await ampy.cpdir(oldFolderPath, newFolderPath);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
Debug.error(error);
|
||||
}
|
||||
try {
|
||||
await ampy.exit();
|
||||
await ampy.dispose();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
Debug.error(error);
|
||||
}
|
||||
return [error, stdout];
|
||||
}
|
||||
|
||||
async deleteDirectory(folderPath) {
|
||||
let stdout = '', error = null, ampy = null;
|
||||
|
||||
@@ -28,6 +28,8 @@ class AmpyExt extends Ampy {
|
||||
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
|
||||
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
|
||||
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
|
||||
this.CPDIR = goog.readFileSync(path.join(Env.templatePath, 'python/cpdir.py'));
|
||||
this.CPFILE = goog.readFileSync(path.join(Env.templatePath, 'python/cpfile.py'));
|
||||
}
|
||||
|
||||
#device_ = null;
|
||||
@@ -338,6 +340,31 @@ class AmpyExt extends Ampy {
|
||||
return !dataError;
|
||||
}
|
||||
|
||||
async cpdir(oldname, newname, timeout = 5000) {
|
||||
if (!this.isActive()) {
|
||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||
}
|
||||
const code = Mustache.render(AmpyExt.CPDIR, {
|
||||
oldPath: oldname,
|
||||
newPath: newname
|
||||
});
|
||||
const { data, dataError } = await this.exec(code, timeout);
|
||||
console.log(data, dataError)
|
||||
return !dataError;
|
||||
}
|
||||
|
||||
async cpfile(oldname, newname, timeout = 5000) {
|
||||
if (!this.isActive()) {
|
||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||
}
|
||||
const code = Mustache.render(AmpyExt.CPFILE, {
|
||||
oldPath: oldname,
|
||||
newPath: newname
|
||||
});
|
||||
const { dataError } = await this.exec(code, timeout);
|
||||
return !dataError;
|
||||
}
|
||||
|
||||
async cwd(timeout = 5000) {
|
||||
if (!this.isActive()) {
|
||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||
|
||||
Reference in New Issue
Block a user