Configuration.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Windows;
  9. using Comal.Classes;
  10. using Comal.Stores;
  11. using InABox.Configuration;
  12. using InABox.Core;
  13. using InABox.DynamicGrid;
  14. using InABox.Logging;
  15. using InABox.Reports;
  16. using InABox.Scripting;
  17. using InABox.Wpf;
  18. using InABox.WPF;
  19. using PRS.Shared;
  20. using RestSharp;
  21. using Syncfusion.Licensing;
  22. namespace PRSServer
  23. {
  24. /// <summary>
  25. /// Interaction logic for MainWindow.xaml
  26. /// </summary>
  27. public partial class Configuration : ThemableWindow
  28. {
  29. private AutoUpdateSettings _settings;
  30. public Configuration()
  31. {
  32. Progress.DisplayImage = Properties.Resources.appstore.AsBitmapImage(200, 200);
  33. Progress.ShowModal("Starting...", progress =>
  34. {
  35. _settings = new LocalConfiguration<AutoUpdateSettings>().Load();
  36. SyncfusionLicenseProvider.RegisterLicense(CoreUtils.SyncfusionLicense(SyncfusionVersion.v20_2));
  37. StoreUtils.RegisterClasses();
  38. CoreUtils.RegisterClasses();
  39. ComalUtils.RegisterClasses();
  40. ReportUtils.RegisterClasses();
  41. ConfigurationUtils.RegisterClasses();
  42. Logger.OnLog += MainLogger.Send;
  43. MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
  44. Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
  45. ScriptDocument.DefaultAssemblies.AddRange(
  46. Assembly.Load("RoslynPad.Roslyn.Windows"),
  47. Assembly.Load("RoslynPad.Editor.Windows")
  48. );
  49. ScriptDocument.Initialize();
  50. });
  51. InitializeComponent();
  52. CheckForUpdates();
  53. DatabaseEngine.MoveUpdateFiles();
  54. Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
  55. Servers.Refresh(true, true);
  56. }
  57. #region Update
  58. private string GetChannelLocation(string location)
  59. {
  60. return _settings.Channel switch
  61. {
  62. AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
  63. AutoUpdateChannel.Stable or _ => $"{location}/Stable",
  64. };
  65. }
  66. private string GetUpdateLocation()
  67. {
  68. return _settings?.Location;
  69. }
  70. private string GetLatestVersion(string location)
  71. {
  72. return Update.GetRemoteFile($"{GetChannelLocation(location)}/version.txt").Content;
  73. }
  74. private string GetReleaseNotes(string location)
  75. {
  76. return Update.GetRemoteFile($"{location}/Release Notes.txt").Content;
  77. }
  78. private byte[]? GetInstaller(string location)
  79. {
  80. return Update.GetRemoteFile($"{GetChannelLocation(location)}/PRSSetup.exe").RawBytes;
  81. }
  82. private void CheckForUpdates()
  83. {
  84. Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, true, "PRSSetup.exe");
  85. }
  86. #endregion
  87. private void Window_Closing(object sender, CancelEventArgs e)
  88. {
  89. //if (CoreUtils.GetVersion() == "???")
  90. // Servers.StopAll();
  91. }
  92. }
  93. }