/// <summary> /// StartAsync seeking for updates /// </summary> /// <param name="gitHubRepoPath">Path to the GitHub repo (like: https://github.com/myuser/myrepo )</param> /// <param name="acceptPrerelease">If you want to accept prereleases as updates</param> /// <param name="accessToken">If you have an access token for the repo put it down here</param> /// <param name="myAssembly">If you want an other assembly the the calling assembly of the updater DLL file</param> public static async Task StartAsync(string gitHubRepoPath, bool showDialogs = false, bool acceptPrerelease = false, string accessToken = null, Assembly myAssembly = null) { //Update checker already running if (_working) { return; } _working = true; try { GitHubRepoPath = gitHubRepoPath; AcceptPrerelease = acceptPrerelease; AccessToken = accessToken; if (myAssembly == null) { //Return if the caller is an unmanaged application (= null) if (Assembly.GetEntryAssembly() != null) { myAssembly = Assembly.GetEntryAssembly(); } else { return; } } AppName = myAssembly.GetName().Name; CurrentVersion = myAssembly.GetName().Version; LastGitHubRelease = await GitHubApi.GitHubGetLastReleaseAsync(GitHubRepoPath, AccessToken); if (LastGitHubRelease.Version > CurrentVersion) { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { ShowUpdateWindow(); } else { var thread = new Thread(ShowUpdateWindow); thread.CurrentCulture = thread.CurrentUICulture = CultureInfo.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); } } else { if (showDialogs) { MessageBox.Show(_resManager.GetString("no_update_found_text", CultureInfo.CurrentUICulture), _resManager.GetString("no_update_found", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Information); } } _working = false; } catch (Exception ex) { _working = false; if (showDialogs) { MessageBox.Show(ex.Message, _resManager.GetString("error", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// StartAsync seeking for updates /// </summary> /// <param name="gitHubRepoPath">Path to the GitHub repo (like: https://github.com/myuser/myrepo )</param> /// <param name="showDialogs">Show error dialogs. (false = silent mode)</param> /// <param name="acceptPrerelease">If you want to accept prereleases as updates</param> /// <param name="accessToken">If you have an access token for the repo put it down here</param> /// <param name="myAssembly">If you want an other assembly the the calling assembly of the updater DLL file</param> public static async Task StartAsync(string gitHubRepoPath, bool showDialogs = false, bool acceptPrerelease = false, string accessToken = null, Assembly myAssembly = null) { //Update checker already running if (_working) { return; } _working = true; try { GitHubRepoPath = gitHubRepoPath; AcceptPrerelease = acceptPrerelease; AccessToken = accessToken; if (myAssembly == null) { myAssembly = Assembly.GetEntryAssembly(); //Return if the caller is an unmanaged application (= null) if (myAssembly == null) { return; } } var fileVersion = FileVersionInfo.GetVersionInfo(myAssembly.Location); CompanyName = fileVersion.CompanyName; AppName = string.IsNullOrWhiteSpace(fileVersion.ProductName) ? myAssembly.GetName().Name : fileVersion.ProductName; CurrentVersion = new Version(fileVersion.ProductVersion); //Use default persistence provider when it is null if (PersistenceProvider == null) { string registryLocation = !string.IsNullOrEmpty(CompanyName) ? $@"Software\{CompanyName}\{AppName}\Updater" : $@"Software\{AppName}\Updater"; PersistenceProvider = new RegistryUserPersistenceProvider(registryLocation); } LastGitHubRelease = await GitHubApi.GitHubGetLastReleaseAsync(GitHubRepoPath, AccessToken); Version skippedVersion = PersistenceProvider.GetSkippedVersion(); if (LastGitHubRelease.Version > CurrentVersion && (skippedVersion == null || LastGitHubRelease.Version != skippedVersion)) { if (skippedVersion != null) { PersistenceProvider.SetSkippedVersion(null); } if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { ShowUpdateWindow(); } else { var thread = new Thread(ShowUpdateWindow); thread.CurrentCulture = thread.CurrentUICulture = CultureInfo.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); } } else { if (showDialogs) { MessageBox.Show(ResManager.GetString("no_update_found_text", CultureInfo.CurrentUICulture), ResManager.GetString("no_update_found", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Information); } } _working = false; } catch (Exception ex) { _working = false; if (showDialogs) { MessageBox.Show(ex.Message, ResManager.GetString("error", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error); } } }