From e2cf258f3643d7107efa76661d8d8758b723fa05 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Thu, 6 Jun 2024 13:02:19 +0200 Subject: [PATCH] =?UTF-8?q?Download=20Manager=20+=20Download=20Controller?= =?UTF-8?q?=20aufger=C3=A4umt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeWoLauncher/App.config | 3 + BeWoLauncher/BeWoLauncher.csproj | 4 +- BeWoLauncher/LauncherApp.xaml.cs | 2 + BeWoLauncher/Logic/Behavior/LaunchBehavior.cs | 112 +++++++++----- .../Logic/Behavior/ViewSwitchBehavior.cs | 11 +- .../Logic/Controller/DownloadController.cs | 137 ++++++++++++------ .../Logic/Controller/ViewController.cs | 4 +- .../Logic/Utils/Download/DownloadManager.cs | 8 +- .../Logic/Utils/LauncherAppdataConfig.cs | 42 +++++- BeWoLauncher/Logic/Utils/LauncherPaths.cs | 19 +-- BeWoLauncher/Properties/Settings.Designer.cs | 14 +- BeWoLauncher/Properties/Settings.settings | 3 + .../View/Components/ProxyLoginView.xaml | 5 +- .../View/Components/PwVergessenView.xaml | 7 +- .../View/Components/PwVergessenView.xaml.cs | 4 +- .../View/Frames/InstallInfoFrame.xaml.cs | 2 +- .../View/Frames/UpdateInfoFrame.xaml.cs | 4 +- BeWoLauncher/View/LoginView.xaml | 4 +- BeWoLauncher/View/LoginView.xaml.cs | 16 +- .../LauncherServiceImp.cs | 1 + SharedLauncher/LauncherEnums.cs | 4 +- SharedLauncher/Logic/FileController.cs | 2 +- 22 files changed, 277 insertions(+), 131 deletions(-) diff --git a/BeWoLauncher/App.config b/BeWoLauncher/App.config index 7378a93aa..c31e50375 100644 --- a/BeWoLauncher/App.config +++ b/BeWoLauncher/App.config @@ -63,6 +63,9 @@ False + + False + \ No newline at end of file diff --git a/BeWoLauncher/BeWoLauncher.csproj b/BeWoLauncher/BeWoLauncher.csproj index 149fc8910..13415c298 100644 --- a/BeWoLauncher/BeWoLauncher.csproj +++ b/BeWoLauncher/BeWoLauncher.csproj @@ -14,7 +14,7 @@ 4 true false - D:\Test\Launcher\ + C:\Test\Launcher\ true Disk false @@ -25,7 +25,7 @@ false true true - 1 + 2 1.0.0.%2a false true diff --git a/BeWoLauncher/LauncherApp.xaml.cs b/BeWoLauncher/LauncherApp.xaml.cs index a9198e1c7..05fb2afd5 100644 --- a/BeWoLauncher/LauncherApp.xaml.cs +++ b/BeWoLauncher/LauncherApp.xaml.cs @@ -81,6 +81,8 @@ namespace BeWoLauncher } public static void ShowError(string message, string ex, bool showDetails) { + ViewController.EndWaiting(); + if (ViewController.CurrentWindow is null) { MessageBox.Show(ex, message); diff --git a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs index 25b0a61f2..8700ae914 100644 --- a/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs +++ b/BeWoLauncher/Logic/Behavior/LaunchBehavior.cs @@ -4,6 +4,7 @@ using BeWoLauncher.Logic.Utils; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Information; using System; +using System.IO; using System.Threading.Tasks; using static BeWoLauncher.Logic.Controller.ViewController; @@ -18,10 +19,7 @@ namespace BeWoLauncher.Logic.Behavior } - /// - /// Waiting aktiv, Nutzer wurde erfolgreich angemeldet - /// - public void LaunchUpdatePhase() + public void LoginSuccessful() { #region confirm demo #if DEBUG @@ -39,60 +37,94 @@ namespace BeWoLauncher.Logic.Behavior #endif #endregion - var path = LauncherPaths.GetInstallLocationFromSetting(); + DownloadController.Start(LauncherPaths.GetLoggerPath()); - LauncherPaths.ActualPlanerLocation = path; + var planer_location_set = LauncherAppdataConfig.GetInstallLocationSetSuccess(); - if (!string.IsNullOrWhiteSpace(path) && !CheckForPermissions(path)) + var path_to_check = planer_location_set + ? LauncherAppdataConfig.GetPlanerLocation() + : LauncherPaths.GetPlanerLocationFromSettingOrDefault(); + + var check = IsDirectoryWritable(path_to_check); + + if (!check) { - ViewBehavior.ShowNoPermissions(path); + ViewBehavior.ShowNoPermissions(path_to_check); + return; + } + + LauncherPaths.PlanerLocation = path_to_check; + + if (planer_location_set) + { + if (UninstallMode) + { + // optional: Hier kann man ggf zusatzlich prüfen, ob InstallLocationSetSuccess gesetzt ist + // Ziel: Erweiterte Fehler/Rechte Erkennung + StartUninstallInfoPhase(); + } + else + { + StartUpdateInfoPhase(); + } } else { - DownloadController.Start(); - - if (UninstallMode) - LaunchUninstall(); - else - LoadUpdates(); + // Install + StartInstallInfoPhase(); } EndWaiting(); } - public void LaunchUninstall() + public void StartInstallInfoPhase() { - DownloadController.GetDeletePlan(); - ViewBehavior.ShowUninstallInfo(); - } + var error = DownloadController.TryLoadInstallPlan(); - public void LoadUpdates() - { - var handled = DownloadController.GetUpdatePlan(); - - if (handled) - return; - - if (DownloadController.CanQuickStartLauncher()) + if(error is null) { - if (DownloadController.DoesPlanerExeExists()) - { - GenericTextLogger.Post("Launcher ist aktuell oder Download Server nicht erreichbar."); - - ViewBehavior.ShowLoading(); - } - else - { - GenericTextLogger.Post("BewoPlaner.exe nicht gefunden."); - - ViewBehavior.ShowError("BewoPlaner.exe nicht gefunden."); - } + ViewBehavior.ShowInfo(false); } else { - GenericTextLogger.Post("Launcher hat etwas zu tun."); + GenericTextLogger.Post(error); - ViewBehavior.ShowInfo(); + ViewBehavior.ShowError(error); + } + } + + public void StartUpdateInfoPhase() + { + var error = DownloadController.TryLoadUpdatePlan(out bool can_quick_start); + + if (error is null) + { + if (can_quick_start) + ViewBehavior.ShowLoading(); + else + ViewBehavior.ShowInfo(true); + } + else + { + GenericTextLogger.Post(error); + + ViewBehavior.ShowError(error); + } + } + + public void StartUninstallInfoPhase() + { + var error = DownloadController.TryLoadUninstallPlan(); + + if (error is null) + { + ViewBehavior.ShowUninstallInfo(); + } + else + { + GenericTextLogger.Post(error); + + ViewBehavior.ShowError(error); } } diff --git a/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs b/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs index b8bc530b9..e1f2a2660 100644 --- a/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs +++ b/BeWoLauncher/Logic/Behavior/ViewSwitchBehavior.cs @@ -64,12 +64,11 @@ namespace BeWoLauncher.Logic.Behavior CurrentFrame = ViewController.ViewBuilder.GetNewFrame(ft); } - public void ShowInfo() + public void ShowInfo(bool is_update) { ViewController.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { - if (LauncherAppdataConfig.GetFirstInstallationSuccess() && - File.Exists(LauncherPaths.GetPlanerExePath())) + if (is_update) { ShowFrame(FrameType.UpdateInfo); } @@ -134,18 +133,16 @@ namespace BeWoLauncher.Logic.Behavior } public void LoginSuccessful(object sender, EventArgs e) { - Task.Run(() => ViewController.LaunchBehavior.LaunchUpdatePhase()); + Task.Run(() => ViewController.LaunchBehavior.LoginSuccessful()); } public void InstallInfoAccept(object sender, EventArgs e) { var install = sender as InstallInfoFrame; - if (CheckForPermissions(install.InstallLocation)) + if (IsDirectoryWritable(install.InstallLocation)) { - DownloadController.InitLogger(); LauncherPaths.SetAndSaveInstallLocation(install.InstallLocation); - LauncherAppdataConfig.SetFirstInstallationSuccess(true); ShowFrame(FrameType.InstallProgress); } else diff --git a/BeWoLauncher/Logic/Controller/DownloadController.cs b/BeWoLauncher/Logic/Controller/DownloadController.cs index a2b24e33d..a4cca168b 100644 --- a/BeWoLauncher/Logic/Controller/DownloadController.cs +++ b/BeWoLauncher/Logic/Controller/DownloadController.cs @@ -2,6 +2,7 @@ using BeWoLauncher.Logic.Utils.Download; using BS.SharedLauncher.Extensions; using BS.SharedLauncher.Information; +using BS.SharedLauncher.Logic; using BS.SharedLauncher.Utils; using System; using System.IO; @@ -18,30 +19,29 @@ namespace BeWoLauncher.Logic.Controller static DownloadController() { - + } - public static void Start() + public static void Start(string logger_path = null) { Manager = new DownloadManager(); - if (LauncherAppdataConfig.GetFirstInstallationSuccess()) - InitLogger(); + if (!string.IsNullOrEmpty(logger_path)) + { + GenericTextLogger.Init(logger_path); + } } - public static void InitLogger() + /// + /// + /// + /// Error string - null if successful + public static string TryLoadInstallPlan() { - GenericTextLogger.Init(LauncherPaths.GetLoggerPath()); - } + GenericTextLogger.PostImportantInfo("Starting Install Process"); - public static bool GetUpdatePlan() - { - GenericTextLogger.PostImportantInfo("Starting Update Process"); - - Manager.CheckForConnection(); - - if (!Manager.IsDownloadServerUp) - return false; + if (!CheckConnection()) + return "Download server is down"; try { @@ -55,24 +55,78 @@ namespace BeWoLauncher.Logic.Controller GenericTextLogger.Post($"Anfrage wurde erfolgreich verarbeitet. Server gibt Version {client_version} vor."); - SessionInformation.Session.Version = client_version; + return null; } else { - GenericTextLogger.Post($"Server gibt Fehler zurück. Fehler: {response.Error}"); - - ViewController.ShowError(response.Error); - - return true; + return $"Server gibt Fehler zurück. Fehler: {response.Error}"; } } - catch(Exception e) + catch (Exception e) { - ViewController.ShowError(e); - return true; + return e.ToString(); + } + } + + public static string TryLoadUpdatePlan(out bool can_quick_start) + { + GenericTextLogger.PostImportantInfo($"Starting Update Process"); + + can_quick_start = false; + + if (!CheckConnection()) + { + if (DoesPlanerExeExists()) + { + can_quick_start = true; + + return null; + } + else + { + return "Download server is down & quickstart not possible"; + } } - return false; + try + { + Manager.GetUpdatePlan(); + + var response = Manager.UpdatePlanResponse; + + if (response.Successful) + { + var client_version = response.CurrentPackage.Version; + + GenericTextLogger.Post($"Anfrage wurde erfolgreich verarbeitet. Server gibt Version {client_version} vor."); + + if (!response.HasToDo()) + can_quick_start = true; + + return null; + } + else + { + return $"Server gibt Fehler zurück. Fehler: {response.Error}"; + } + } + catch (Exception e) + { + return e.ToString(); + } + } + + public static string TryLoadUninstallPlan() + { + try + { + Manager.GetDeletePlan(); + return null; + } + catch (Exception e) + { + return e.ToString(); + } } public static bool DoesPlanerExeExists() @@ -86,28 +140,7 @@ namespace BeWoLauncher.Logic.Controller } - return false; - } - public static void GetDeletePlan() - { - Manager.GetDeletePlan(); - } - - public static bool CanQuickStartLauncher() - { - try - { - if (!Manager.IsDownloadServerUp) - return true; - - if (!Manager.UpdatePlanResponse.HasToDo()) - return true; - } - catch - { - - } return false; } @@ -123,5 +156,17 @@ namespace BeWoLauncher.Logic.Controller else return "error"; } + + private static bool CheckConnection() + { + GenericTextLogger.Post("Checking download server connection..."); + var check = Manager.CheckForConnection(); + if (check) + GenericTextLogger.Post("Download server is up"); + else + GenericTextLogger.Post("Download server is down"); + + return check; + } } } diff --git a/BeWoLauncher/Logic/Controller/ViewController.cs b/BeWoLauncher/Logic/Controller/ViewController.cs index 6c540dd9f..af1e21ff9 100644 --- a/BeWoLauncher/Logic/Controller/ViewController.cs +++ b/BeWoLauncher/Logic/Controller/ViewController.cs @@ -80,9 +80,9 @@ namespace BeWoLauncher.Logic.Controller public static void StartWaiting() => CurrentWindow.StartWaiting(); public static void EndWaiting() => CurrentWindow.EndWaiting(); - public static bool CheckForPermissions(string path) + public static bool IsDirectoryWritable(string path) { - return FileController.IsDirectoryWritable(path, false); + return FileController.IsDirectoryWritable(path); } public static void CheckForAutoLogin(object sender, EventArgs e) { diff --git a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs index d8efc521d..34cef8fb6 100644 --- a/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs +++ b/BeWoLauncher/Logic/Utils/Download/DownloadManager.cs @@ -61,7 +61,7 @@ namespace BeWoLauncher.Logic.Utils.Download { UpdatePlanResponse = new UpdatePlanResponse(); - if (LauncherPaths.ActualPlanerLocation.Exists()) + if (LauncherPaths.PlanerLocation.Exists()) { if (ApplyFolder.Exists()) if (!ApplyFolder.IsFolderEmpty()) @@ -221,7 +221,7 @@ namespace BeWoLauncher.Logic.Utils.Download { UpdatePlanRequest = new UpdatePlanRequest(); - if (UpdatePlanRequest.PlanerRootFolderExists = LauncherPaths.ActualPlanerLocation.Exists()) + if (UpdatePlanRequest.PlanerRootFolderExists = LauncherPaths.PlanerLocation.Exists()) { if (UpdatePlanRequest.DownloadFolderExists = DownloadFolder.Exists()) if (!(UpdatePlanRequest.DownloadFolderIsEmpty = DownloadFolder.IsFolderEmpty())) @@ -254,7 +254,7 @@ namespace BeWoLauncher.Logic.Utils.Download UpdatePlanResponse = LauncherServiceFacade.DoDownloadBeWoServiceSyncWithException(x => x.GetUpdatePlan(UpdatePlanRequest)); } - public void CheckForConnection() + public bool CheckForConnection() { bool test_connection = false; @@ -268,6 +268,8 @@ namespace BeWoLauncher.Logic.Utils.Download } IsDownloadServerUp = test_connection; + + return test_connection; } } } diff --git a/BeWoLauncher/Logic/Utils/LauncherAppdataConfig.cs b/BeWoLauncher/Logic/Utils/LauncherAppdataConfig.cs index 81d3f4e92..d91363dc5 100644 --- a/BeWoLauncher/Logic/Utils/LauncherAppdataConfig.cs +++ b/BeWoLauncher/Logic/Utils/LauncherAppdataConfig.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,17 +9,39 @@ namespace BeWoLauncher.Logic.Utils { public static class LauncherAppdataConfig { - public static string GetInstallLocation() + private static string _Location; + + public static string Location { - return Properties.Settings.Default.InstallLocation; + get => _Location ?? (_Location = GetLauncherAppdataConfigLocation()); + set { _Location = value; } } - public static void SetInstallLocation(string path) + + public static string GetPlanerLocation() + { + var path = Properties.Settings.Default.InstallLocation; + + return string.IsNullOrWhiteSpace(path) ? null : path; + } + + public static void SetPlanerLocation(string path) { Properties.Settings.Default.InstallLocation = path; Properties.Settings.Default.Save(); } + public static bool GetInstallLocationSetSuccess() + { + return Properties.Settings.Default.InstallLocationSetSuccess; + } + + public static void SetInstallLocationSetSuccess(bool b) + { + Properties.Settings.Default.InstallLocationSetSuccess = b; + Properties.Settings.Default.Save(); + } + public static bool GetFirstInstallationSuccess() { return Properties.Settings.Default.FirstInstallationSuccess; @@ -29,5 +52,18 @@ namespace BeWoLauncher.Logic.Utils Properties.Settings.Default.FirstInstallationSuccess = b; Properties.Settings.Default.Save(); } + + private static string GetLauncherAppdataConfigLocation() + { + try + { + var UserConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); + return UserConfig.FilePath; + } + catch (ConfigurationException e) + { + return e.Filename; + } + } } } diff --git a/BeWoLauncher/Logic/Utils/LauncherPaths.cs b/BeWoLauncher/Logic/Utils/LauncherPaths.cs index 2bdad947a..d951f3631 100644 --- a/BeWoLauncher/Logic/Utils/LauncherPaths.cs +++ b/BeWoLauncher/Logic/Utils/LauncherPaths.cs @@ -19,16 +19,16 @@ namespace BeWoLauncher.Logic.Utils //private static readonly string versionXml = "bewo.version"; public static string LoginSelectionPlanerLocation { get; set; } - public static string ActualPlanerLocation { get; set; } + public static string PlanerLocation { get; set; } /// /// Holt den Install Ort aus den Properties Settings. /// Sollte dieser nicht verfügbar sein, wird als default - "CurrentBaseDir"/BeWoPlaner - verwendet /// /// - public static string GetInstallLocationFromSettingOrDefault() + public static string GetPlanerLocationFromSettingOrDefault() { - var installLocation = GetInstallLocationFromSetting(); + var installLocation = GetPlanerLocationFromSetting(); if (string.IsNullOrWhiteSpace(installLocation)) { @@ -38,9 +38,9 @@ namespace BeWoLauncher.Logic.Utils return installLocation; } - public static string GetInstallLocationFromSetting() + public static string GetPlanerLocationFromSetting() { - return LauncherAppdataConfig.GetInstallLocation(); + return LauncherAppdataConfig.GetPlanerLocation(); } /// @@ -71,18 +71,19 @@ namespace BeWoLauncher.Logic.Utils public static void SetAndSaveInstallLocation(string path) { - ActualPlanerLocation = path; + PlanerLocation = path; - LauncherAppdataConfig.SetInstallLocation(path); + LauncherAppdataConfig.SetPlanerLocation(path); + LauncherAppdataConfig.SetInstallLocationSetSuccess(true); } public static string GetRootPath() { - return ActualPlanerLocation; + return PlanerLocation; } public static string GetLoggerPath() { - return Path.Combine(new string[] { GetRootPath(), "log" }); + return Path.Combine(new string[] { LauncherAppdataConfig.Location, "log" }); } public static string GetDownloadPath() { diff --git a/BeWoLauncher/Properties/Settings.Designer.cs b/BeWoLauncher/Properties/Settings.Designer.cs index 3dbb00994..0f2035207 100644 --- a/BeWoLauncher/Properties/Settings.Designer.cs +++ b/BeWoLauncher/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace BeWoLauncher.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -46,5 +46,17 @@ namespace BeWoLauncher.Properties { this["FirstInstallationSuccess"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool InstallLocationSetSuccess { + get { + return ((bool)(this["InstallLocationSetSuccess"])); + } + set { + this["InstallLocationSetSuccess"] = value; + } + } } } diff --git a/BeWoLauncher/Properties/Settings.settings b/BeWoLauncher/Properties/Settings.settings index f4fc75103..9d49f8a1d 100644 --- a/BeWoLauncher/Properties/Settings.settings +++ b/BeWoLauncher/Properties/Settings.settings @@ -8,5 +8,8 @@ False + + False + \ No newline at end of file diff --git a/BeWoLauncher/View/Components/ProxyLoginView.xaml b/BeWoLauncher/View/Components/ProxyLoginView.xaml index 766ca6191..ee2e581be 100644 --- a/BeWoLauncher/View/Components/ProxyLoginView.xaml +++ b/BeWoLauncher/View/Components/ProxyLoginView.xaml @@ -2,6 +2,7 @@ x:ClassModifier="internal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:markup="clr-namespace:BeWoLauncher.MultiLanguage.Markup" Title="Proxy Einstellungen" Height="200" Width="300">