Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 public Task <string> AddUri(string[] uris, Aria2Options options = null, long position = long.MaxValue)
 => Call <string>("aria2.addUri", JArray.FromObject(uris), SerializeOptions(options), position);
Exemplo n.º 5
0
 public Task ChangeGlobalOptions(Aria2Options options) => Call("aria2.changeGlobalOption", SerializeOptions(options));
Exemplo n.º 6
0
 public Task ChangeOptions(string gid, Aria2Options options) => Call("aria2.changeOption", gid, SerializeOptions(options));
Exemplo n.º 7
0
 public Task <string> AddMetalink(string metalink, Aria2Options options = null, long position = long.MaxValue)
 => Call <string>("aria2.addMetalink", metalink, SerializeOptions(options), position);