private JObject SerializeOptions(Aria2Options options) { JObject obj = new JObject(); foreach (var option in options) { var key = option.Key.ToString().Replace('_', '-'); obj[key] = option.Value; } return(obj); }
private Aria2Options DeserializeOptions(JToken obj) { var options = new Aria2Options(); foreach (var option in (JObject)obj) { if (Enum.TryParse(option.Key.Replace('-', '_'), out Aria2Option key)) { options.Add(key, option.Value.ToString()); } } return(options); }
public void Start(Aria2Options args) { if (args.TryGetValue(Aria2Option.input_file, out string input_file)) { if (!File.Exists(input_file)) { File.Create(input_file); } } if (args.TryGetValue(Aria2Option.dir, out string dir)) { args[Aria2Option.dir] = $"\"{dir.TrimEnd('\\')}\""; } args[Aria2Option.enable_rpc] = "true"; args[Aria2Option.enable_color] = "false"; args[Aria2Option.rpc_listen_port] = RPC.Port.ToString(); args[Aria2Option.rpc_secure] = RPC.Secure ? "true" : "false"; string arguments = args.Aggregate("", (str, a) => $"{str} --{a.Key.ToString().Replace('_', '-')}={a.Value}"); Process = new Process { StartInfo = new ProcessStartInfo("aria2c.exe") { Arguments = arguments, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true } }; Process.OutputDataReceived += OnOutput; Process.ErrorDataReceived += OnError; Process.Start(); Process.BeginOutputReadLine(); Process.BeginErrorReadLine(); }
public Task <string> AddUri(string[] uris, Aria2Options options = null, long position = long.MaxValue) => Call <string>("aria2.addUri", JArray.FromObject(uris), SerializeOptions(options), position);
public Task ChangeGlobalOptions(Aria2Options options) => Call("aria2.changeGlobalOption", SerializeOptions(options));
public Task ChangeOptions(string gid, Aria2Options options) => Call("aria2.changeOption", gid, SerializeOptions(options));
public Task <string> AddMetalink(string metalink, Aria2Options options = null, long position = long.MaxValue) => Call <string>("aria2.addMetalink", metalink, SerializeOptions(options), position);