/// <inheritdoc /> public override async Task SaveFileAsync(string filePath, IMsiService msiService, IProgress <double> progress = null, CancellationToken cancellationToken = default) { if (String.IsNullOrEmpty(FilePath)) { throw new Exception("FilePath is null"); } if (!File.Exists(FilePath)) { throw new Exception("Source file doesn't exist"); } if (File.Exists(filePath)) { throw new ArgumentException("Target file already exists"); } try { using (var sourceFile = File.OpenRead(FilePath)) using (var targetFile = File.Create(filePath)) { cancellationToken.ThrowIfCancellationRequested(); if (progress == null) { await sourceFile.CopyToAsync(targetFile, 81920, cancellationToken); return; } var totalBytes = sourceFile.Length; var progressReporter = new Progress <long>(bytesCopied => progress.Report((double)bytesCopied / totalBytes)); await sourceFile.CopyToAsync(targetFile, progressReporter, cancellationToken : cancellationToken); } await ReadMsiMetadata(filePath, msiService); } catch { try { File.Delete(filePath); } catch { } throw; } }
public ViewModelService(IDialogService dialogService, IThemeService themeService, INotificationService notificationService, IProgressBarService progressBarService, IConfigurationService configurationService, IInstallService installService, IProductService productService, IMsiService msiService, IInstallerFileBundleProviderFactory installerFileBundleProviderFactory, IUriService uriService, IClipboardService clipboardService, IIOService ioService, string tmpFolderPath) { _dialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService)); _themeService = themeService ?? throw new ArgumentNullException(nameof(themeService)); _notificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService)); _progressBarService = progressBarService ?? throw new ArgumentNullException(nameof(progressBarService)); _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); _installService = installService ?? throw new ArgumentNullException(nameof(installService)); _productService = productService ?? throw new ArgumentNullException(nameof(productService)); _msiService = msiService ?? throw new ArgumentNullException(nameof(msiService)); _installerFileBundleProviderFactory = installerFileBundleProviderFactory ?? throw new ArgumentNullException(nameof(installerFileBundleProviderFactory)); _uriService = uriService ?? throw new ArgumentNullException(nameof(uriService)); _clipboardService = clipboardService ?? throw new ArgumentNullException(nameof(clipboardService)); _ioService = ioService ?? throw new ArgumentNullException(nameof(ioService)); if (String.IsNullOrEmpty(tmpFolderPath)) { throw new ArgumentNullException(nameof(tmpFolderPath)); } _downloadFolderPath = GetDownloadFolderPath(tmpFolderPath); _logFolderPath = GetLogFolderPath(tmpFolderPath); }
protected async Task ReadMsiMetadata(string filePath, IMsiService msiService) { await Task.Run(() => { using (var metadata = msiService.GetMsiMetadata(filePath)) { Name = metadata.GetProperty(MsiPropertyName.ProductName); if (String.IsNullOrEmpty(Name)) { throw new Exception($"MSI installer \"{FileName}\" has no ProductName property. This property is REQUIRED according to the official documentation: https://docs.microsoft.com/en-us/windows/desktop/msi/productname"); } var languageString = metadata.GetProperty(MsiPropertyName.ProductLanguage); if (String.IsNullOrEmpty(languageString)) { throw new Exception($"MSI installer \"{FileName}\" has no ProductLanguage property. This property is REQUIRED according to the official documentation: https://docs.microsoft.com/en-us/windows/desktop/msi/productlanguage"); } if (!int.TryParse(languageString, out var languageId)) { throw new Exception($"Parsing the ProductLanguage of MSI installer \"{FileName}\" failed. (got: {languageString})"); } Culture = new CultureInfo(languageId); var versionString = metadata.GetProperty(MsiPropertyName.ProductVersion); if (String.IsNullOrEmpty(versionString)) { throw new Exception($"MSI installer \"{FileName}\" has no ProductVersion property. This property is REQUIRED according to the official documentation: https://docs.microsoft.com/en-us/windows/desktop/msi/productversion"); } Version = null; ProductCode = metadata.GetProperty(MsiPropertyName.ProductCode); if (String.IsNullOrEmpty(ProductCode)) { throw new Exception($"MSI installer \"{FileName}\" has no ProductCode property. This property is REQUIRED according to the official documentation: https://docs.microsoft.com/en-us/windows/desktop/msi/productcode"); } } }); }
/// <inheritdoc /> public abstract Task SaveFileAsync(string filePath, IMsiService msiService, IProgress <double> progress = null, CancellationToken cancellationToken = default);