123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Windows.Media;
- using Comal.Classes;
- using Comal.Stores;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Logging;
- using InABox.Scripting;
- using InABox.Wpf;
- using InABox.Wpf.Reports;
- using InABox.WPF;
- using InABox.WPF.Themes;
- using PRS.Shared;
- using PRSServices;
- using Syncfusion.Licensing;
- using Color = System.Windows.Media.Color;
- using ColorConverter = System.Windows.Media.ColorConverter;
- namespace PRSServer;
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class Configuration : ThemableWindow
- {
- private AutoUpdateSettings _settings;
- public Configuration()
- {
- ThemeManager.BaseColor = Colors.CornflowerBlue;
- var database = PRSService.GetConfiguration().LoadAll().FirstOrDefault(x => x.Value.Type == ServerType.Database).Value;
- if(database is not null)
- {
- var properties = (database.DeserializeServerProperties() as DatabaseServerProperties)!;
-
- try
- {
- ThemeManager.BaseColor = (Color)ColorConverter.ConvertFromString(properties.ColorScheme);
- }
- catch
- {
- }
- }
- Progress.DisplayImage = Properties.Resources.appstore.AsBitmapImage(200, 200);
- Progress.ShowModal("Starting...", progress =>
- {
- _settings = new LocalConfiguration<AutoUpdateSettings>().Load();
- StoreUtils.RegisterClasses();
- CoreUtils.RegisterClasses();
- ComalUtils.RegisterClasses();
- PRSSharedUtils.RegisterClasses();
- ReportUtils.RegisterClasses();
- ConfigurationUtils.RegisterClasses();
- Logger.OnLog += MainLogger.Send;
- MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
- Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
- ScriptDocument.DefaultAssemblies.AddRange(
- Assembly.Load("RoslynPad.Roslyn.Windows"),
- Assembly.Load("RoslynPad.Editor.Windows")
- );
- ScriptDocument.Initialize();
- });
- InitializeComponent();
- if (CheckForUpdates())
- {
- Close();
- return;
- }
- DatabaseEngine.MoveUpdateFiles();
- Title = string.Format("PRS Server Manager (v{0})", CoreUtils.GetVersion());
- Logger.Send(LogType.Information, "", "Doing refresh");
- Servers.Refresh(true, true);
- }
- #region Update
- private string GetChannelLocation(string location)
- {
- return _settings.Channel switch
- {
- AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
- AutoUpdateChannel.Stable or _ => $"{location}/Stable",
- };
- }
- private string GetUpdateLocation()
- {
- return _settings?.Location;
- }
- private string GetLatestVersion(string location)
- {
- return Update.GetRemoteFile($"{GetChannelLocation(location)}/version.txt").Content;
- }
- private string GetReleaseNotes(string location)
- {
- return Update.GetRemoteFile($"{location}/Release Notes.txt").Content;
- }
- private byte[]? GetInstaller(string location)
- {
- return Update.GetRemoteFile($"{GetChannelLocation(location)}/PRSSetup.exe").RawBytes;
- }
- private void BeforeUpdate()
- {
- Servers.BeforeUpdate();
- }
- private bool CheckForUpdates()
- {
- return Update.CheckForUpdates(GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, BeforeUpdate, true, "PRSSetup.exe");
- }
- #endregion
- private void Window_Closing(object sender, CancelEventArgs e)
- {
- //if (CoreUtils.GetVersion() == "???")
- // Servers.StopAll();
- }
- }
|