-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
306 lines (274 loc) · 12.6 KB
/
Program.cs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Jint;
using Newtonsoft.Json;
namespace JSparkerEngine
{
internal class ProgramCore
{
private static void Main(string[] args)
{
string type = "";
var prm = new ProgramCore();
if (args != null)
{
Console.WriteLine(" _ -- Welcome To JSPY-Parker-Engine 1.0v -- _");
Console.WriteLine("note: would have a nice gui, but .net core... you know. Might do it in electron.js");
Console.WriteLine("make sure to add me to the PATH :)");
Console.WriteLine("Comand Prompt Mode: /start to start engine or enter windows command line commands");
while (true)
{
Console.Write(":> ");
string r = Console.ReadLine();
if (r == "/start")
{
break;
}
prm.ExecuteCommandSync(r);
}
Console.WriteLine("type /open to open a javascript/python file");
Console.WriteLine("");
Console.Write("Do you want python or javascript? or JSPY (javascript & python merged) (p, j or jspy): ");
type = Console.ReadLine().Trim();
if (type.ToLower() == "jspy")
{
var core = new JScore();
var main_engine = core.createEngine();
var python = new PythonClass();
while (true)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write(":");
Console.ForegroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("> ");
Console.ForegroundColor = ConsoleColor.White;
var cmd = Console.ReadLine();
try
{
object ret_final = null;
try
{
if (System.IO.File.Exists(Environment.CurrentDirectory + "\\temp.js"))
{
File.Delete(Environment.CurrentDirectory + "\\temp.js");
}
File.WriteAllText(Environment.CurrentDirectory + "\\temp.js", cmd);
var ret = core.executeJSCode(main_engine, "", "./temp");
ret_final = ret;
}
catch (Exception ii)
{
}
var check = false;
try
{
check = python.ExecutePythonCommand(cmd);
}
catch (Exception ii)
{
}
Console.WriteLine("JS: " + ret_final + ", PY:" + Convert.ToString(check));
}
catch (Exception i)
{
Console.WriteLine(i);
}
}
}
if (type.ToLower() == "j")
{
Console.WriteLine("");
var core = new JScore();
var main_engine = core.createEngine();
Console.Write("Do you want to add modules to the javascript? and add C# functions? (Y/N): ");
var check = Console.ReadLine().Trim().ToLower();
if (check == "y")
{
}
while (true)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(":> ");
Console.ForegroundColor = ConsoleColor.White;
var cmd = Console.ReadLine();
if (cmd != "")
{
if (cmd.Trim() == "/open")
{
Console.WriteLine("Please enter or paste the directory:");
var dir = Console.ReadLine();
try
{
dir = dir.Substring(0, dir.Length - 3).Replace("\\", "/");
core.executeJSCode(main_engine, "", dir);
}
catch (Exception i)
{
Console.WriteLine(i);
}
}
else
{
try
{
if (System.IO.File.Exists(Environment.CurrentDirectory + "\\temp.js"))
{
File.Delete(Environment.CurrentDirectory + "\\temp.js");
}
string[] deps =
{
"var File = require(\"file\");",
"var Zip = require(\"zip\");",
"var WebClient = require(\"webClient\");",
"var Math = require(\"math\");",
"var Environment = require(\"Environment\");",
"var console = require(\"console\");",
"var stringBuilder = require(\"stringBuilder\");",
"var array = require(\"Array\");",
"var directory = require(\"Directory\");",
"var proccess = require(\"Process\");",
"var driveInfo = require(\"DriveInfo\");",
"var exception = require(\"Exception\");",
"var thread = require(\"Thread\");",
"var encoding = require(\"Encoding\");",
"var smtpClient = require(\"SmtpClient\");",
"var cultureInfo = require(\"CultureInfo\");"
};
string[] init =
{
//s"var file = new File();",
//"var zip = new Zip();",
//"var web = new WebClient();",
//"var math = new math();"
//"var env = new Environment();",
};
string[] code = { cmd };
List<string> arr = new List<string>();
arr.AddRange(deps);
arr.AddRange(init);
arr.AddRange(code);
File.WriteAllLines(Environment.CurrentDirectory + "\\temp.js", arr.ToArray());
var ret = core.executeJSCode(main_engine, "", "./temp");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(ret);
Console.ForegroundColor = ConsoleColor.White;
}
catch (Exception i)
{
Console.WriteLine(i);
}
}
}
}
}
if(type == "p")
{
var python = new PythonClass();
while (true)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(":> ");
Console.ForegroundColor = ConsoleColor.White;
var cmd = Console.ReadLine();
if (cmd != "")
{
if (cmd.Trim() == "/open")
{
Console.WriteLine("Please enter or paste the directory:");
var dir = Console.ReadLine();
try
{
python.ExecutePythonFile(dir, false);
}
catch (Exception i)
{
Console.WriteLine(i);
}
}
else
{
python.ExecutePythonCommand(cmd);
}
}
}
}
}
else
{
try
{
string file = args[0];
if (file.Contains(".js"))
{
var core = new JScore();
var main_engine = core.createEngine();
string module = file.Substring(0, file.Length - 3).Replace("\\", "/");
core.executeJSCode(main_engine, "", module);
}
if (file.Contains(".json"))
{
string json = System.IO.File.ReadAllText(file);
var dat = JsonConvert.DeserializeObject<jsonDat>(json);
var core = new JScore();
var main_engine = core.createEngine();
foreach (string j in dat.javaScript)
{
string module = j.Substring(0, file.Length - 3).Replace("\\", "/");
core.executeJSCode(main_engine, "", module);
}
}
if (file.Contains(".py"))
{
var python = new PythonClass();
string dat = File.ReadAllText(file);
python.ExecutePythonCommand(dat);
}
}
catch(Exception i)
{
Console.WriteLine(i);
}
}
}
public Exception ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
var procStartInfo =
new ProcessStartInfo("cmd", "/c " + command)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
// Do not create the black window.
// Now we create a process, assign its ProcessStartInfo and start it
var proc = new Process { StartInfo = procStartInfo };
proc.Start();
// Get the output into a string
var result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
return null;
}
catch (Exception objException)
{
return objException;
// Log the exception
}
}
}
public class jsonDat
{
public string[] javaScript;
}
}