-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathromLocalTree.js
More file actions
94 lines (91 loc) · 3.29 KB
/
Copy pathromLocalTree.js
File metadata and controls
94 lines (91 loc) · 3.29 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const vscode = require('vscode');
const FileUtil = require('./fileUtil');
const os = require('os');
const path = require('path');
class RomLocalTree {
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'))) {
//if not exists create default ahost floder
try{
FileUtil.createDefaultANesFloder(this.userRoot,this.context);
}catch(e){
vscode.window.showInformationMessage('Ahost need Administrator permission!');
}
}
}
refresh(){
this._onDidChangeTreeData.fire();
}
getTreeItem(element){
return element;
}
getChildren(element) {
let romConfigFileList = FileUtil.getRomConfigFileList(this.userRoot);
console.log(`romConfigFileList ${JSON.stringify(romConfigFileList)}`);
if( romConfigFileList && romConfigFileList.length > 0){
let hostConfigs = [];
romConfigFileList.forEach((romConfig) => {
hostConfigs.push(new DataItem(romConfig.label,null,{
command:"anes.openGameBox",title:"",arguments:[romConfig]
}));
})
return hostConfigs;
}else{
return [];
}
}
deleteRom(item){
let romConfigList = FileUtil.getRomConfigFileList(this.userRoot);
if(romConfigList && romConfigList.length > 0){
let deleteIndex = -1;
romConfigList.forEach((romConfig,index)=>{
if(romConfig.label == item.label){
deleteIndex = index;
}
});
deleteIndex > -1 && romConfigList.splice(deleteIndex,1);
FileUtil.writeMetaInfo(this.userRoot,romConfigList);
this._onDidChangeTreeData.fire();
}
}
rename(item){
vscode.window.showInputBox({ placeHolder: 'Enter the new game name', value: item.label })
.then((value) => {
if(value){
let romConfigList = FileUtil.getRomConfigFileList(this.userRoot);
let exist = false;
romConfigList.forEach(romConfig=>{
if(romConfig.label == value){
exist = true;
}
});
if(exist){
vscode.window.showInformationMessage('This name is aready exist!');
}else{
romConfigList.forEach(romConfig=>{
if(romConfig.label == item.label){
romConfig.label = value;
}
});
FileUtil.writeMetaInfo(this.userRoot,romConfigList);
this._onDidChangeTreeData.fire();
}
}else{
vscode.window.showInformationMessage('Please enter your game name!');
}
});
}
}
class DataItem extends vscode.TreeItem{
constructor(label, children, command) {
super(label, vscode.TreeItemCollapsibleState.None);
this.iconPath = path.join(__filename,'..','resources', 'rom.svg');;
this.children = children;
this.command = command;
}
}
module.exports = RomLocalTree;