Kenric Nugteren 2 недель назад
Родитель
Сommit
fe27e1f9ea

+ 86 - 9
prs.server/Forms/Configuration.xaml.cs

@@ -14,6 +14,7 @@ using InABox.Wpf.Reports;
 using InABox.WPF;
 using InABox.WPF.Themes;
 using PRS.Shared;
+using PRSServer.Forms.Version9Update;
 using PRSServices;
 using Syncfusion.Licensing;
 using Color = System.Windows.Media.Color;
@@ -26,7 +27,7 @@ namespace PRSServer;
 /// </summary>
 public partial class Configuration : ThemableWindow
 {
-    private AutoUpdateSettings _settings;
+    private AutoUpdateSettings _autoUpdateSettings;
 
     public Configuration()
     {
@@ -52,7 +53,7 @@ public partial class Configuration : ThemableWindow
 
         Progress.ShowModal("Starting...", progress =>
         {
-            _settings = new LocalConfiguration<AutoUpdateSettings>().Load();
+            _autoUpdateSettings = new LocalConfiguration<AutoUpdateSettings>().Load();
 
             StoreUtils.RegisterClasses();
             CoreUtils.RegisterClasses();
@@ -64,7 +65,7 @@ public partial class Configuration : ThemableWindow
             CoreUtils.RegisterClasses(typeof(Configuration).Assembly);
 
             Logger.OnLog += MainLogger.Send;
-            MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath(), false));
+            MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));
 
             Logger.Send(LogType.Information, "", string.Format("Config Path: {0}", CoreUtils.GetPath()));
 
@@ -83,6 +84,11 @@ public partial class Configuration : ThemableWindow
             Close();
             return;
         }
+        else if (CheckForVersion9Update())
+        {
+            Close();
+            return;
+        }
 
         DatabaseEngine.MoveUpdateFiles();
 
@@ -91,20 +97,91 @@ public partial class Configuration : ThemableWindow
         Servers.Refresh(true, true);
     }
 
+    #region Version 9 Update
+
+    private bool CheckForVersion9Update()
+    {
+        var location = $"{_autoUpdateSettings.Location}/v9";
+        var result = Update.GetRemoteFile($"{GetChannelLocation(location, allowAlpha: true)}/version.txt");
+        if(result.StatusCode == System.Net.HttpStatusCode.NotFound)
+        {
+            return false;
+        }
+
+        var res = MessageWindow.New()
+            .Title("PRS Version 9")
+            .Message("PRS Version 9 is available!")
+            .AddOKButton("Proceed")
+            .AddCancelButton()
+            .Display()
+            .Result;
+        if(res != MessageWindowResult.OK)
+        {
+            return false;
+        }
+
+        var updateDBWindow = new UpdateDatabaseFiles();
+        if(updateDBWindow.ShowDialog() != true)
+        {
+            return false;
+        }
+
+        if(!MessageWindow.ShowYesNo("Proceed with update to version 9?", "Update?"))
+        {
+            return false;
+        }
+
+        bool? bOK = null;
+        Progress.ShowModal("Retrieving Update", progress =>
+        {
+            bOK = Update.DownloadAndRunInstaller(
+                location => Update.GetRemoteFile($"{GetChannelLocation(location, allowAlpha: true)}/PRSSetup.exe").RawBytes,
+                BeforeUpdate,
+                true,
+                location,
+                "PRSSetup.exe",
+                progress);
+        });
+        if (bOK is null || bOK == true)
+        {
+            // In this case, the Progress window was closed by the installer, and so we must close our current window.
+            return true;
+        }
+        else
+        {
+            MessageWindow.ShowMessage("Unable to retrieve installer!", "Error");
+            return false;
+        }
+    }
+
+    #endregion
+
     #region Update
 
-    private string GetChannelLocation(string location)
+    private string GetChannelLocation(string location, bool allowAlpha = false)
     {
-        return _settings.Channel switch
+        if (allowAlpha)
+        {
+            return _autoUpdateSettings.Channel switch
+            {
+                AutoUpdateChannel.Unstable => $"{location}/Alpha",
+                AutoUpdateChannel.PreRelease => $"{location}/PreRelease",
+                AutoUpdateChannel.Stable or _ => $"{location}/Stable",
+            };
+        }
+        else
         {
-            AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
-            AutoUpdateChannel.Stable or _ => $"{location}/Stable",
-        };
+            return _autoUpdateSettings.Channel switch
+            {
+                AutoUpdateChannel.PreRelease or AutoUpdateChannel.Unstable => $"{location}/PreRelease",
+                AutoUpdateChannel.Stable or _ => $"{location}/Stable",
+            };
+        }
     }
 
     private string GetUpdateLocation()
     {
-        return _settings?.Location;
+        return _autoUpdateSettings.Location;
     }
     private string GetLatestVersion(string location)
     {

+ 12 - 0
prs.server/Forms/Version9Update/UpdateDatabaseFiles.xaml

@@ -0,0 +1,12 @@
+<Window x:Class="PRSServer.Forms.Version9Update.UpdateDatabaseFiles"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:PRSServer.Forms.Version9Update"
+        mc:Ignorable="d"
+        Title="UpdateDatabaseFiles" Height="450" Width="800">
+    <Grid>
+        
+    </Grid>
+</Window>

+ 27 - 0
prs.server/Forms/Version9Update/UpdateDatabaseFiles.xaml.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace PRSServer.Forms.Version9Update
+{
+    /// <summary>
+    /// Interaction logic for UpdateDatabaseFiles.xaml
+    /// </summary>
+    public partial class UpdateDatabaseFiles : Window
+    {
+        public UpdateDatabaseFiles()
+        {
+            InitializeComponent();
+        }
+    }
+}