-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathromRemoteTree.js
More file actions
73 lines (70 loc) · 2.62 KB
/
Copy pathromRemoteTree.js
File metadata and controls
73 lines (70 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const vscode = require('vscode');
const FileUtil = require('./fileUtil');
const os = require('os');
const path = require('path');
const fs = require('fs');
class RomRemoteTree {
constructor(context){
this.context = context;
this.userRoot = os.homedir();
this._onDidChangeTreeData = new vscode.EventEmitter();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
if(!FileUtil.pathExists(path.join(this.userRoot, '.anes','remote'))) {
//if not exists create default ahost floder
try{
//FileUtil.createDefaultAHostFloder(this.userRoot,this.context);
}catch(e){
//vscode.window.showInformationMessage('Ahost need Administrator permission!');
}
}
}
refresh(){
this._onDidChangeTreeData.fire();
}
getTreeItem(element){
return element;
}
getChildren(element) {
let remoteRomConfig = FileUtil.getRemoteRomConfig(this.userRoot);
let remoteMeta = fs.readFileSync(path.join(this.userRoot, '.anes', 'remote','meta.json'));
remoteMeta = remoteMeta.toString();
remoteMeta = JSON.parse(remoteMeta);
let remoteMetaMap = {};
remoteMeta.forEach((meta)=>{
remoteMetaMap[meta.name] = meta;
});
if(remoteRomConfig && remoteRomConfig.length >0){
let remoteRomList = [];
remoteRomConfig.forEach((config)=>{
let meta = remoteMetaMap[config.name] ? remoteMetaMap[config.name] : {}
remoteRomList.push(new DataItem({
label:config.name,
url:config.url,
children: null,
command: null,
downloadStatus: meta.downloadStatus,
fileName: config.fileName,
nesName: config.nesName
}));
});
return remoteRomList;
}else{
return [];
}
}
}
class DataItem extends vscode.TreeItem{
constructor({label, url, children, command, downloadStatus,fileName,nesName}) {
super(label, vscode.TreeItemCollapsibleState.None);
downloadStatus = downloadStatus ? downloadStatus : 0; // download 0 downloading 1 downloaded 2
console.log(`downloadStatus:${downloadStatus}`);
this.downloadStatus = downloadStatus;
this.iconPath = path.join(__filename,'..','resources', `d0.svg`);
this.children = children;
this.command = command;
this.url = url;
this.fileName = fileName;
this.nesName= nesName;
}
}
module.exports = RomRemoteTree;