private string GetUpdateChannel(FFNxUpdateChannelOptions channel) { switch (channel) { case FFNxUpdateChannelOptions.Stable: return("https://api.github.com/repos/julianxhokaxhiu/FFNx/releases/latest"); case FFNxUpdateChannelOptions.Canary: return("https://api.github.com/repos/julianxhokaxhiu/FFNx/releases/tags/canary"); default: return(""); } }
public void DownloadAndExtractLatestVersion(FFNxUpdateChannelOptions channel) { DownloadItem download = new DownloadItem() { Links = new List <string>() { LocationUtil.FormatHttpUrl(GetUpdateChannel(channel)) }, SaveFilePath = GetUpdateInfoPath(), Category = DownloadCategory.AppUpdate, ItemName = $"Fetching the latest FFNx version using channel {Sys.Settings.FFNxUpdateChannel.ToString()}..." }; download.IProc = new Install.InstallProcedureCallback(e => { bool success = (e.Error == null && e.Cancelled == false); if (success) { try { StreamReader file = File.OpenText(download.SaveFilePath); dynamic release = JValue.Parse(file.ReadToEnd()); file.Close(); File.Delete(download.SaveFilePath); Version newVersion = new Version(GetUpdateVersion(release.name.Value)); DownloadAndExtract(GetUpdateReleaseUrl(release.assets), newVersion.ToString()); } catch (Exception) { MessageDialogWindow.Show("Something went wrong while checking for FFNx updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); Sys.Message(new WMessage() { Text = $"Could not parse the FFNx release json at {GetUpdateChannel(channel)}", LoggedException = e.Error }); } } else { MessageDialogWindow.Show("Something went wrong while checking for FFNx updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); Sys.Message(new WMessage() { Text = $"Could not fetch for FFNx updates at {GetUpdateChannel(channel)}", LoggedException = e.Error }); } }); Sys.Downloads.AddToDownloadQueue(download); }
public void CheckForUpdates(FFNxUpdateChannelOptions channel) { try { _currentDriverVersion = FileVersionInfo.GetVersionInfo( Path.Combine(Sys.InstallPath, "FFNx.dll") ); } catch (FileNotFoundException) { _currentDriverVersion = null; } DownloadItem download = new DownloadItem() { Links = new List <string>() { LocationUtil.FormatHttpUrl(GetUpdateChannel(channel)) }, SaveFilePath = GetUpdateInfoPath(), Category = DownloadCategory.AppUpdate, ItemName = $"Checking for FFNx Updates using channel {Sys.Settings.FFNxUpdateChannel.ToString()}..." }; download.IProc = new Install.InstallProcedureCallback(e => { bool success = (e.Error == null && e.Cancelled == false); if (success) { try { StreamReader file = File.OpenText(download.SaveFilePath); dynamic release = JValue.Parse(file.ReadToEnd()); file.Close(); File.Delete(download.SaveFilePath); Version curVersion = new Version(GetCurrentDriverVersion()); Version newVersion = new Version(GetUpdateVersion(release.name.Value)); switch (newVersion.CompareTo(curVersion)) { case 1: // NEWER if ( MessageDialogWindow.Show( $"New FFNx Update driver found!\n\nCurrent Version: {curVersion.ToString()}\nNew Version: {newVersion.ToString()}\n\nWould you like to update?", "Update found!", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question ).Result == System.Windows.MessageBoxResult.Yes) { DownloadAndExtract(GetUpdateReleaseUrl(release.assets), newVersion.ToString()); } break; case 0: // SAME MessageDialogWindow.Show("Your FFNx Driver version seems to be up to date!", "No update found", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); break; case -1: // OLDER if ( MessageDialogWindow.Show( $"Your current FFNx driver versions seems newer to the one currently available.\n\nCurrent Version: {curVersion.ToString()}\nNew Version: {newVersion.ToString()}\n\nWould you like to install it anyway?", "Update found!", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question ).Result == System.Windows.MessageBoxResult.Yes) { DownloadAndExtract(GetUpdateReleaseUrl(release.assets), newVersion.ToString()); } break; } } catch (Exception) { MessageDialogWindow.Show("Something went wrong while checking for FFNx updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); Sys.Message(new WMessage() { Text = $"Could not parse the FFNx release json at {GetUpdateChannel(channel)}", LoggedException = e.Error }); } } else { MessageDialogWindow.Show("Something went wrong while checking for FFNx updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); Sys.Message(new WMessage() { Text = $"Could not fetch for FFNx updates at {GetUpdateChannel(channel)}", LoggedException = e.Error }); } }); Sys.Downloads.AddToDownloadQueue(download); }