diff --git a/.idea/.idea.Aaru/.idea/contentModel.xml b/.idea/.idea.Aaru/.idea/contentModel.xml index 5f07def8f..902910ecd 100644 --- a/.idea/.idea.Aaru/.idea/contentModel.xml +++ b/.idea/.idea.Aaru/.idea/contentModel.xml @@ -1,28 +1,27 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -71,13 +70,6 @@ - - - - - - - @@ -88,12 +80,18 @@ + + + + + + @@ -102,14 +100,6 @@ - - - - - - - - @@ -117,11 +107,19 @@ + + + + + + + + @@ -180,6 +178,13 @@ + + + + + + + @@ -200,19 +205,10 @@ - - - - - - - - - @@ -221,6 +217,7 @@ + @@ -238,6 +235,7 @@ + @@ -258,8 +256,8 @@ - + @@ -269,11 +267,11 @@ - + - + @@ -287,17 +285,17 @@ - - + + - + @@ -317,12 +315,19 @@ - + + + + + + + + @@ -339,68 +344,61 @@ - - - - - - - - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + @@ -425,7 +423,6 @@ - @@ -437,11 +434,12 @@ + - + @@ -463,9 +461,9 @@ + - @@ -495,6 +493,13 @@ + + + + + + + @@ -558,11 +563,11 @@ + - @@ -582,17 +587,10 @@ - - - - - - - - + @@ -649,6 +647,13 @@ + + + + + + + @@ -661,28 +666,17 @@ - + - - - - - - - - + - - - - @@ -690,13 +684,16 @@ + + + - - + + @@ -732,11 +729,13 @@ + - + + @@ -744,11 +743,14 @@ - + + + + @@ -788,8 +790,8 @@ - + @@ -798,8 +800,8 @@ - + @@ -808,8 +810,8 @@ - + @@ -836,8 +838,15 @@ - + + + + + + + + @@ -855,11 +864,11 @@ - + @@ -882,34 +891,17 @@ - - - - - - - - - - - - + - - - - - - @@ -917,12 +909,18 @@ + + + + + + @@ -1016,6 +1014,12 @@ + + + + + + @@ -1040,12 +1044,6 @@ - - - - - - @@ -1128,6 +1126,8 @@ + + @@ -1143,6 +1143,18 @@ + + + + + + + + + + + + @@ -1155,18 +1167,6 @@ - - - - - - - - - - - - @@ -1175,14 +1175,14 @@ - - + + @@ -1205,12 +1205,10 @@ - - - + @@ -1219,8 +1217,6 @@ - - @@ -1250,6 +1246,16 @@ + + + + + + + + + + @@ -1288,6 +1294,7 @@ + @@ -1300,6 +1307,8 @@ + + @@ -1315,17 +1324,6 @@ - - - - - - - - - - - @@ -1334,6 +1332,7 @@ + @@ -1341,10 +1340,6 @@ - - - - @@ -1352,6 +1347,9 @@ + + + @@ -1434,16 +1432,7 @@ - - - - - - - - - - + @@ -1465,6 +1454,16 @@ + + + + + + + + + + @@ -1498,16 +1497,6 @@ - - - - - - - - - - @@ -1545,6 +1534,16 @@ + + + + + + + + + + @@ -1635,8 +1634,8 @@ - + @@ -1670,16 +1669,6 @@ - - - - - - - - - - @@ -1691,6 +1680,23 @@ + + + + + + + + + + + + + + + + + @@ -1873,16 +1879,6 @@ - - - - - - - - - - @@ -1893,6 +1889,16 @@ + + + + + + + + + + @@ -1911,14 +1917,6 @@ - - - - - - - - @@ -1926,6 +1924,7 @@ + @@ -1933,6 +1932,13 @@ + + + + + + + @@ -1942,20 +1948,11 @@ - - - - - - - - - + - @@ -1964,19 +1961,13 @@ + - - - - - - - - - - + + + @@ -2010,8 +2001,8 @@ - + @@ -2019,7 +2010,7 @@ - + @@ -2042,7 +2033,14 @@ + + + + + + + \ No newline at end of file diff --git a/Aaru.Gui/Aaru.Gui.csproj b/Aaru.Gui/Aaru.Gui.csproj index 40f1a5d1e..81b99036a 100644 --- a/Aaru.Gui/Aaru.Gui.csproj +++ b/Aaru.Gui/Aaru.Gui.csproj @@ -343,6 +343,12 @@ PluginsDialog.xaml + + Designer + + + ConsoleDialog.xaml + diff --git a/Aaru.Gui/ConsoleHandler.cs b/Aaru.Gui/ConsoleHandler.cs index 0b04f051f..571326a80 100644 --- a/Aaru.Gui/ConsoleHandler.cs +++ b/Aaru.Gui/ConsoleHandler.cs @@ -133,7 +133,7 @@ namespace Aaru.Gui } } - internal class LogEntry + public class LogEntry { public string Message { get; set; } public string Module { get; set; } diff --git a/Aaru.Gui/Forms/frmConsole.xeto b/Aaru.Gui/Forms/frmConsole.xeto deleted file mode 100644 index d8124a29a..000000000 --- a/Aaru.Gui/Forms/frmConsole.xeto +++ /dev/null @@ -1,55 +0,0 @@ - - -
- - - - - - Enable debug console - - - - - - - - - - - - -
\ No newline at end of file diff --git a/Aaru.Gui/Forms/frmConsole.xeto.cs b/Aaru.Gui/Forms/frmConsole.xeto.cs deleted file mode 100644 index c46679c27..000000000 --- a/Aaru.Gui/Forms/frmConsole.xeto.cs +++ /dev/null @@ -1,204 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : frmConsole.xeto.cs -// Author(s) : Natalia Portillo -// -// Component : Console window. -// -// --[ Description ] ---------------------------------------------------------- -// -// Implements the console window and saving or clearing console log. -// -// --[ License ] -------------------------------------------------------------- -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General public License for more details. -// -// You should have received a copy of the GNU General public License -// along with this program. If not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.ComponentModel; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using Aaru.CommonTypes.Interop; -using Aaru.Console; -using Eto.Drawing; -using Eto.Forms; -using Eto.Serialization.Xaml; -using PlatformID = Aaru.CommonTypes.Interop.PlatformID; -using Version = Aaru.CommonTypes.Interop.Version; - -namespace Aaru.Gui.Forms -{ - public class frmConsole : Form - { - public frmConsole() - { - XamlReader.Load(this); - - grdMessages.DataStore = ConsoleHandler.Entries; - - grdMessages.Columns.Add(new GridColumn - { - DataCell = new TextBoxCell - { - Binding = Binding.Property(r => $"{r.Timestamp}") - }, - HeaderText = "Time", Sortable = true - }); - - grdMessages.Columns.Add(new GridColumn - { - DataCell = new TextBoxCell - { - Binding = Binding.Property(r => r.Type) - }, - HeaderText = "Type", Sortable = true - }); - - grdMessages.Columns.Add(new GridColumn - { - DataCell = new TextBoxCell - { - Binding = Binding.Property(r => r.Module) - }, - HeaderText = "Module", Sortable = true - }); - - grdMessages.Columns.Add(new GridColumn - { - DataCell = new TextBoxCell - { - Binding = Binding.Property(r => r.Message) - }, - HeaderText = "Message", Sortable = true - }); - - grdMessages.AllowMultipleSelection = false; - - grdMessages.CellFormatting += (sender, e) => - { - if(((LogEntry)e.Item).Type.ToLower() != "error") - return; - - e.BackgroundColor = Colors.Red; - e.ForegroundColor = Colors.Black; - }; - - grdMessages.AllowColumnReordering = true; - - chkDebug.Checked = ConsoleHandler.Debug; - Closing += OnClosing; - } - - // Otherwise if this closes it does not stop hearing events from collection, preventing console to keep working. - void OnClosing(object sender, CancelEventArgs e) => grdMessages.DataStore = null; - - protected void OnChkDebugChecked(object sender, EventArgs e) => ConsoleHandler.Debug = chkDebug.Checked.Value; - - protected void OnBtnClearClicked(object sender, EventArgs e) => ConsoleHandler.Entries.Clear(); - - protected void OnBtnSaveClicked(object sender, EventArgs e) - { - var dlgSave = new SaveFileDialog - { - CheckFileExists = true - }; - - dlgSave.Filters.Add(new FileFilter - { - Extensions = new[] - { - "log" - }, - Name = "Log files" - }); - - DialogResult result = dlgSave.ShowDialog(this); - - if(result != DialogResult.Ok) - return; - - try - { - var logFs = new FileStream(dlgSave.FileName, FileMode.Create, FileAccess.ReadWrite); - var logSw = new StreamWriter(logFs); - - logSw.WriteLine("Log saved at {0}", DateTime.Now); - - PlatformID platId = DetectOS.GetRealPlatformID(); - string platVer = DetectOS.GetVersion(); - - var assemblyVersion = - Attribute.GetCustomAttribute(typeof(AaruConsole).Assembly, - typeof(AssemblyInformationalVersionAttribute)) as - AssemblyInformationalVersionAttribute; - - logSw.WriteLine("################# System information #################"); - - logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer, - Environment.Is64BitOperatingSystem ? 64 : 32); - - if(DetectOS.IsMono) - logSw.WriteLine("Mono {0}", Version.GetMonoVersion()); - else if(DetectOS.IsNetCore) - logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion()); - else - logSw.WriteLine(RuntimeInformation.FrameworkDescription); - - logSw.WriteLine(); - - logSw.WriteLine("################# Program information ################"); - logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion); - logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32); - logSw.WriteLine("Running GUI mode using {0}", Application.Instance.Platform.ID); - #if DEBUG - logSw.WriteLine("DEBUG version"); - #endif - logSw.WriteLine("Command line: {0}", Environment.CommandLine); - logSw.WriteLine(); - - logSw.WriteLine("################# Console ################"); - - foreach(LogEntry entry in ConsoleHandler.Entries) - if(entry.Type != "Info") - logSw.WriteLine("{0}: ({1}) {2}", entry.Timestamp, entry.Type.ToLower(), entry.Message); - else - logSw.WriteLine("{0}: {1}", entry.Timestamp, entry.Message); - - logSw.Close(); - logFs.Close(); - } - catch(Exception exception) - { - Eto.Forms.MessageBox.Show("Exception {0} trying to save logfile, details has been sent to console.", - exception.Message); - - AaruConsole.ErrorWriteLine("Console", exception.Message); - AaruConsole.ErrorWriteLine("Console", exception.StackTrace); - } - } - - #region XAML controls - GridView grdMessages; - CheckBox chkDebug; - Button btnClear; - Button btnSave; - #endregion - } -} \ No newline at end of file diff --git a/Aaru.Gui/Forms/frmMain.xeto.cs b/Aaru.Gui/Forms/frmMain.xeto.cs index 036e0d727..2f43ba47c 100644 --- a/Aaru.Gui/Forms/frmMain.xeto.cs +++ b/Aaru.Gui/Forms/frmMain.xeto.cs @@ -669,8 +669,6 @@ namespace Aaru.Gui.Forms } } - protected void OnMenuConsole(object sender, EventArgs e) => new frmConsole().Show(); - protected void OnTreeImagesSelectedItemChanged(object sender, EventArgs e) { if(!(sender is TreeGridView tree)) diff --git a/Aaru.Gui/ViewModels/ConsoleWindowViewModel.cs b/Aaru.Gui/ViewModels/ConsoleWindowViewModel.cs new file mode 100644 index 000000000..ae793a0f7 --- /dev/null +++ b/Aaru.Gui/ViewModels/ConsoleWindowViewModel.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Reactive; +using System.Reflection; +using Aaru.CommonTypes.Interop; +using Aaru.Console; +using Aaru.Gui.Views; +using Avalonia.Controls; +using ReactiveUI; +using PlatformID = Aaru.CommonTypes.Interop.PlatformID; +using Version = Aaru.CommonTypes.Interop.Version; + +namespace Aaru.Gui.ViewModels +{ + public class ConsoleWindowViewModel : ViewModelBase + { + bool _debugChecked; + readonly ConsoleWindow _view; + + public ConsoleWindowViewModel(ConsoleWindow view) + { + _view = view; + SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand); + ClearCommand = ReactiveCommand.Create(ExecuteClearCommand); + } + + public string Title => "Console"; + public ReactiveCommand ClearCommand { get; } + public ReactiveCommand SaveCommand { get; } + public ObservableCollection Entries => ConsoleHandler.Entries; + public string DebugText => "Enable debug console"; + public string SaveLabel => "Save"; + public string ClearLabel => "Clear"; + + public bool DebugChecked + { + get => _debugChecked; + set + { + ConsoleHandler.Debug = value; + this.RaiseAndSetIfChanged(ref _debugChecked, value); + } + } + + async void ExecuteSaveCommand() + { + var dlgSave = new SaveFileDialog(); + + dlgSave.Filters.Add(new FileDialogFilter + { + Extensions = new List(new[] + { + "log" + }), + Name = "Log files" + }); + + string result = await dlgSave.ShowAsync(_view); + + if(result is null) + return; + + try + { + var logFs = new FileStream(result, FileMode.Create, FileAccess.ReadWrite); + var logSw = new StreamWriter(logFs); + + logSw.WriteLine("Log saved at {0}", DateTime.Now); + + PlatformID platId = DetectOS.GetRealPlatformID(); + string platVer = DetectOS.GetVersion(); + + var assemblyVersion = + Attribute.GetCustomAttribute(typeof(AaruConsole).Assembly, + typeof(AssemblyInformationalVersionAttribute)) as + AssemblyInformationalVersionAttribute; + + logSw.WriteLine("################# System information #################"); + + logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer, + Environment.Is64BitOperatingSystem ? 64 : 32); + + logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion()); + + logSw.WriteLine(); + + logSw.WriteLine("################# Program information ################"); + logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion); + logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32); + #if DEBUG + logSw.WriteLine("DEBUG version"); + #endif + logSw.WriteLine("Command line: {0}", Environment.CommandLine); + logSw.WriteLine(); + + logSw.WriteLine("################# Console ################"); + + foreach(LogEntry entry in ConsoleHandler.Entries) + if(entry.Type != "Info") + logSw.WriteLine("{0}: ({1}) {2}", entry.Timestamp, entry.Type.ToLower(), entry.Message); + else + logSw.WriteLine("{0}: {1}", entry.Timestamp, entry.Message); + + logSw.Close(); + logFs.Close(); + } + catch(Exception exception) + { + Eto.Forms.MessageBox.Show("Exception {0} trying to save logfile, details has been sent to console.", + exception.Message); + + AaruConsole.ErrorWriteLine("Console", exception.Message); + AaruConsole.ErrorWriteLine("Console", exception.StackTrace); + } + } + + void ExecuteClearCommand() => ConsoleHandler.Entries.Clear(); + } +} \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/MainWindowViewModel.cs b/Aaru.Gui/ViewModels/MainWindowViewModel.cs index e74009fa2..91e1189e8 100644 --- a/Aaru.Gui/ViewModels/MainWindowViewModel.cs +++ b/Aaru.Gui/ViewModels/MainWindowViewModel.cs @@ -13,6 +13,7 @@ namespace Aaru.Gui.ViewModels public class MainWindowViewModel : ViewModelBase { readonly MainWindow _view; + ConsoleWindow _consoleWindow; public MainWindowViewModel(MainWindow view) { @@ -22,6 +23,7 @@ namespace Aaru.Gui.ViewModels StatisticsCommand = ReactiveCommand.Create(ExecuteStatisticsCommand); ExitCommand = ReactiveCommand.Create(ExecuteExitCommand); SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand); + ConsoleCommand = ReactiveCommand.Create(ExecuteConsoleCommand); _view = view; } @@ -29,9 +31,10 @@ namespace Aaru.Gui.ViewModels public bool NativeMenuSupported => NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as - IClassicDesktopStyleApplicationLifetime)?.MainWindow); + IClassicDesktopStyleApplicationLifetime)?.MainWindow); public ReactiveCommand AboutCommand { get; } + public ReactiveCommand ConsoleCommand { get; } public ReactiveCommand EncodingsCommand { get; } public ReactiveCommand PluginsCommand { get; } public ReactiveCommand StatisticsCommand { get; } @@ -90,5 +93,16 @@ namespace Aaru.Gui.ViewModels internal void ExecuteExitCommand() => (Application.Current.ApplicationLifetime as ClassicDesktopStyleApplicationLifetime)?.Shutdown(); + + internal void ExecuteConsoleCommand() + { + if(_consoleWindow is null) + { + _consoleWindow = new ConsoleWindow(); + _consoleWindow.DataContext = new ConsoleWindowViewModel(_consoleWindow); + } + + _consoleWindow.Show(); + } } } \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/SplashWindowViewModel.cs b/Aaru.Gui/ViewModels/SplashWindowViewModel.cs index 0026fb195..6e1e4c983 100644 --- a/Aaru.Gui/ViewModels/SplashWindowViewModel.cs +++ b/Aaru.Gui/ViewModels/SplashWindowViewModel.cs @@ -58,6 +58,7 @@ namespace Aaru.Gui.ViewModels Task.Run(() => { ConsoleHandler.Init(); + AaruConsole.WriteLine("Aaru started!"); Dispatcher.UIThread.Post(LoadSettings); }); @@ -67,6 +68,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Loading settings..."; + AaruConsole.WriteLine("Loading settings..."); Task.Run(() => { @@ -81,6 +83,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Migrating local database..."; + AaruConsole.WriteLine("Migrating local database..."); Task.Run(() => { @@ -96,6 +99,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Updating master database..."; + AaruConsole.WriteLine("Updating master database..."); Task.Run(() => { @@ -138,6 +142,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Checking GDPR compliance..."; + AaruConsole.WriteLine("Checking GDPR compliance..."); if(Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel) { @@ -145,7 +150,6 @@ namespace Aaru.Gui.ViewModels var settingsDialogViewModel = new SettingsDialogViewModel(settingsDialog, true); settingsDialog.DataContext = settingsDialogViewModel; await settingsDialog.ShowDialog(_view); - AaruConsole.ErrorWriteLine("Settings window not yet implemented"); } LoadStatistics(); @@ -155,6 +159,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Loading statistics..."; + AaruConsole.WriteLine("Loading statistics..."); Task.Run(() => { @@ -168,6 +173,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Registering encodings..."; + AaruConsole.WriteLine("Registering encodings..."); Task.Run(() => { @@ -181,6 +187,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Saving statistics..."; + AaruConsole.WriteLine("Saving statistics..."); Task.Run(() => { @@ -194,6 +201,7 @@ namespace Aaru.Gui.ViewModels { CurrentProgress++; Message = "Loading main window..."; + AaruConsole.WriteLine("Loading main window..."); WorkFinished?.Invoke(this, EventArgs.Empty); } diff --git a/Aaru.Gui/Views/ConsoleDialog.xaml b/Aaru.Gui/Views/ConsoleDialog.xaml new file mode 100644 index 000000000..93d4b0384 --- /dev/null +++ b/Aaru.Gui/Views/ConsoleDialog.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Aaru.Gui/Views/ConsoleDialog.xaml.cs b/Aaru.Gui/Views/ConsoleDialog.xaml.cs new file mode 100644 index 000000000..52cc96a1f --- /dev/null +++ b/Aaru.Gui/Views/ConsoleDialog.xaml.cs @@ -0,0 +1,28 @@ +using System.ComponentModel; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Aaru.Gui.Views +{ + public class ConsoleWindow : Window + { + public ConsoleWindow() + { + InitializeComponent(); + #if DEBUG + this.AttachDevTools(); + #endif + } + + void InitializeComponent() => AvaloniaXamlLoader.Load(this); + + protected override void OnClosing(CancelEventArgs e) + { + e.Cancel = true; + Hide(); + + base.OnClosing(e); + } + } +} \ No newline at end of file diff --git a/Aaru.Gui/Views/MainWindow.xaml b/Aaru.Gui/Views/MainWindow.xaml index c4207c39b..a1814d6a0 100644 --- a/Aaru.Gui/Views/MainWindow.xaml +++ b/Aaru.Gui/Views/MainWindow.xaml @@ -19,7 +19,7 @@ - +