private static DownloadData Load(DownloadControllerOptions options)
 {
     try
     {
         var json = options.Storage.ReadAllText(options.DownloadingInfoPath);
         return(JsonSerializer.Deserialize <DownloadData>(json));
     }
     catch
     {
         return(new DownloadData());
     }
 }
 private DownloadController(DownloadControllerOptions options, DownloadData downloadData)
     : base(new DownloaderOptions()
 {
     Uri = options.Uri,
     DownloadedRanges  = downloadData.DownloadedRanges,
     AutoDisposeStream = true,
     IsStopped         = options.IsStopped,
     AllowResuming     = options.AllowResuming,
     MaxPartCount      = options.MaxPartCount,
     MaxRetryCount     = options.MaxRetryCount,
     PartSize          = options.PartSize,
     WriteBufferSize   = options.WriteBufferSize,
 })
 {
     DownloadPath         = options.DownloadPath;
     _downloadingInfoPath = options.DownloadingInfoPath;
     _downloadingPath     = options.DownloadingPath;
     _storage             = options.Storage;
 }
        public static DownloadController Create(DownloadControllerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.DownloadPath == null)
            {
                throw new ArgumentNullException(nameof(options.DownloadPath));
            }
            options.DownloadingPath ??= options.DownloadPath + options.DownloadingExtension;
            options.DownloadingInfoPath ??= options.DownloadPath + options.DownloadingInfoExtension;

            var downloadData = Load(options);

            options.Uri ??= downloadData.Uri ?? throw new ArgumentNullException(nameof(options.Uri));
            var ret = new DownloadController(options, downloadData);

            if (!options.IsStopped)
            {
                ret.Init().GetAwaiter();
            }
            return(ret);
        }