From 65945fd94d0588f10ee0d77e11bdb5d68b9d9a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Tue, 2 Jul 2024 13:12:40 +0200 Subject: [PATCH] Refractor Log page to simplify implementation, fix theming issues (fix #2381) --- src/UniGetUI/Interface/MainView.xaml.cs | 7 +- src/UniGetUI/Interface/Pages/LogPage.xaml.cs | 273 ------------------ .../Interface/Pages/LogPage/AppLogPage.cs | 89 ++++++ .../Pages/{ => LogPage}/LogPage.xaml | 10 +- .../Interface/Pages/LogPage/LogPage.xaml.cs | 127 ++++++++ .../Pages/LogPage/ManagerLogsPage.cs | 75 +++++ .../Pages/LogPage/OperationHistoryPage.cs | 41 +++ .../Interface/Pages/SettingsPage.xaml.cs | 1 - src/UniGetUI/UniGetUI.csproj.user | 3 - 9 files changed, 341 insertions(+), 285 deletions(-) delete mode 100644 src/UniGetUI/Interface/Pages/LogPage.xaml.cs create mode 100644 src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs rename src/UniGetUI/Interface/Pages/{ => LogPage}/LogPage.xaml (73%) create mode 100644 src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml.cs create mode 100644 src/UniGetUI/Interface/Pages/LogPage/ManagerLogsPage.cs create mode 100644 src/UniGetUI/Interface/Pages/LogPage/OperationHistoryPage.cs diff --git a/src/UniGetUI/Interface/MainView.xaml.cs b/src/UniGetUI/Interface/MainView.xaml.cs index 6cd91100f..26bbb815b 100644 --- a/src/UniGetUI/Interface/MainView.xaml.cs +++ b/src/UniGetUI/Interface/MainView.xaml.cs @@ -9,6 +9,7 @@ using UniGetUI.Core.Tools; using UniGetUI.Interface.Dialogs; using UniGetUI.Interface.Pages; +using UniGetUI.Interface.Pages.LogPage; using UniGetUI.Interface.SoftwarePages; using UniGetUI.Interface.Widgets; using UniGetUI.PackageEngine.Enums; @@ -593,17 +594,17 @@ public async Task ConfirmUninstallation(IEnumerable packages) private void OperationHistoryMenu_Click(object sender, RoutedEventArgs e) { - NavigateToPage(new Logger_LogPage(Logger_LogType.OperationHistory)); + NavigateToPage(new OperationHistoryPage()); } private void ManagerLogsMenu_Click(object sender, RoutedEventArgs e) { - NavigateToPage(new Logger_LogPage(Logger_LogType.ManagerLogs)); + NavigateToPage(new ManagerLogsPage()); } public void UniGetUILogs_Click(object sender, RoutedEventArgs e) { - NavigateToPage(new Logger_LogPage(Logger_LogType.UniGetUILog)); + NavigateToPage(new AppLogPage()); } private void HelpMenu_Click(object sender, RoutedEventArgs e) diff --git a/src/UniGetUI/Interface/Pages/LogPage.xaml.cs b/src/UniGetUI/Interface/Pages/LogPage.xaml.cs deleted file mode 100644 index a33e095b3..000000000 --- a/src/UniGetUI/Interface/Pages/LogPage.xaml.cs +++ /dev/null @@ -1,273 +0,0 @@ -using ExternalLibraries.Clipboard; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Documents; -using Microsoft.UI.Xaml.Media; -using System.Diagnostics; -using UniGetUI.Core.Logging; -using UniGetUI.Core.SettingsEngine; -using UniGetUI.Core.Tools; -using UniGetUI.PackageEngine; -using Windows.Storage; -using Windows.Storage.Pickers; -using Windows.UI; - -// To learn more about WinUI, the WinUI project structure, -// and more about our project templates, see: http://aka.ms/winui-project-info. - -namespace UniGetUI.Interface.Pages -{ - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - /// - public enum Logger_LogType - { - UniGetUILog, - ManagerLogs, - OperationHistory - } - - public sealed partial class Logger_LogPage : Page, IPageWithKeyboardShortcuts - { - private int LOG_LEVEL = 4; - public Logger_LogType Logger_LogType; - public Logger_LogPage(Logger_LogType logger_LogType = Logger_LogType.UniGetUILog) - { - InitializeComponent(); - Logger_LogType = logger_LogType; - LoadLog(); - - - if (Logger_LogType == Logger_LogType.UniGetUILog) - { - LogLevelCombo.Items.Clear(); - LogLevelCombo.Items.Add(CoreTools.Translate("1 - Errors")); - LogLevelCombo.Items.Add(CoreTools.Translate("2 - Warnings")); - LogLevelCombo.Items.Add(CoreTools.Translate("3 - Information (less)")); - LogLevelCombo.Items.Add(CoreTools.Translate("4 - Information (more)")); - LogLevelCombo.Items.Add(CoreTools.Translate("5 - information (debug)")); - LogLevelCombo.SelectedIndex = 3; - } - else if (Logger_LogType == Logger_LogType.ManagerLogs) - { - LogLevelCombo.Items.Clear(); - foreach (PackageEngine.ManagerClasses.Manager.PackageManager manager in PEInterface.Managers) - { - LogLevelCombo.Items.Add(manager.Name); - LogLevelCombo.Items.Add($"{manager.Name} ({CoreTools.Translate("Verbose")})"); - } - LogLevelCombo.SelectedIndex = 0; - } - else - { - LogLevelCombo.Items.Clear(); - LogLevelCombo.Items.Add(CoreTools.Translate("Operation log")); - LogLevelCombo.SelectedIndex = 0; - } - } - - public void ReloadTriggered() - { - LoadLog(); - } - - public void SelectAllTriggered() - { - LogTextBox.SelectAll(); - } - - public void SearchTriggered() - { } - - public void SetText(string body) - { - Paragraph paragraph = new(); - foreach (string line in body.Split("\n")) - { - if (line.Replace("\r", "").Replace("\n", "").Trim() == "") - { - continue; - } - - paragraph.Inlines.Add(new Run { Text = line.Replace("\r", "").Replace("\n", "") }); - paragraph.Inlines.Add(new LineBreak()); - } - LogTextBox.Blocks.Clear(); - LogTextBox.Blocks.Add(paragraph); - } - - // Dark theme colors - Color DARK_GREY = Color.FromArgb(255, 130, 130, 130); - Color DARK_LIGHT_GREY = Color.FromArgb(255, 190, 190, 190); - Color DARK_WHITE = Color.FromArgb(255, 250, 250, 250); - Color DARK_YELLOW = Color.FromArgb(255, 255, 255, 90); - Color DARK_RED = Color.FromArgb(255, 255, 80, 80); - Color DARK_GREEN = Color.FromArgb(255, 80, 255, 80); - Color DARK_BLUE = Color.FromArgb(255, 120, 120, 255); - - // Light theme colors - Color LIGHT_GREY = Color.FromArgb(255, 125, 125, 225); - Color LIGHT_LIGHT_GREY = Color.FromArgb(255, 50, 50, 150); - Color LIGHT_WHITE = Color.FromArgb(255, 0, 0, 0); - Color LIGHT_YELLOW = Color.FromArgb(255, 150, 150, 0); - Color LIGHT_RED = Color.FromArgb(255, 205, 0, 0); - Color LIGHT_GREEN = Color.FromArgb(255, 0, 205, 0); - Color LIGHT_BLUE = Color.FromArgb(255, 0, 0, 205); - - public void LoadLog() - { - - - bool IS_DARK = MainApp.Instance.ThemeListener.CurrentTheme == ApplicationTheme.Dark; - - if (Logger_LogType == Logger_LogType.UniGetUILog) - { - - LogEntry[] logs = Logger.GetLogs(); - LogTextBox.Blocks.Clear(); - foreach (LogEntry log_entry in logs) - { - Paragraph p = new(); - if (log_entry.Content == "") - { - continue; - } - - if (LOG_LEVEL == 1 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success || log_entry.Severity == LogEntry.SeverityLevel.Warning)) - { - continue; - } - else if (LOG_LEVEL == 2 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success)) - { - continue; - } - else if (LOG_LEVEL == 3 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info)) - { - continue; - } - else if (LOG_LEVEL == 4 && (log_entry.Severity == LogEntry.SeverityLevel.Debug)) - { - continue; - } - - Brush color = log_entry.Severity switch - { - LogEntry.SeverityLevel.Debug => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY }, - LogEntry.SeverityLevel.Info => new SolidColorBrush { Color = IS_DARK ? DARK_LIGHT_GREY : LIGHT_LIGHT_GREY }, - LogEntry.SeverityLevel.Success => new SolidColorBrush { Color = IS_DARK ? DARK_WHITE : LIGHT_WHITE }, - LogEntry.SeverityLevel.Warning => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, - LogEntry.SeverityLevel.Error => new SolidColorBrush { Color = IS_DARK ? DARK_RED : LIGHT_RED }, - _ => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY }, - }; - string[] lines = log_entry.Content.Split('\n'); - int date_length = -1; - foreach (string line in lines) - { - if (date_length == -1) - { - p.Inlines.Add(new Run { Text = $"[{log_entry.Time}] {line}\n", Foreground = color }); - date_length = $"[{log_entry.Time}] ".Length; - } - else - { - p.Inlines.Add(new Run { Text = new string(' ', date_length) + line + "\n", Foreground = color }); - } - } ((Run)p.Inlines[^1]).Text = ((Run)p.Inlines[^1]).Text.TrimEnd(); - LogTextBox.Blocks.Add(p); - } - MainScroller.ScrollToVerticalOffset(MainScroller.ScrollableHeight); - } - - else if (Logger_LogType == Logger_LogType.ManagerLogs) - { - bool verbose = LogLevelCombo.SelectedValue?.ToString()?.Contains("(") ?? false; - foreach (PackageEngine.ManagerClasses.Manager.PackageManager manager in PEInterface.Managers) - { - if (manager.Name.Contains(LogLevelCombo.SelectedValue?.ToString()?.Split(' ')[0] ?? "uncontained_word")) - { - PackageEngine.ManagerClasses.Classes.ManagerLogger TaskLogger = manager.TaskLogger; - LogTextBox.Blocks.Clear(); - Paragraph versionParagraph = new(); - versionParagraph.Inlines.Add(new Run() { Text = $"Manager {manager.Name} with version:\n" }); - versionParagraph.Inlines.Add(new Run() { Text = manager.Status.Version }); - versionParagraph.Inlines.Add(new Run() { Text = $"\n\n——————————————————————————————————————————\n\n" }); - LogTextBox.Blocks.Add(versionParagraph); - - foreach (PackageEngine.ManagerClasses.Classes.TaskLogger operation in TaskLogger.Operations) - { - Paragraph p = new(); - foreach (string line in operation.AsColoredString(verbose)) - { - Brush color = line[0] switch - { - '0' => new SolidColorBrush { Color = IS_DARK ? DARK_WHITE : LIGHT_WHITE }, - '1' => new SolidColorBrush { Color = IS_DARK ? DARK_LIGHT_GREY : LIGHT_LIGHT_GREY }, - '2' => new SolidColorBrush { Color = IS_DARK ? DARK_RED : LIGHT_RED }, - '3' => new SolidColorBrush { Color = IS_DARK ? DARK_BLUE : LIGHT_BLUE }, - '4' => new SolidColorBrush { Color = IS_DARK ? DARK_GREEN : LIGHT_GREEN }, - '5' => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, - _ => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, - }; - p.Inlines.Add(new Run() { Text = line[1..] + "\n", Foreground = color }); - } - ((Run)p.Inlines[^1]).Text = ((Run)p.Inlines[^1]).Text.TrimEnd(); - LogTextBox.Blocks.Add(p); - } - break; - } - } - - MainScroller.ScrollToVerticalOffset(MainScroller.ScrollableHeight); - } - else if (Logger_LogType == Logger_LogType.OperationHistory) - { - SetText(Settings.GetValue("OperationHistory")); - } - } - - public void CopyButton_Click(object sender, RoutedEventArgs e) - { - LogTextBox.SelectAll(); - WindowsClipboard.SetText(LogTextBox.SelectedText); - LogTextBox.Select(LogTextBox.SelectionStart, LogTextBox.SelectionStart); - } - - public async void ExportButton_Click(object sender, RoutedEventArgs e) - { - FileSavePicker savePicker = new() - { - SuggestedStartLocation = PickerLocationId.DocumentsLibrary - }; - WinRT.Interop.InitializeWithWindow.Initialize(savePicker, WinRT.Interop.WindowNative.GetWindowHandle(MainApp.Instance.MainWindow)); - savePicker.FileTypeChoices.Add(CoreTools.Translate("Text"), [".txt"]); - savePicker.SuggestedFileName = CoreTools.Translate("WingetUI Log"); - - StorageFile file = await savePicker.PickSaveFileAsync(); - if (file != null) - { - LogTextBox.SelectAll(); - await File.WriteAllTextAsync(file.Path, LogTextBox.SelectedText); - LogTextBox.Select(LogTextBox.SelectionStart, LogTextBox.SelectionStart); - Process.Start(new ProcessStartInfo() - { - FileName = "explorer.exe", - Arguments = @$"/select, ""{file.Path}""" - }); - - } - } - - public void ReloadButton_Click(object sender, RoutedEventArgs e) - { - LoadLog(); - } - - - private void LogLevelCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - LOG_LEVEL = LogLevelCombo.SelectedIndex + 1; - LoadLog(); - } - } -} diff --git a/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs b/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs new file mode 100644 index 000000000..f6efd05a6 --- /dev/null +++ b/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs @@ -0,0 +1,89 @@ +using Microsoft.UI.Xaml.Documents; +using Microsoft.UI.Xaml.Media; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniGetUI.Core.Logging; +using UniGetUI.Core.Tools; + +namespace UniGetUI.Interface.Pages.LogPage +{ + internal class AppLogPage : BaseLogPage + { + public AppLogPage() : base(true) + { + } + + protected override void LoadLogLevels() + { + LogLevelCombo.Items.Clear(); + LogLevelCombo.Items.Add(CoreTools.Translate("1 - Errors")); + LogLevelCombo.Items.Add(CoreTools.Translate("2 - Warnings")); + LogLevelCombo.Items.Add(CoreTools.Translate("3 - Information (less)")); + LogLevelCombo.Items.Add(CoreTools.Translate("4 - Information (more)")); + LogLevelCombo.Items.Add(CoreTools.Translate("5 - information (debug)")); + LogLevelCombo.SelectedIndex = 3; + } + + public override void LoadLog() + { + bool IS_DARK = ActualTheme == Microsoft.UI.Xaml.ElementTheme.Dark; + + LogEntry[] logs = Logger.GetLogs(); + LogTextBox.Blocks.Clear(); + foreach (LogEntry log_entry in logs) + { + Paragraph p = new(); + if (log_entry.Content == "") + { + continue; + } + + if (LOG_LEVEL == 1 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success || log_entry.Severity == LogEntry.SeverityLevel.Warning)) + { + continue; + } + else if (LOG_LEVEL == 2 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success)) + { + continue; + } + else if (LOG_LEVEL == 3 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info)) + { + continue; + } + else if (LOG_LEVEL == 4 && (log_entry.Severity == LogEntry.SeverityLevel.Debug)) + { + continue; + } + + Brush color = log_entry.Severity switch + { + LogEntry.SeverityLevel.Debug => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY }, + LogEntry.SeverityLevel.Info => new SolidColorBrush { Color = IS_DARK ? DARK_LIGHT_GREY : LIGHT_LIGHT_GREY }, + LogEntry.SeverityLevel.Success => new SolidColorBrush { Color = IS_DARK ? DARK_WHITE : LIGHT_WHITE }, + LogEntry.SeverityLevel.Warning => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, + LogEntry.SeverityLevel.Error => new SolidColorBrush { Color = IS_DARK ? DARK_RED : LIGHT_RED }, + _ => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY }, + }; + string[] lines = log_entry.Content.Split('\n'); + int date_length = -1; + foreach (string line in lines) + { + if (date_length == -1) + { + p.Inlines.Add(new Run { Text = $"[{log_entry.Time}] {line}\n", Foreground = color }); + date_length = $"[{log_entry.Time}] ".Length; + } + else + { + p.Inlines.Add(new Run { Text = new string(' ', date_length) + line + "\n", Foreground = color }); + } + } ((Run)p.Inlines[^1]).Text = ((Run)p.Inlines[^1]).Text.TrimEnd(); + LogTextBox.Blocks.Add(p); + } + MainScroller.ScrollToVerticalOffset(MainScroller.ScrollableHeight); + } + } +} diff --git a/src/UniGetUI/Interface/Pages/LogPage.xaml b/src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml similarity index 73% rename from src/UniGetUI/Interface/Pages/LogPage.xaml rename to src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml index 4b0f9338c..0ebaa228b 100644 --- a/src/UniGetUI/Interface/Pages/LogPage.xaml +++ b/src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml @@ -1,6 +1,6 @@ - + - + - - + + diff --git a/src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml.cs b/src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml.cs new file mode 100644 index 000000000..ae464d200 --- /dev/null +++ b/src/UniGetUI/Interface/Pages/LogPage/LogPage.xaml.cs @@ -0,0 +1,127 @@ +using ExternalLibraries.Clipboard; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Documents; +using Microsoft.UI.Xaml.Media; +using System.Diagnostics; +using UniGetUI.Core.Logging; +using UniGetUI.Core.SettingsEngine; +using UniGetUI.Core.Tools; +using UniGetUI.PackageEngine; +using Windows.Storage; +using Windows.Storage.Pickers; +using Windows.UI; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace UniGetUI.Interface.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + /// + + public abstract partial class BaseLogPage : Page, IPageWithKeyboardShortcuts + { + protected int LOG_LEVEL = 4; + private readonly bool LogLevelEnabled; + + protected abstract void LoadLogLevels(); + public abstract void LoadLog(); + + + public BaseLogPage(bool log_level_enabled) + { + LogLevelEnabled = log_level_enabled; + InitializeComponent(); + if (LogLevelEnabled) + { + LoadLogLevels(); + } + else + { + LogLevelPane.Visibility = Visibility.Collapsed; + } + LoadLog(); + } + + public void ReloadTriggered() + { + LoadLog(); + } + + public void SelectAllTriggered() + { + LogTextBox.SelectAll(); + } + + public void SearchTriggered() + { } + + public void SetText(string body) + { + } + + // Dark theme colors + protected Color DARK_GREY = Color.FromArgb(255, 130, 130, 130); + protected Color DARK_LIGHT_GREY = Color.FromArgb(255, 190, 190, 190); + protected Color DARK_WHITE = Color.FromArgb(255, 250, 250, 250); + protected Color DARK_YELLOW = Color.FromArgb(255, 255, 255, 90); + protected Color DARK_RED = Color.FromArgb(255, 255, 80, 80); + protected Color DARK_GREEN = Color.FromArgb(255, 80, 255, 80); + protected Color DARK_BLUE = Color.FromArgb(255, 120, 120, 255); + + // Light theme colors + protected Color LIGHT_GREY = Color.FromArgb(255, 125, 125, 225); + protected Color LIGHT_LIGHT_GREY = Color.FromArgb(255, 50, 50, 150); + protected Color LIGHT_WHITE = Color.FromArgb(255, 0, 0, 0); + protected Color LIGHT_YELLOW = Color.FromArgb(255, 150, 150, 0); + protected Color LIGHT_RED = Color.FromArgb(255, 205, 0, 0); + protected Color LIGHT_GREEN = Color.FromArgb(255, 0, 205, 0); + protected Color LIGHT_BLUE = Color.FromArgb(255, 0, 0, 205); + + public void CopyButton_Click(object sender, RoutedEventArgs e) + { + LogTextBox.SelectAll(); + WindowsClipboard.SetText(LogTextBox.SelectedText); + LogTextBox.Select(LogTextBox.SelectionStart, LogTextBox.SelectionStart); + } + + public async void ExportButton_Click(object sender, RoutedEventArgs e) + { + FileSavePicker savePicker = new() + { + SuggestedStartLocation = PickerLocationId.DocumentsLibrary + }; + WinRT.Interop.InitializeWithWindow.Initialize(savePicker, WinRT.Interop.WindowNative.GetWindowHandle(MainApp.Instance.MainWindow)); + savePicker.FileTypeChoices.Add(CoreTools.Translate("Text"), [".txt"]); + savePicker.SuggestedFileName = CoreTools.Translate("WingetUI Log"); + + StorageFile file = await savePicker.PickSaveFileAsync(); + if (file != null) + { + LogTextBox.SelectAll(); + await File.WriteAllTextAsync(file.Path, LogTextBox.SelectedText); + LogTextBox.Select(LogTextBox.SelectionStart, LogTextBox.SelectionStart); + Process.Start(new ProcessStartInfo() + { + FileName = "explorer.exe", + Arguments = @$"/select, ""{file.Path}""" + }); + + } + } + + public void ReloadButton_Click(object sender, RoutedEventArgs e) + { + LoadLog(); + } + + private void LogLevelCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + LOG_LEVEL = LogLevelCombo.SelectedIndex + 1; + LoadLog(); + } + } +} diff --git a/src/UniGetUI/Interface/Pages/LogPage/ManagerLogsPage.cs b/src/UniGetUI/Interface/Pages/LogPage/ManagerLogsPage.cs new file mode 100644 index 000000000..3ff9e3cc6 --- /dev/null +++ b/src/UniGetUI/Interface/Pages/LogPage/ManagerLogsPage.cs @@ -0,0 +1,75 @@ +using Microsoft.UI.Xaml.Documents; +using Microsoft.UI.Xaml.Media; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniGetUI.Core.Tools; +using UniGetUI.PackageEngine; + +namespace UniGetUI.Interface.Pages.LogPage +{ + public class ManagerLogsPage : BaseLogPage + { + + public ManagerLogsPage() : base(true) + { + + } + public override void LoadLog() + { + bool IS_DARK = ActualTheme == Microsoft.UI.Xaml.ElementTheme.Dark; + + bool verbose = LogLevelCombo.SelectedValue?.ToString()?.Contains("(") ?? false; + foreach (PackageEngine.ManagerClasses.Manager.PackageManager manager in PEInterface.Managers) + { + if (manager.Name.Contains(LogLevelCombo.SelectedValue?.ToString()?.Split(' ')[0] ?? "uncontained_word")) + { + PackageEngine.ManagerClasses.Classes.ManagerLogger TaskLogger = manager.TaskLogger; + LogTextBox.Blocks.Clear(); + Paragraph versionParagraph = new(); + versionParagraph.Inlines.Add(new Run() { Text = $"Manager {manager.Name} with version:\n" }); + versionParagraph.Inlines.Add(new Run() { Text = manager.Status.Version }); + versionParagraph.Inlines.Add(new Run() { Text = $"\n\n——————————————————————————————————————————\n\n" }); + LogTextBox.Blocks.Add(versionParagraph); + + foreach (PackageEngine.ManagerClasses.Classes.TaskLogger operation in TaskLogger.Operations) + { + Paragraph p = new(); + foreach (string line in operation.AsColoredString(verbose)) + { + Brush color = line[0] switch + { + '0' => new SolidColorBrush { Color = IS_DARK ? DARK_WHITE : LIGHT_WHITE }, + '1' => new SolidColorBrush { Color = IS_DARK ? DARK_LIGHT_GREY : LIGHT_LIGHT_GREY }, + '2' => new SolidColorBrush { Color = IS_DARK ? DARK_RED : LIGHT_RED }, + '3' => new SolidColorBrush { Color = IS_DARK ? DARK_BLUE : LIGHT_BLUE }, + '4' => new SolidColorBrush { Color = IS_DARK ? DARK_GREEN : LIGHT_GREEN }, + '5' => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, + _ => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW }, + }; + p.Inlines.Add(new Run() { Text = line[1..] + "\n", Foreground = color }); + } + ((Run)p.Inlines[^1]).Text = ((Run)p.Inlines[^1]).Text.TrimEnd(); + LogTextBox.Blocks.Add(p); + } + break; + } + + MainScroller.ScrollToVerticalOffset(MainScroller.ScrollableHeight); + } + } + + protected override void LoadLogLevels() + { + LogLevelCombo.Items.Clear(); + foreach (PackageEngine.ManagerClasses.Manager.PackageManager manager in PEInterface.Managers) + { + LogLevelCombo.Items.Add(manager.Name); + LogLevelCombo.Items.Add($"{manager.Name} ({CoreTools.Translate("Verbose")})"); + } + LogLevelCombo.SelectedIndex = 0; + } + } +} diff --git a/src/UniGetUI/Interface/Pages/LogPage/OperationHistoryPage.cs b/src/UniGetUI/Interface/Pages/LogPage/OperationHistoryPage.cs new file mode 100644 index 000000000..290c9f30c --- /dev/null +++ b/src/UniGetUI/Interface/Pages/LogPage/OperationHistoryPage.cs @@ -0,0 +1,41 @@ +using Microsoft.UI.Xaml.Documents; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniGetUI.Core.SettingsEngine; + +namespace UniGetUI.Interface.Pages.LogPage +{ + public class OperationHistoryPage : BaseLogPage + { + public OperationHistoryPage() : base(false) + { + + } + + public override void LoadLog() + { + Paragraph paragraph = new(); + foreach (string line in Settings.GetValue("OperationHistory").Split("\n")) + { + if (line.Replace("\r", "").Replace("\n", "").Trim() == "") + { + continue; + } + + paragraph.Inlines.Add(new Run { Text = line.Replace("\r", "").Replace("\n", "") }); + paragraph.Inlines.Add(new LineBreak()); + } + LogTextBox.Blocks.Clear(); + LogTextBox.Blocks.Add(paragraph); + + } + + protected override void LoadLogLevels() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/UniGetUI/Interface/Pages/SettingsPage.xaml.cs b/src/UniGetUI/Interface/Pages/SettingsPage.xaml.cs index 340443bf4..39dd834f6 100644 --- a/src/UniGetUI/Interface/Pages/SettingsPage.xaml.cs +++ b/src/UniGetUI/Interface/Pages/SettingsPage.xaml.cs @@ -155,7 +155,6 @@ public SettingsInterface() ExtraSettingsCards[PEInterface.Chocolatey].Add(Chocolatey_SystemChoco); - foreach (PackageManager Manager in PEInterface.Managers) { diff --git a/src/UniGetUI/UniGetUI.csproj.user b/src/UniGetUI/UniGetUI.csproj.user index ca560fe11..0b4297675 100644 --- a/src/UniGetUI/UniGetUI.csproj.user +++ b/src/UniGetUI/UniGetUI.csproj.user @@ -28,9 +28,6 @@ Designer - - Designer - Designer