public static void Cmd_Copy(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); //Copy File.Copy(data.strArgOne, data.strArgTwo); //Done callback(new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id), id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }
static void OnRequest(object raw, RSN_ServerResponse_Data data) { ArkIOInterfaceRequestData req = (ArkIOInterfaceRequestData)raw; req.id = data.packet.id; ArkIOInterface_Updates callback = new ArkIOInterface_Updates(OnRequestUpdate); Console.WriteLine("Command " + req.type.ToString().ToUpper() + " issued."); int id = requestNum; requestNum++; requests.Add(id, data); switch (req.type) { case RequestType.Compress: ArkIOInterfaceRequests.Cmd_Compress(id, req, callback); break; case RequestType.Copy: ArkIOInterfaceRequests.Cmd_Copy(id, req, callback); break; case RequestType.Delete: ArkIOInterfaceRequests.Cmd_Delete(id, req, callback); break; case RequestType.DirList: ArkIOInterfaceRequests.Cmd_DirList(id, req, callback); break; case RequestType.EndProcess: ArkIOInterfaceRequests.Cmd_StopProcess(id, req, callback); break; case RequestType.Move: ArkIOInterfaceRequests.Cmd_Move(id, req, callback); break; case RequestType.StartProcess: ArkIOInterfaceRequests.Cmd_StartProcess(id, req, callback); break; case RequestType.GetProcessByName: ArkIOInterfaceRequests.Cmd_GetProcessByName(id, req, callback); break; } }
public static void Cmd_DirList(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); string[] files = Directory.GetFiles(data.strArgOne); //Done var d = new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id); d.output = files; callback(d, id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }
public static void Cmd_StartProcess(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); Process p = Process.Start(data.strArgOne, data.strArgTwo); //Done var c = new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id); c.output = new string[1] { p.Id.ToString() }; callback(c, id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }
public static void Cmd_Compress(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); //Copy ZipFile.CreateFromDirectory(data.strArgOne, data.strArgTwo); //Validate ZIP string tmpDir = Path.GetTempPath() + @"RomanPort\"; if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } tmpDir += "ArkBot\\"; if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } tmpDir += "ZipVerify\\"; if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } else { //It exists. Clear it. Directory.Delete(tmpDir, true); Directory.CreateDirectory(tmpDir); } //Extract here ZipFile.ExtractToDirectory(data.strArgTwo, tmpDir); //Delete Directory.Delete(tmpDir, true); //Done callback(new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id), id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }
public static void Cmd_StopProcess(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); Process p = Process.GetProcessById(data.intArgOne); if (p == null) { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } p.CloseMainWindow(); //Done var c = new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id); callback(c, id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }
public static void Cmd_GetProcessByName(int id, ArkIOInterfaceRequestData data, ArkIOInterface_Updates callback) { try { callback(new ArkIOInterfaceResponse(0, 0, 1, false, false, data.id), id); Process[] p = Process.GetProcessesByName(data.strArgOne); List <string> s = new List <string>(); foreach (Process pr in p) { s.Add(pr.Id.ToString()); } //Done var c = new ArkIOInterfaceResponse(0, 1, 1, true, false, data.id); c.output = s.ToArray(); callback(c, id); } catch { callback(new ArkIOInterfaceResponse(0, 0, 1, false, true, data.id), id); } }