Configuration.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. if (CheckForUpdates())
  71. {
  72. Close();
  73. return;
  74. }
  75. DatabaseEngine.MoveUpdateFiles();
  76. Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
  77. Logger.Send(LogType.Information, "", "Doing refresh");
  78. Servers.Refresh(true, true);
  79. }
  80. #region Update
  81. private string GetChannelLocation(string location)
  82. {
  83. return _settings.Channel switch
  84. {
  85. AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
  86. AutoUpdateChannel.Stable or _ => $"{location}/Stable",
  87. };
  88. }
  89. private string GetUpdateLocation()
  90. {
  91. return _settings?.Location;
  92. }
  93. private string GetLatestVersion(string location)
  94. {
  95. return Update.GetRemoteFile($"{GetChannelLocation(location)}/version.txt").Content;
  96. }
  97. private string GetReleaseNotes(string location)
  98. {
  99. return Update.GetRemoteFile($"{location}/Release Notes.txt").Content;
  100. }
  101. private byte[]? GetInstaller(string location)
  102. {
  103. return Update.GetRemoteFile($"{GetChannelLocation(location)}/PRSSetup.exe").RawBytes;
  104. }
  105. private void BeforeUpdate()
  106. {
  107. Servers.BeforeUpdate();
  108. }
  109. private bool CheckForUpdates()
  110. {
  111. return Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, BeforeUpdate, true, "PRSSetup.exe");
  112. }
  113. #endregion
  114. private void Window_Closing(object sender, CancelEventArgs e)
  115. {
  116. //if (CoreUtils.GetVersion() == "???")
  117. // Servers.StopAll();
  118. }
  119. }
  120. }