This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFile.class.js
More file actions
135 lines (124 loc) · 4.19 KB
/
Copy pathFile.class.js
File metadata and controls
135 lines (124 loc) · 4.19 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
var temp = require('temp').track(),
fs = require('fs'),
struct_languages = require('./language.struct.js'),
child_process = require('child_process'),
path = require('path');
function File(currentConsole, options) {
this.console = currentConsole;
base = this;
if (typeof options == "undefined" || typeof options.language == "undefined") {
this.language = "C";
} else {
this.language = options.language;
}
if (typeof options == "undefined" || typeof options.path == "undefined") {
temp.open({
suffix: struct_languages[base.language].extension
}, function(err, info) {
console.log(info);
if (err) throw err;
base.path = info.path;
base.basename = path.basename(base.path, struct_languages[base.language].extension);
base.folder = path.dirname(base.path);
fs.close(info.fd, function(err) {
if (err) throw err;
// Do something with the file
});
});
this.temp = true;
} else {
this.path = options.path;
this.basename = path.basename(this.path, struct_languages[base.language].extension);
console.log(this.basename);
this.folder = path.dirname(this.path);
this.temp = false;
}
this.child_options = {};
if(struct_languages[base.language].envhack){
$("#loading").show();
$("#btnstart").prop("disabled", true);
child_process.exec('"%VS140COMNTOOLS%\\VsDevCmd.bat" && SET', function(error, stdout, stderr){
base.child_options = {env: {}};
var lines = stdout.split('\n');
for (var i = 0; i < lines.length - 1; i++) {
var pair = lines[i].split('=');
base.child_options.env[pair[0]] = pair[1].toString().trim();
}
$("#btnstart").prop("disabled", false);
$("#loading").hide();
});
}
}
File.prototype.changePath = function(newPath) {
this.path = newPath;
this.temp = false;
base.basename = path.basename(this.path, struct_languages[this.language].extension);
this.folder = path.dirname(this.path);
};
File.prototype.save = function(text, callback) {
console.log(this.path);
fs.writeFile(this.path, text, function() {
callback.call(this);
});
};
File.prototype.changeLanguage = function(language) {
this.language = language;
if (this.temp) {
temp.open({
suffix: struct_languages[base.language].extension
}, function(err, info) {
console.log(info);
if (err) throw err;
base.path = info.path;
base.basename = path.basename(base.path, struct_languages[base.language].extension);
base.folder = path.dirname(base.path);
fs.close(info.fd, function(err) {
if (err) throw err;
// Do something with the file
});
});
this.temp = true;
}
};
File.prototype.compile = function(callback) {
var base = this;
var command = struct_languages[this.language].compile(this.folder, this.basename);
console.log(command);
this.console.clear();
child_process.exec(command, this.child_options, function (error, stdout, stderr) {
base.console.postMsg(stdout);
base.console.postError(stderr);
callback.call(this);
if (error !== null) {
base.console.postError('exec error ' + error);
}
});
};
File.prototype.run = function() {
var base = this;
if (this.language == "Java") {
// Get class name
var getClass = 'java -jar tools\\parsejava-all-1.0.jar ' + this.folder + '\\' + this.basename + '.java';
child_process.exec(getClass, this.child_options, function(error, stdout, stderr) {
var command = struct_languages[base.language].run(base.folder, stdout);
console.log(command);
child_process.exec(command, base.child_options, function(error2, stdout2, stderr2) {
base.console.postMsg(stdout2);
base.console.postError(stderr2);
if (error !== null) {
base.console.postError('exec error ' + error2);
}
});
});
} else {
var command = struct_languages[this.language].run(this.folder, this.basename);
child_process.exec(command, this.child_options, function(error, stdout, stderr) {
base.console.postMsg(stdout);
base.console.postError(stderr);
if (error !== null) {
base.console.postError('exec error ' + error);
}
});
}
};
module.exports = File;