Configuration.xaml.cs 4.1 KB

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