Configuration.xaml.cs 4.3 KB

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