using AutoUpdaterDotNET; using System; using System.Diagnostics; using System.Net; using System.Reflection; using System.Text; using System.Windows; namespace Szmedi.RvKits.Common { /// /// ReleaseNoteWin.xaml 的交互逻辑 /// public partial class ReleaseNoteWin { public ReleaseNoteWin() { var collection = Properties.Settings.Default.UpdateNotes; var sb = new StringBuilder(); foreach (var str in collection) { //Regex regex = new("^(\\d+.){3}\\d$"); //if (regex.IsMatch(str)) //{ // sb.AppendLine(); //} sb.AppendLine(str); } //DataContext = this; InitializeComponent(); Title = $"更新日志"; TbReleaseNote.Text = sb.ToString(); TbVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); AutoUpdater.CheckForUpdateEvent += args => { switch (args.Error) { case null when args.IsUpdateAvailable: { var messageBoxResult = args.Mandatory.Value ? MessageBox.Show( $@"有新的版本 {args.CurrentVersion} 可用。正在使用的版本:{args.InstalledVersion} 必须进行更新。", @"SZMEDI工具 更新", MessageBoxButton.OK, MessageBoxImage.Information ) : MessageBox.Show( $@"有新的版本 {args.CurrentVersion} 可用。你正在使用的版本:{args.InstalledVersion}。是否想要退出Revit进行更新程序?", @"SZMEDI工具 更新", MessageBoxButton.YesNo, MessageBoxImage.Question ); if (messageBoxResult.Equals(MessageBoxResult.OK) || messageBoxResult.Equals(MessageBoxResult.Yes)) { try { if (AutoUpdater.DownloadUpdate(args)) { Process.GetCurrentProcess().Kill(); //Application.Current.Shutdown(); } } catch (Exception exception) { MessageBox.Show( exception.Message, exception.GetType().ToString(), MessageBoxButton.OK, MessageBoxImage.Error ); } } break; } case null: MessageBox.Show(@"无更新可用,请稍后再试", @"无更新可用", MessageBoxButton.OK, MessageBoxImage.Information); break; case WebException: MessageBox.Show(@"更新服务器出现问题。请检查网络连接,稍后再试。", @"更新检查失败", MessageBoxButton.OK, MessageBoxImage.Error); break; default: //MessageBox.Show(args.Error.Message, // args.Error.GetType().ToString(), MessageBoxButton.OK, // MessageBoxImage.Error); break; } }; } private void Update_Click(object sender, RoutedEventArgs e) { UpdateCheck(); } private void UpdateCheck() { // Uncomment following line to run update process without admin privileges. AutoUpdater.RunUpdateAsAdmin = false; // Uncomment following line if you want to open download page instead of downloading update file when user click on download button. // AutoUpdater.OpenDownloadPage = true; // Uncomment following lines if you don't want user to select remind later time in AutoUpdater notification window. //AutoUpdater.LetUserSelectRemindLater = false; //AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Days; //AutoUpdater.RemindLaterAt = 2; // Uncomment following line if you don't want to show Skip button. // AutoUpdater.ShowSkipButton = false; // Uncomment following line if you don't want to show Remind Later button. //AutoUpdater.ShowRemindLaterButton = false; // Uncomment following line to show custom application title in AutoUpdater notification window. AutoUpdater.AppTitle = "SZMEDI工具 更新"; // Uncomment following line if you want to show errors. AutoUpdater.ReportErrors = true; // Uncomment following lines if you want to handle how your application will exit when application finishes downloading the update. //AutoUpdater.ApplicationExitEvent += () => //{ // Title = @"关闭程序中..."; // Thread.Sleep(5000); // Application.Current.Shutdown(); //}; // Uncomment following lines to handle update logic yourself. // Uncomment following lines if you want to use XML and update file served only through Proxy. // var proxy = new WebProxy("local-proxy-IP:8080", true) {Credentials = new NetworkCredential("domain\\user", "password")}; // AutoUpdater.Proxy = proxy; // Uncomment following lines to periodically check for updates. // var timer = new DispatcherTimer { Interval = TimeSpan.FromMinutes(2) }; // timer.Tick += delegate { AutoUpdater.Start("http://rbsoft.org/updates/AutoUpdaterTest.xml"); }; // timer.Start(); // Uncomment following lines to provide basic authentication credentials needed to access update resources. // var basicAuthentication = new BasicAuthentication("myUserName", "myPassword"); // AutoUpdater.BasicAuthXML = AutoUpdater.BasicAuthDownload = AutoUpdater.BasicAuthChangeLog = basicAuthentication; // Uncomment following lines to enable forced updates. // AutoUpdater.Mandatory = true; // AutoUpdater.UpdateMode = Mode.Forced; // Uncomment following line to change AutoUpdater notification window size. //AutoUpdater.UpdateFormSize = new System.Drawing.Size(800, 600); // Uncomment following line if you your XML file can only be accessed through FTP. AutoUpdater.Start($"{Properties.Settings.Default.FTPServerIP}Updates/AutoUpdater.xml", new NetworkCredential(), Assembly.GetExecutingAssembly()); // Uncomment following lines if you want to persist Remind Later and Skip values in a json file instead of registry. // string jsonPath = Path.Combine(Environment.CurrentDirectory, "settings.json"); // AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath); // Uncomment following lines if you want to change the update zip extraction path. This only works when you use zip file as an update file. //DirectoryInfo currentDirectory = new(Environment.CurrentDirectory); //if (currentDirectory.Parent != null) //{ // AutoUpdater.InstallationPath = currentDirectory.Parent.FullName; //} // Uncomment following line if you want to check for update synchronously. // AutoUpdater.Synchronous = true; // Uncomment following line if you want to assign installed version manually and don't want to rely on the library to determine the installed version from assembly. // AutoUpdater.InstalledVersion = new Version("2.0.0.1"); // Uncomment following line if you want to clear application directory before update zip is extracted. This only works when you use zip file as an update file. // AutoUpdater.ClearAppDirectory = true; // Uncomment following line if you want to execute different executable after the update. This only works when you use zip file as an update file. //AutoUpdater.ExecutablePath = "bin/AutoUpdaterTest.exe"; // Uncomment following line to set this window as owner of the all dialogs initiated by AutoUpdater. AutoUpdater.SetOwner(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); // Uncomment following line to set TopMost to true for all updater dialogs. It is necessary to do this if TopMost is set to true in your form or window. AutoUpdater.TopMost = true; // Uncomment following line to change the Icon shown on the updater dialog. //AutoUpdater.Icon = Properties.Resources.Icon; } } }