Example #1
0
        public async Task DownloadAppSignature(CancellationToken token)
        {
            ensureFileDeleted(_appOnlineSignatureFile);
            _updateAppDir.CreateDirectory();
            var client = new YandexDiskClientWrapper(new YandexDiskClient(), _appSourceConfig.YandexKey);
            await client.TryDownloadFile(_appSourceConfig.FileListUrl, _appOnlineSignatureFile, token);

            AppOnlineSignature = getAppOnlineSignature();
        }
Example #2
0
        public async Task DownloadApp(CancellationToken token)
        {
            var    expectedSignature = AppOnlineSignature;
            FsPath appOnline         = _updateAppDir.Join(expectedSignature.Path);

            ensureFileDeleted(appOnline);
            _updateAppDir.CreateDirectory();
            var    client = new YandexDiskClientWrapper(new YandexDiskClient(), _appSourceConfig.YandexKey);
            string url    = string.Format(_appSourceConfig.ZipUrl, expectedSignature.Path);
            await client.TryDownloadFile(url, appOnline, token);
        }
Example #3
0
        public async Task <bool> Download(ImageDownloadProgress task, CancellationToken token)
        {
            var    client     = new YandexDiskClientWrapper(_client, task.ImageSource.YandexKey, _syncOutput);
            string remotePath = task.ImageSource.GetYandexDiskPath(task.QualityGroup, task.Dir.Subdir);
            bool   success    = await client.DownloadAndExtract(remotePath, task.TargetDirectory, task.Dir.Subdir.Concat(".7z"), token);

            if (success)
            {
                ProgressChanged?.Invoke(task);
            }

            return(success);
        }
Example #4
0
        public async Task Download(string storageUrl, FsPath targetDirectory, string name, CancellationToken token, 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;

            await _syncSelfDownload.WaitAsync(token);

            try
            {
                if (!MegadlExePath.IsFile())
                {
                    var webClient = new YandexDiskClientWrapper(new YandexDiskClient(), _yandexKey);
                    // alternatively download from https://yadi.sk/d/f1HuKUg7xW2FUQ/tools?w=1
                    await webClient.DownloadAndExtract(_megatoolsUrl, AppDir.Update, new FsPath("megatools.7z"), token);
                }
            }
            finally
            {
                _syncSelfDownload.Release();
            }

            DownloadedCount = 0;

            string arguments;

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

            _process = new Process
            {
                StartInfo = new ProcessStartInfo(MegadlExePath.Value, 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();
        }