Пример #1
0
        public static DualSourceHTTPDownloadInfo?LoadDualSourceHTTPDownloadInfo(string id)
        {
            try
            {
                using var s = new FileStream(Path.Combine(Config.DataDir, id + ".info"), FileMode.Open);
                using var r = new BinaryReader(s);

                var info = new DualSourceHTTPDownloadInfo
                {
                    Uri1          = StreamHelper.ReadString(r),
                    Uri2          = StreamHelper.ReadString(r),
                    File          = StreamHelper.ReadString(r),
                    ContentLength = r.ReadInt64()
                };
                StreamHelper.ReadStateHeaders(r, out Dictionary <string, List <string> > headers1);
                info.Headers1 = headers1;
                StreamHelper.ReadStateHeaders(r, out Dictionary <string, List <string> > headers2);
                info.Headers2 = headers2;
                StreamHelper.ReadStateCookies(r, out Dictionary <string, string> cookies1);
                info.Cookies1 = cookies1;
                StreamHelper.ReadStateCookies(r, out Dictionary <string, string> cookies2);
                info.Cookies2 = cookies2;
                return(info);
            }
            catch (Exception ex)
            {
                Log.Debug(ex, ex.Message);
            }
            return(null);
        }
Пример #2
0
 public bool LinkAccepted(DualSourceHTTPDownloadInfo info)
 {
     if (refreshLinkCandidate != null && IsMatchingDualSourceLink(info))
     {
         HandleDualSourceLinkRefresh(info);
         return(true);
     }
     return(false);
 }
Пример #3
0
 private bool IsMatchingDualSourceLink(DualSourceHTTPDownloadInfo info)
 {
     if (!(refreshLinkCandidate is DualSourceHTTPDownloader))
     {
         return(false);
     }
     return(info.ContentLength > 0 &&
            ((DualSourceHTTPDownloader)refreshLinkCandidate).FileSize == info.ContentLength);
 }
Пример #4
0
 private void HandleDualSourceLinkRefresh(DualSourceHTTPDownloadInfo info)
 {
     if (refreshLinkCandidate == null)
     {
         return;
     }
     ((DualSourceHTTPDownloader)refreshLinkCandidate).SetDownloadInfo(info);
     refreshLinkCandidate = null;
     RefreshedLinkReceived?.Invoke(this, EventArgs.Empty);
     ClearRefreshRecivedEvents();
 }
Пример #5
0
 public static void SaveDownloadInfo(string id, DualSourceHTTPDownloadInfo info)
 {
     using var s = new FileStream(Path.Combine(Config.DataDir, id + ".info"), FileMode.Create);
     using var w = new BinaryWriter(s);
     WriteStringSafe(info.Uri1, w);
     WriteStringSafe(info.Uri2, w);
     WriteStringSafe(info.File, w);
     w.Write(info.ContentLength);
     StreamHelper.WriteStateHeaders(info.Headers1, w);
     StreamHelper.WriteStateHeaders(info.Headers2, w);
     StreamHelper.WriteStateCookies(info.Cookies1, w);
     StreamHelper.WriteStateCookies(info.Cookies2, w);
     //File.WriteAllText(Path.Combine(Config.DataDir, id + ".info"), JsonConvert.SerializeObject(downloadInfo));
 }