Ejemplo n.º 1
0
        static async Task Start(CommandOptions options)
        {
            //string link = "https://github.com/OpenShot/openshot-qt/releases/download/v2.4.1/OpenShot-v2.4.1-x86_64.dmg";
            //string link = "http://www.itu.edu.tr/docs/default-source/KurumsalKimlik-2017/itu-sunum.rar?sfvrsn=2";
            //var link = "https://media.forgecdn.net/files/2573/89/DBM-Core-7.3.31.zip";
            // if (options.ClearConsole)
            Console.Clear();

            var downloadOptions = new Options();

            downloadOptions.BufferSize = options.BufferSize;
            downloadOptions.Override   = options.Override;
            downloadOptions.Timeout    = options.Timeout;
            downloadOptions.Startover  = options.Startover;
            if (options.PartitionCount != 0)
            {
                downloadOptions.PartitionCount = options.PartitionCount;
            }

            if (!string.IsNullOrEmpty(options.OutputFolder))
            {
                downloadOptions.OutputFolder = options.OutputFolder;
            }
            else if (options.DownloadFolder)
            {
                downloadOptions.OutputFolder =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");
            }

            Console.CancelKeyPress += Exit;
            downloader              = new Downloader(options.Link, downloadOptions);
            downloader.Progress    += ReportProgress;

            TimeLog.WriteLine("Preparing");

            if (options.Startover)
            {
                TimeLog.WriteLine("The download startover.");
            }

            var status = await downloader.PrepareAsync();

            TimeLog.WriteLine($"Source {downloader.Url}, {(status.IsRangeSupported ? "Range is supported" : "Range is not supported") }");
            TimeLog.WriteLine($"File Name {downloader.FileName}, Size {downloader.Length.AsReadable()}");
            _continued = status.Continued;

            if (status.Continued)
            {
                TimeLog.WriteLine($"Download is continued");
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            top = Console.CursorTop;

            await downloader.StartAsync();

            Console.SetCursorPosition(0, top + downloader.PartitionCount);
            if (downloader.ConnectionLost)
            {
                TimeLog.WriteLine("Connection is lost.");
            }

            if (downloader.SourceException)
            {
                TimeLog.WriteLine("There exist a problem with source.");
            }

            if (!downloader.Canceled)
            {
                TimeLog.WriteLine("Merging partitions.");
                var path = await downloader.MergeAsync();

                sw.Stop();
                TimeLog.WriteLine($"Total elapsed time {sw.ElapsedMilliseconds} ms");
                TimeLog.WriteLine("Download is finished.");
                TimeLog.WriteLine($"File path: {path}");
            }
            else
            {
                TimeLog.WriteLine("Download is canceled.");
                sw.Stop();
                TimeLog.WriteLine($"Total elapsed time {sw.ElapsedMilliseconds} ms");
            }
        }
Ejemplo n.º 2
0
 static void ArgumentError(string text)
 {
     TimeLog.WriteLine(text);
     Environment.Exit(-1);
 }