示例#1
0
        private async Task DownloadFileAsync(ToolUpdate update)
        {
            if (update.Status != ToolUpdateStatus.NoUpdateAvailable || _settings.ReloadTools)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(update.DestinationPath));

                try
                {
                    await _simpleHttpClient.DownloadToFileAsync(
                        update.LatestDownload.Url,
                        update.DestinationPath,
                        _progress).ConfigureAwait(false);

                    try
                    {
                        await ArchiveUtility.TestAsync(
                            update.LatestDownload.Format,
                            update.DestinationPath).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        throw new TorSharpException(
                                  $"The tool downloaded from '{update.LatestDownload.Url.AbsoluteUri}' could not be read as a " +
                                  $"{ArchiveUtility.GetFileExtension(update.LatestDownload.Format)} file.", ex);
                    }
                }
                catch
                {
                    try
                    {
                        File.Delete(update.DestinationPath);
                    }
                    catch
                    {
                        // Best effort.
                    }

                    throw;
                }
            }
        }
示例#2
0
 public ToolUpdates(ToolUpdate privoxy, ToolUpdate tor)
 {
     Privoxy = privoxy ?? throw new ArgumentNullException(nameof(privoxy));
     Tor     = tor ?? throw new ArgumentNullException(nameof(tor));
 }