Configuration.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Windows;
  10. using System.Windows.Media;
  11. using Comal.Classes;
  12. using Comal.Stores;
  13. using InABox.Clients;
  14. using InABox.Configuration;
  15. using InABox.Core;
  16. using InABox.DynamicGrid;
  17. using InABox.Logging;
  18. using InABox.Reports;
  19. using InABox.Scripting;
  20. using InABox.Wpf;
  21. using InABox.WPF;
  22. using InABox.WPF.Themes;
  23. using PRS.Shared;
  24. using Syncfusion.Licensing;
  25. using Color = System.Windows.Media.Color;
  26. using ColorConverter = System.Windows.Media.ColorConverter;
  27. namespace PRSServer
  28. {
  29. /// <summary>
  30. /// Interaction logic for MainWindow.xaml
  31. /// </summary>
  32. public partial class Configuration : ThemableWindow
  33. {
  34. private AutoUpdateSettings _settings;
  35. public Configuration()
  36. {
  37. ThemeManager.BaseColor = Colors.CornflowerBlue;
  38. var database = PRSService.GetConfiguration().LoadAll().FirstOrDefault(x => x.Value.Type == ServerType.Database).Value;
  39. if(database is not null)
  40. {
  41. var properties = (database.DeserializeServerProperties() as DatabaseServerProperties)!;
  42. try
  43. {
  44. ThemeManager.BaseColor = (Color)ColorConverter.ConvertFromString(properties.ColorScheme);
  45. }
  46. catch
  47. {
  48. }
  49. }
  50. Progress.DisplayImage = Properties.Resources.appstore.AsBitmapImage(200, 200);
  51. Progress.ShowModal("Starting...", progress =>
  52. {
  53. _settings = new LocalConfiguration<AutoUpdateSettings>().Load();
  54. SyncfusionLicenseProvider.RegisterLicense(CoreUtils.SyncfusionLicense(SyncfusionVersion.v20_2));
  55. StoreUtils.RegisterClasses();
  56. CoreUtils.RegisterClasses();
  57. ComalUtils.RegisterClasses();
  58. ReportUtils.RegisterClasses();
  59. ConfigurationUtils.RegisterClasses();
  60. Logger.OnLog += MainLogger.Send;
  61. MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
  62. Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
  63. ScriptDocument.DefaultAssemblies.AddRange(
  64. Assembly.Load("RoslynPad.Roslyn.Windows"),
  65. Assembly.Load("RoslynPad.Editor.Windows")
  66. );
  67. ScriptDocument.Initialize();
  68. });
  69. InitializeComponent();
  70. CheckForUpdates();
  71. DatabaseEngine.MoveUpdateFiles();
  72. Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
  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 void CheckForUpdates()
  105. {
  106. Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, BeforeUpdate, true, "PRSSetup.exe");
  107. }
  108. #endregion
  109. private void Window_Closing(object sender, CancelEventArgs e)
  110. {
  111. //if (CoreUtils.GetVersion() == "???")
  112. // Servers.StopAll();
  113. }
  114. }
  115. }