public async Task DownloadApp(AppInformation appInfo) { if (appInfo is null) { throw new ArgumentNullException(nameof(appInfo)); } //if (Directory.Exists(AppInformation.AppFolderPath) == false) //{ // Directory.CreateDirectory(AppInformation.AppFolderPath); // // Wait untill download. // await DownloadAppTask(appInfo, new Version()).ConfigureAwait(false); // return; //} var maxVesion = GetAppInstalledMaxVersion(appInfo); if (maxVesion is null) { // Wait untill download. await DownloadAppTask(appInfo, maxVesion).ConfigureAwait(false); } else { // Don't wait, run exising app, Download new version if exist for next time. DownloadApp(appInfo, maxVesion); } }
private static Version GetAppInstalledMaxVersion(AppInformation appInfo) { var appVersionFolderPathList = Directory.GetDirectories(AppInformation.AppFolderPath, $"{appInfo.AppVersionFolderNamePrefix}*", SearchOption.TopDirectoryOnly).ToList(); if (appVersionFolderPathList.Any() == false) { return(null); } var maxVesion = appVersionFolderPathList.Select(p => new Version(p.Split(appInfo.AppVersionFolderNamePrefix).LastOrDefault())).Max(); return(maxVesion); }
public static void RunApp(ProcessStartInfo process, AppInformation appInfo) { if (process is null) { throw new ArgumentNullException(nameof(process)); } if (appInfo is null) { throw new ArgumentNullException(nameof(appInfo)); } var appVersionExePath = GetAppMaxVersionExePath(appInfo); process.FileName = appVersionExePath; Process.Start(process); }
private static string GetAppMaxVersionExePath(AppInformation appInfo) { var maxVesion = GetAppInstalledMaxVersion(appInfo); if (maxVesion is null) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotFound, nameof(maxVesion))); } var appVersionExePath = Path.Combine(AppInformation.AppFolderPath, $"{appInfo.AppVersionFolderNamePrefix}{maxVesion}", appInfo.AppExecutableName); if (File.Exists(appVersionExePath) == false) { throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.NotFound, nameof(appVersionExePath))); } return(appVersionExePath); }
private async void DownloadApp(AppInformation appInfo, Version installedMaxVersion) { await DownloadAppTask(appInfo, installedMaxVersion).ConfigureAwait(false); }