Configuration.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. ConfigurationUtils.RegisterClasses();
  55. Logger.OnLog += MainLogger.Send;
  56. MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
  57. Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
  58. ScriptDocument.DefaultAssemblies.AddRange(
  59. Assembly.Load("RoslynPad.Roslyn.Windows"),
  60. Assembly.Load("RoslynPad.Editor.Windows")
  61. );
  62. ScriptDocument.Initialize();
  63. });
  64. InitializeComponent();
  65. if (CheckForUpdates())
  66. {
  67. Close();
  68. return;
  69. }
  70. DatabaseEngine.MoveUpdateFiles();
  71. Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
  72. Logger.Send(LogType.Information, "", "Doing refresh");
  73. Servers.Refresh(true, true);
  74. }
  75. #region Update
  76. private string GetChannelLocation(string location)
  77. {
  78. return _settings.Channel switch
  79. {
  80. AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
  81. AutoUpdateChannel.Stable or _ => $"{location}/Stable",
  82. };
  83. }
  84. private string GetUpdateLocation()
  85. {
  86. return _settings?.Location;
  87. }
  88. private string GetLatestVersion(string location)
  89. {
  90. return Update.GetRemoteFile($"{GetChannelLocation(location)}/version.txt").Content;
  91. }
  92. private string GetReleaseNotes(string location)
  93. {
  94. return Update.GetRemoteFile($"{location}/Release Notes.txt").Content;
  95. }
  96. private byte[]? GetInstaller(string location)
  97. {
  98. return Update.GetRemoteFile($"{GetChannelLocation(location)}/PRSSetup.exe").RawBytes;
  99. }
  100. private void BeforeUpdate()
  101. {
  102. Servers.BeforeUpdate();
  103. }
  104. private bool CheckForUpdates()
  105. {
  106. return Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, BeforeUpdate, true, "PRSSetup.exe", true);
  107. }
  108. #endregion
  109. private void Window_Closing(object sender, CancelEventArgs e)
  110. {
  111. //if (CoreUtils.GetVersion() == "???")
  112. // Servers.StopAll();
  113. }
  114. }