Configuration.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System.ComponentModel;
  2. using System.Linq;
  3. using System.Reflection;
  4. using System.Windows.Media;
  5. using Comal.Classes;
  6. using Comal.Stores;
  7. using InABox.Configuration;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. using InABox.Logging;
  11. using InABox.Scripting;
  12. using InABox.Wpf;
  13. using InABox.Wpf.Reports;
  14. using InABox.WPF;
  15. using InABox.WPF.Themes;
  16. using PRS.Shared;
  17. using PRSServices;
  18. using Syncfusion.Licensing;
  19. using Color = System.Windows.Media.Color;
  20. using ColorConverter = System.Windows.Media.ColorConverter;
  21. namespace PRSServer;
  22. /// <summary>
  23. /// Interaction logic for MainWindow.xaml
  24. /// </summary>
  25. public partial class Configuration : ThemableWindow
  26. {
  27. private AutoUpdateSettings _settings;
  28. public Configuration()
  29. {
  30. ThemeManager.BaseColor = Colors.CornflowerBlue;
  31. var database = PRSService.GetConfiguration().LoadAll().FirstOrDefault(x => x.Value.Type == ServerType.Database).Value;
  32. if(database is not null)
  33. {
  34. var properties = (database.DeserializeServerProperties() as DatabaseServerProperties)!;
  35. try
  36. {
  37. ThemeManager.BaseColor = (Color)ColorConverter.ConvertFromString(properties.ColorScheme);
  38. }
  39. catch
  40. {
  41. }
  42. }
  43. DynamicGridUtils.SelectionBackground = ThemeManager.SelectionBackgroundBrush;
  44. DynamicGridUtils.SelectionForeground = ThemeManager.SelectionForegroundBrush;
  45. Progress.DisplayImage = Properties.Resources.appstore.AsBitmapImage(200, 200);
  46. Progress.ShowModal("Starting...", progress =>
  47. {
  48. _settings = new LocalConfiguration<AutoUpdateSettings>().Load();
  49. StoreUtils.RegisterClasses();
  50. CoreUtils.RegisterClasses();
  51. ComalUtils.RegisterClasses();
  52. PRSSharedUtils.RegisterClasses();
  53. ReportUtils.RegisterClasses();
  54. WPFUtils.RegisterClasses();
  55. ConfigurationUtils.RegisterClasses();
  56. CoreUtils.RegisterClasses(typeof(Configuration).Assembly);
  57. Logger.OnLog += MainLogger.Send;
  58. MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
  59. Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
  60. ScriptDocument.DefaultAssemblies.AddRange(
  61. Assembly.Load("RoslynPad.Roslyn.Windows"),
  62. Assembly.Load("RoslynPad.Editor.Windows")
  63. );
  64. ScriptDocument.Initialize();
  65. });
  66. InitializeComponent();
  67. if (CheckForUpdates())
  68. {
  69. Close();
  70. return;
  71. }
  72. DatabaseEngine.MoveUpdateFiles();
  73. Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
  74. Logger.Send(LogType.Information, "", "Doing refresh");
  75. Servers.Refresh(true, true);
  76. }
  77. #region Update
  78. private string GetChannelLocation(string location)
  79. {
  80. return _settings.Channel switch
  81. {
  82. AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
  83. AutoUpdateChannel.Stable or _ => $"{location}/Stable",
  84. };
  85. }
  86. private string GetUpdateLocation()
  87. {
  88. return _settings?.Location;
  89. }
  90. private string GetLatestVersion(string location)
  91. {
  92. return Update.GetRemoteFile($"{GetChannelLocation(location)}/version.txt").Content;
  93. }
  94. private string GetReleaseNotes(string location)
  95. {
  96. return Update.GetRemoteFile($"{location}/Release Notes.txt").Content;
  97. }
  98. private byte[]? GetInstaller(string location)
  99. {
  100. return Update.GetRemoteFile($"{GetChannelLocation(location)}/PRSSetup.exe").RawBytes;
  101. }
  102. private void BeforeUpdate()
  103. {
  104. Servers.BeforeUpdate();
  105. }
  106. private bool CheckForUpdates()
  107. {
  108. return Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, BeforeUpdate, true, "PRSSetup.exe", true);
  109. }
  110. #endregion
  111. private void Window_Closing(object sender, CancelEventArgs e)
  112. {
  113. //if (CoreUtils.GetVersion() == "???")
  114. // Servers.StopAll();
  115. }
  116. }