private void ExceptAlreadyDownloadedFiles(DriveDirectory driveDirectory)
        {
            var hashes        = Filesystem.GetFileHashes(driveDirectory.LocalPath);
            var filesToRemove = new List <DriveFile>();

            foreach (var hash in hashes)
            {
                var file = driveDirectory.Files.FirstOrDefault(f => f.Checksum == hash);

                if (file != null)
                {
                    filesToRemove.Add(file);
                }
            }

            driveDirectory.Files = driveDirectory.Files.Except(filesToRemove).ToList();
        }
Exemple #2
0
        private static async Task Main()
        {
            var thread = new Thread(() =>
            {
                Application.Run(new ClipboardNotificationWindow(cts));
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            InitializeConsole();

            var options = AppOptions.Get();

            Filesystem.Initialize(options.DownloadRootDirectory);

            await DownloadQueueObserver.ObserveAsync(options.MaxParallelDownloads, cts.Token);
        }
        internal async Task DownloadAsync(string directoryUrl, CancellationToken token)
        {
            var folder = await _driveServiceWrapper.GetDriveDirectoryAsync(directoryUrl, token);

            if (!folder.ContainsFiles)
            {
                return;
            }

            folder.LocalPath = Filesystem.CreateDirectory(folder.Name);
            ExceptAlreadyDownloadedFiles(folder);

            Parallel.ForEach(folder.Files, new ParallelOptions {
                MaxDegreeOfParallelism = _maxParallelDownloads
            }, (file) =>
            {
                var resource = _driveServiceWrapper.GetDriveFile(file.Id);

                using var stream = Filesystem.CreateFile(file.Name, folder.LocalPath);
                using var downloadProgressBar = new DownloadProgressBar(file, resource.MediaDownloader);

                var result = resource.DownloadWithStatus(stream);
            });
        }