Esempio n. 1
0
        private static void StateToBytes(SingleSourceHTTPDownloaderState state, BinaryWriter w)
        {
            w.Write(state !.Id !);
            w.Write(state.TempDir ?? string.Empty);
            w.Write(state.FileSize);
            w.Write(state.LastModified.ToBinary());
            w.Write(state.SpeedLimit);
            w.Write(state.Url.ToString());
            var hasHeaders = state.Headers != null;

            w.Write(hasHeaders);
            if (hasHeaders)
            {
                XDM.Messaging.StreamHelper.WriteStateHeaders(state.Headers, w);
            }
            var hasCookies = state.Cookies != null;

            w.Write(hasCookies);
            if (hasCookies)
            {
                XDM.Messaging.StreamHelper.WriteStateCookies(state.Cookies, w);
            }
            var hasProxy = state.Proxy.HasValue;

            w.Write(hasProxy);
            if (hasProxy)
            {
                w.Write(state.Proxy !.Value.Host ?? string.Empty);
                w.Write(state.Proxy !.Value.Port);
                w.Write((int)state.Proxy !.Value.ProxyType);
                w.Write(state.Proxy !.Value.UserName ?? string.Empty);
                w.Write(state.Proxy !.Value.Password ?? string.Empty);
            }
            w.Write(state.ConvertToMp3);
        }
Esempio n. 2
0
        private static SingleSourceHTTPDownloaderState SingleSourceHTTPDownloaderStateFromBytes(BinaryReader r)
        {
            var state = new SingleSourceHTTPDownloaderState
            {
                Id           = r.ReadString(),
                TempDir      = XDM.Messaging.StreamHelper.ReadString(r),
                FileSize     = r.ReadInt64(),
                LastModified = DateTime.FromBinary(r.ReadInt64()),
                SpeedLimit   = r.ReadInt32(),
                Url          = new Uri(r.ReadString())
            };

            if (r.ReadBoolean())
            {
                XDM.Messaging.StreamHelper.ReadStateHeaders(r, out Dictionary <string, List <string> > headers);
                state.Headers = headers;
            }
            if (r.ReadBoolean())
            {
                XDM.Messaging.StreamHelper.ReadStateCookies(r, out Dictionary <string, string> cookies);
                state.Cookies = cookies;
            }

            if (r.ReadBoolean())
            {
                state.Proxy = new ProxyInfo
                {
                    Host      = XDM.Messaging.StreamHelper.ReadString(r),
                    Port      = r.ReadInt32(),
                    ProxyType = (ProxyType)r.ReadInt32(),
                    UserName  = XDM.Messaging.StreamHelper.ReadString(r),
                    Password  = XDM.Messaging.StreamHelper.ReadString(r),
                };
            }
            state.ConvertToMp3 = r.ReadBoolean();
            return(state);
        }
Esempio n. 3
0
 public static void Save(SingleSourceHTTPDownloaderState state)
 {
     TransactedBinaryDataReader.Write($"{state.Id}.state", Config.DataDir, w => StateToBytes(state, w));
 }