public static async Task <InstalledSoftware> InstallAsync(SoftwareDescription softwareDescription) { var installPath = GetInstallPath(softwareDescription); var isInstalled = Directory.Exists(installPath); if (isInstalled) { LogHelper.Log.Information($"{softwareDescription}' is already installed"); return(new InstalledSoftware(softwareDescription, installPath)); } LogHelper.Log.Information($"{softwareDescription} not installed, installing it"); var tempDownload = Path.Combine( Path.GetTempPath(), $"{softwareDescription.ShortName}-v{softwareDescription.Version}-{Guid.NewGuid():N}.zip"); try { await DownloadFileAsync(softwareDescription.DownloadUri, tempDownload).ConfigureAwait(false); ExtractZipFile(tempDownload, installPath); return(new InstalledSoftware(softwareDescription, installPath)); } finally { if (File.Exists(tempDownload)) { File.Delete(tempDownload); } } }
internal InstalledSoftware( SoftwareDescription description, string installPath) { if (description == null) { throw new ArgumentNullException(nameof(description)); } if (string.IsNullOrEmpty(installPath)) { throw new ArgumentNullException(nameof(installPath)); } Description = description; InstallPath = installPath; }
private static string GetInstallPath(SoftwareDescription softwareDescription) { return(Path.Combine( Path.GetTempPath(), $"eventflow-{softwareDescription.ShortName}-v{softwareDescription.Version}")); }