Configuration.xaml.cs 3.8 KB

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