Пример #1
0
        public static bool DownloadAndExtract(this GdriveWebClient webClient, string gdriveUrl, string targetDirectory, string fileName)
        {
            if (!Str.Equals(".7z", Path.GetExtension(fileName)))
            {
                throw new ArgumentException();
            }

            string archiveFileName = targetDirectory.AddPath(fileName);

            if (File.Exists(archiveFileName))
            {
                try
                {
                    File.Delete(archiveFileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to remove {archiveFileName}: {ex.Message}");
                    return(false);
                }
            }

            try
            {
                webClient.DownloadFromGdrive(gdriveUrl, targetDirectory);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error downloading {archiveFileName} from {gdriveUrl}: {ex.Message}");
                return(false);
            }

            if (!File.Exists(archiveFileName))
            {
                Console.WriteLine($"Failed to download {archiveFileName} from {gdriveUrl}");
                return(false);
            }

            var sevenZip = new SevenZip(silent: true);

            sevenZip.Extract(archiveFileName, targetDirectory, Enumerable.Empty <string>());

            try
            {
                File.Delete(archiveFileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to remove {archiveFileName}: {ex.Message}");
            }

            return(true);
        }
Пример #2
0
        private void downloadFromGdrive(ImageDownloadProgress task, GdriveWebClient webClient)
        {
            string fileName        = task.Dir.Subdirectory + ".7z";
            string archiveFileName = task.TargetDirectory.AddPath(fileName);

            lock (_syncOutput)
                Console.WriteLine($"Downloading {task.Dir.Subdirectory} from {task.GdriveUrl}");

            if (File.Exists(archiveFileName))
            {
                try
                {
                    File.Delete(archiveFileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to remove {archiveFileName}: {ex.Message}");
                    return;
                }
            }

            try
            {
                webClient.DownloadFromGdrive(task.GdriveUrl, task.TargetDirectory);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error downloading {archiveFileName} from {task.GdriveUrl}: {ex.Message}");
                return;
            }

            if (!File.Exists(archiveFileName))
            {
                Console.WriteLine($"Failed to download {archiveFileName} from {task.GdriveUrl}");
                return;
            }

            var sevenZip = new SevenZip(silent: true);

            sevenZip.Extract(archiveFileName, task.TargetDirectory, Enumerable.Empty <string>());

            Interlocked.Add(ref _countInDownloadedDirs, task.FilesOnline.Count - task.FilesDownloaded.Count);
            ProgressChanged?.Invoke();

            try
            {
                File.Delete(archiveFileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to remove {archiveFileName}: {ex.Message}");
            }
        }
Пример #3
0
        public static void TryDownload(this GdriveWebClient webClient, string url, string targetDirectory, string description)
        {
            Console.Write($"Download {description} from {url} ...");

            try
            {
                webClient.DownloadFromGdrive(url, targetDirectory);
            }
            catch (Exception ex)
            {
                Console.WriteLine($" {ex}");
                return;
            }

            Console.WriteLine(" done");
        }