Skip to content

Portable Tool for an Ideal Windows Setup

upd. enhance error logging and exception metadata

Greedekse7c8ee69d1fb
diff --git a/.Source/GTweak/App.xaml.cs b/.Source/GTweak/App.xaml.cs
index 9295cb92..f60c5fc4 100644
--- a/.Source/GTweak/App.xaml.cs
+++ b/.Source/GTweak/App.xaml.cs
@@ -7,7 +7,6 @@ using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
using GTweak.Windows;
-
using Wpf.Ui.Appearance;
namespace GTweak
@@ -55,7 +54,7 @@ namespace GTweak
{
if (e != null)
{
- ErrorLogging.LogWritingFile(e.Exception);
+ ErrorLogging.LogWritingFile(e.Exception, true);
e.Handled = true;
Environment.Exit(0);
}
@@ -65,7 +64,7 @@ namespace GTweak
{
if (e?.ExceptionObject is Exception ex)
{
- ErrorLogging.LogWritingFile(ex);
+ ErrorLogging.LogWritingFile(ex, true);
}
Environment.Exit(0);
diff --git a/.Source/GTweak/Core/Base/IViewPageBase.cs b/.Source/GTweak/Core/Base/IViewPageBase.cs
new file mode 100644
index 00000000..280c7658
--- /dev/null
+++ b/.Source/GTweak/Core/Base/IViewPageBase.cs
@@ -0,0 +1,8 @@
+using System.ComponentModel;
+
+namespace GTweak.Core.Base
+{
+ [ToolboxItem(false)]
+ [DesignTimeVisible(false)]
+ internal interface IViewPageBase { }
+}
diff --git a/.Source/GTweak/Core/Base/ViewModelBase.cs b/.Source/GTweak/Core/Base/ViewModelBase.cs
index a3de989a..71c1b6f3 100644
--- a/.Source/GTweak/Core/Base/ViewModelBase.cs
+++ b/.Source/GTweak/Core/Base/ViewModelBase.cs
@@ -1,4 +1,4 @@
-using System.ComponentModel;
+using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace GTweak.Core.Base
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index 63ab9ef7..e40b6525 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -142,6 +142,7 @@
<Compile Include="Assets\UserControls\FileCard.xaml.cs">
<DependentUpon>FileCard.xaml</DependentUpon>
</Compile>
+ <Compile Include="Core\Base\IViewPageBase.cs" />
<Compile Include="Core\Base\ViewModelPageBase.cs" />
<Compile Include="Core\Converters\AngleToPercentConverter.cs" />
<Compile Include="Core\Model\AddonsModel.cs" />
diff --git a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
index bdfbd9bb..2ed097d3 100644
--- a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
+++ b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
@@ -15,41 +15,41 @@ namespace GTweak.Utilities.Controls
[Conditional("DEBUG")]
internal static void LogDebug(Exception ex, [CallerMemberName] string memberName = "") => Debug.WriteLine($"Debug: {ex.Message}\nStack Trace: {ex.StackTrace}\nMember: {memberName}\n");
- internal static void LogWritingFile(Exception ex, [CallerMemberName] string memberName = "") => Task.Run(() => LogToFile(ex, memberName)).Wait();
+ internal static void LogWritingFile(Exception ex, bool isFatal = false, [CallerMemberName] string memberName = "") => Task.Run(() => SaveDumpToFile(ex, isFatal, memberName)).Wait();
- private static async Task EnsureAssociation()
+ private static async Task EnsureLogFileAssociation()
{
try
{
- string assocLogFile = await CommandExecutor.GetCommandOutput("/c assoc .log", false);
+ string logAssocOutput = await CommandExecutor.GetCommandOutput("/c assoc .log", false);
- if (assocLogFile.IndexOf("=", StringComparison.OrdinalIgnoreCase) < 0)
+ if (logAssocOutput.IndexOf("=", StringComparison.OrdinalIgnoreCase) < 0)
{
- string assocTxtFile = await CommandExecutor.GetCommandOutput("/c assoc .txt", false);
+ string txtAssocOutput = await CommandExecutor.GetCommandOutput("/c assoc .txt", false);
- if (assocTxtFile.IndexOf("=", StringComparison.OrdinalIgnoreCase) >= 0)
+ if (txtAssocOutput.IndexOf("=", StringComparison.OrdinalIgnoreCase) >= 0)
{
- CommandExecutor.RunCommand($"/c assoc .log={assocTxtFile.Split('=')[1].Trim()}");
+ string txtApp = txtAssocOutput.Split('=')[1].Trim();
+ CommandExecutor.RunCommand($"/c assoc .log={txtApp}");
}
}
}
- catch (Exception fileEx) { LogDebug(fileEx); }
+ catch (Exception ex) { LogDebug(ex); }
}
- private static async Task LogToFile(Exception ex, string memberName)
+ private static async Task SaveDumpToFile(Exception ex, bool isFatal, string memberName)
{
try
{
using (FileStream stream = new FileStream(PathLocator.Files.ErrorLog, FileMode.Create, FileAccess.Write, FileShare.Read))
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
{
- string headerLine = "---------------------------------------------------------";
+ string separator = "---------------------------------------------------------";
Exception currentEx = ex;
byte exLevel = 1;
- await writer.WriteLineAsync($"GTweak has crashed!\n{headerLine}\nIf you wish to report this, please open an issue here:\nhttps://github.com/Greedeks/GTweak/issues\n{headerLine}\n");
- await writer.WriteLineAsync($"{headerLine}\n[{DateTime.Now}]\nOS: {(string.IsNullOrEmpty(HardwareData.OS?.Name) ? "Unknown (Loading error)" : HardwareData.OS.Name)}\nRelease: {SettingsEngine.currentRelease}\n{headerLine}\n");
-
+ await writer.WriteLineAsync($"{(isFatal ? "GTweak has crashed!" : "GTweak has encountered an error.")}\n{separator}\nIf you wish to report this, please open an issue here:\n{PathLocator.Links.GitHub}/GTweak/issues\n{separator}\n");
+ await writer.WriteLineAsync($"{separator}\n[{DateTime.Now}]\nOS: {(string.IsNullOrEmpty(HardwareData.OS?.Name) ? "Unknown" : HardwareData.OS.Name)}\nVersion: {(string.IsNullOrEmpty(HardwareData.OS?.Version) ? "Unknown" : HardwareData.OS.Version)}\nRelease: {SettingsEngine.currentRelease}\n{separator}\n");
while (currentEx != null)
{
@@ -63,7 +63,7 @@ namespace GTweak.Utilities.Controls
await writer.WriteLineAsync($"Type: {currentEx.GetType().FullName}");
await writer.WriteLineAsync($"Error: {currentEx.Message}");
- StackTrace stackTrace = new StackTrace(ex, true);
+ StackTrace stackTrace = new StackTrace(currentEx, true);
if (stackTrace.FrameCount > 0)
{
@@ -71,22 +71,29 @@ namespace GTweak.Utilities.Controls
if (frame?.GetMethod() is MethodBase method)
{
- await writer.WriteLineAsync($"Method: {method.DeclaringType?.FullName}.{method.Name}");
+ await writer.WriteLineAsync($"Class: {method.DeclaringType?.FullName}\nMethod: {method.Name}");
+
+ int fileLine = frame.GetFileLineNumber();
+ if (fileLine > 0)
+ {
+ await writer.WriteLineAsync($"Line: {fileLine}");
+ }
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length > 0)
{
- await writer.WriteLineAsync($"Parameters:");
+ await writer.WriteLineAsync("Parameters:");
+
foreach (ParameterInfo param in parameters)
{
- await writer.WriteLineAsync($"{param.Name}: {param.ParameterType}");
+ await writer.WriteLineAsync($" - Name: {param.Name} | Type: {param.ParameterType}");
}
}
}
}
- await writer.WriteLineAsync($"Stack Trace:\n{stackTrace}");
- await writer.WriteLineAsync($"\n{headerLine}\n");
+ await writer.WriteLineAsync($"Stack Trace:\n{currentEx.StackTrace}");
+ await writer.WriteLineAsync($"\n{separator}\n");
currentEx = currentEx.InnerException;
exLevel++;
@@ -95,19 +102,14 @@ namespace GTweak.Utilities.Controls
await writer.FlushAsync();
}
- await EnsureAssociation();
+ await EnsureLogFileAssociation();
if (File.Exists(PathLocator.Files.ErrorLog))
{
try
{
await Task.Delay(50);
-
- Process.Start(new ProcessStartInfo
- {
- FileName = PathLocator.Files.ErrorLog,
- UseShellExecute = true
- });
+ Process.Start(new ProcessStartInfo { FileName = PathLocator.Files.ErrorLog, UseShellExecute = true });
}
catch (Exception processEx) { LogDebug(processEx); }
}
diff --git a/.Source/GTweak/View/AddonsView.xaml.cs b/.Source/GTweak/View/AddonsView.xaml.cs
index 27e1d08b..cbaf98cd 100644
--- a/.Source/GTweak/View/AddonsView.xaml.cs
+++ b/.Source/GTweak/View/AddonsView.xaml.cs
@@ -1,14 +1,12 @@
using System;
-using System.ComponentModel;
using System.Windows.Controls;
+using GTweak.Core.Base;
using GTweak.Core.ViewModel;
using GTweak.Utilities.Managers;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class AddonsView : UserControl
+ public partial class AddonsView : UserControl, IViewPageBase
{
private TimerControlManager _timer = default;
public AddonsView()
diff --git a/.Source/GTweak/View/ConfidentialityView.xaml.cs b/.Source/GTweak/View/ConfidentialityView.xaml.cs
index 35c0d13d..1b7d62d5 100644
--- a/.Source/GTweak/View/ConfidentialityView.xaml.cs
+++ b/.Source/GTweak/View/ConfidentialityView.xaml.cs
@@ -1,16 +1,14 @@
-using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GTweak.Assets.UserControls;
+using GTweak.Core.Base;
using GTweak.Utilities.Managers;
using GTweak.Utilities.Tweaks;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class ConfidentialityView : UserControl
+ public partial class ConfidentialityView : UserControl, IViewPageBase
{
private readonly ConfidentialityTweaks _confTweaks = new ConfidentialityTweaks();
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index 08c038b3..78783745 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -9,6 +8,7 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
+using GTweak.Core.Base;
using GTweak.Core.ViewModel;
using GTweak.Utilities.Animation;
using GTweak.Utilities.Configuration;
@@ -18,9 +18,7 @@ using GTweak.Utilities.Managers;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class DataSystemView : UserControl
+ public partial class DataSystemView : UserControl, IViewPageBase
{
private readonly SystemDataCollector _systemDataCollector = new SystemDataCollector();
private readonly BackgroundQueue backgroundQueue = new BackgroundQueue();
diff --git a/.Source/GTweak/View/InterfaceView.xaml.cs b/.Source/GTweak/View/InterfaceView.xaml.cs
index 9287c0bc..5e79ca98 100644
--- a/.Source/GTweak/View/InterfaceView.xaml.cs
+++ b/.Source/GTweak/View/InterfaceView.xaml.cs
@@ -1,18 +1,16 @@
using System;
-using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GTweak.Assets.UserControls;
+using GTweak.Core.Base;
using GTweak.Utilities.Maintenance;
using GTweak.Utilities.Managers;
using GTweak.Utilities.Tweaks;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class InterfaceView : UserControl
+ public partial class InterfaceView : UserControl, IViewPageBase
{
private readonly InterfaceTweaks _intfTweaks = new InterfaceTweaks();
private ExplorerManager.ExplorerAction _explorerAction = ExplorerManager.ExplorerAction.None;
diff --git a/.Source/GTweak/View/PackagesView.xaml.cs b/.Source/GTweak/View/PackagesView.xaml.cs
index 74f16028..c4cbf316 100644
--- a/.Source/GTweak/View/PackagesView.xaml.cs
+++ b/.Source/GTweak/View/PackagesView.xaml.cs
@@ -4,6 +4,7 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
+using GTweak.Core.Base;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
using GTweak.Utilities.Managers;
@@ -11,9 +12,7 @@ using GTweak.Utilities.Tweaks;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class PackagesView : UserControl
+ public partial class PackagesView : UserControl, IViewPageBase
{
private TimerControlManager _timer = default;
private readonly BackgroundQueue _backgroundQueue = new BackgroundQueue();
diff --git a/.Source/GTweak/View/ServicesView.xaml.cs b/.Source/GTweak/View/ServicesView.xaml.cs
index fcce68f6..931a64c7 100644
--- a/.Source/GTweak/View/ServicesView.xaml.cs
+++ b/.Source/GTweak/View/ServicesView.xaml.cs
@@ -1,16 +1,14 @@
-using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GTweak.Assets.UserControls;
+using GTweak.Core.Base;
using GTweak.Utilities.Managers;
using GTweak.Utilities.Tweaks;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class ServicesView : UserControl
+ public partial class ServicesView : UserControl, IViewPageBase
{
private readonly ServicesTweaks _svcTweaks = new ServicesTweaks();
diff --git a/.Source/GTweak/View/SystemView.xaml.cs b/.Source/GTweak/View/SystemView.xaml.cs
index ee6fae88..0f77b362 100644
--- a/.Source/GTweak/View/SystemView.xaml.cs
+++ b/.Source/GTweak/View/SystemView.xaml.cs
@@ -1,16 +1,14 @@
-using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GTweak.Assets.UserControls;
+using GTweak.Core.Base;
using GTweak.Utilities.Managers;
using GTweak.Utilities.Tweaks;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class SystemView : UserControl
+ public partial class SystemView : UserControl, IViewPageBase
{
private readonly SystemTweaks _sysTweaks = new SystemTweaks();
diff --git a/.Source/GTweak/View/UtilsView.xaml.cs b/.Source/GTweak/View/UtilsView.xaml.cs
index 6c394958..6e1eeec4 100644
--- a/.Source/GTweak/View/UtilsView.xaml.cs
+++ b/.Source/GTweak/View/UtilsView.xaml.cs
@@ -1,7 +1,7 @@
using System;
-using System.ComponentModel;
using System.IO;
using System.Windows.Controls;
+using GTweak.Core.Base;
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
@@ -12,9 +12,7 @@ using Ookii.Dialogs.Wpf;
namespace GTweak.View
{
- [ToolboxItem(false)]
- [DesignTimeVisible(false)]
- public partial class UtilsView : UserControl
+ public partial class UtilsView : UserControl, IViewPageBase
{
private readonly SystemRestoreService _systemRestore = new SystemRestoreService();
private readonly NTFSCompressor _ntfsCompressor = new NTFSCompressor();
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index c1e8ec37..56b0c607 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -49,7 +49,7 @@ namespace GTweak.Windows
static void ExecuteWithLogging(Action action, string member)
{
try { action(); }
- catch (Exception ex) { ErrorLogging.LogWritingFile(ex, member); }
+ catch (Exception ex) { ErrorLogging.LogWritingFile(ex, false, member); }
}
ExecuteWithLogging(TrustedInstaller.StartTrustedInstallerService, nameof(TrustedInstaller.StartTrustedInstallerService));