Пример #1
0
        private void downloadFromGdrive(ImageDownloadProgress task, GdriveWebClient webClient)
        {
            string fileName        = task.Dir.Subdirectory + ".7z";
            string targetDirectory = task.TargetDirectory;
            string gdriveUrl       = task.GdriveUrl;

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

            if (!webClient.DownloadAndExtract(gdriveUrl, targetDirectory, fileName))
            {
                return;
            }

            Interlocked.Add(ref _countInDownloadedDirs, task.FilesOnline.Count - task.FilesDownloaded.Count);
            ProgressChanged?.Invoke();
        }
Пример #2
0
        public void Download(string storageUrl, string targetDirectory, string name, bool silent = false, int?timeoutSec = null)
        {
            if (_process != null)
            {
                throw new InvalidOperationException("Download is already running. Use another instance to start new download.");
            }

            _silent = silent;

            lock (_syncSelfdownload)
                if (!File.Exists(MegadlExePath))
                {
                    var webClient = new GdriveWebClient();
                    webClient.DownloadAndExtract(_megatoolsUrl, AppDir.Update, "megatools.7z");
                }

            DownloadedCount = 0;

            string arguments;

            if (targetDirectory.Contains(' '))
            {
                arguments = $@"--path=""{targetDirectory}"" --print-names {storageUrl}";
            }
            else
            {
                arguments = $@"--path={targetDirectory} --print-names {storageUrl}";
            }

            _process = new Process
            {
                StartInfo = new ProcessStartInfo(MegadlExePath, arguments)
                {
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true
                },

                EnableRaisingEvents = true
            };

            _process.OutputDataReceived += downloadOutputReceived;
            _process.ErrorDataReceived  += downloadErrorReceived;

            if (!_silent)
            {
                Console.WriteLine("Downloading {0} from {1} to {2}", name, storageUrl, targetDirectory);
            }

            AppDomain.CurrentDomain.ProcessExit += processExit;
            _process.Start();
            _process.BeginOutputReadLine();
            _process.BeginErrorReadLine();

            if (timeoutSec.HasValue)
            {
                _process.WaitForExit(timeoutSec.Value * 1000);
            }
            else
            {
                _process.WaitForExit();
            }

            Abort();
        }