Skip to content

Commit a8f269e

Browse files
committed
Added logs for snackbar updates
1 parent 6aaee4c commit a8f269e

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

CompactGUI.Core/Compactor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public class Compactor : ICompressor, IDisposable
2727
public Compactor(string folderPath, WOFCompressionAlgorithm compressionLevel, string[] excludedFileTypes)
2828
{
2929
workingDirectory = folderPath;
30-
excludedFileExtensions = new HashSet<string>(excludedFileTypes);
30+
excludedFileExtensions = new HashSet<string>(excludedFileTypes).MyTag();
31+
32+
int sum = 1 + 2.MyTag();
3133
wofCompressionAlgorithm = compressionLevel;
3234

3335
InitializeCompressionInfoPointer();
@@ -156,3 +158,8 @@ public void Dispose()
156158

157159

158160
}
161+
162+
public static class MyTagExtensions
163+
{
164+
public static T MyTag<T>(this T obj) => obj;
165+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace CompactGUI.Logging;
4+
5+
public static partial class SnackbarServiceLog
6+
{
7+
8+
[LoggerMessage(Level = LogLevel.Warning, Message = "Invalid Folder {FolderName}: {message}")]
9+
public static partial void ShowInvalidFoldersMessage(ILogger logger, string FolderName, string message);
10+
11+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing insufficient permission snackbar for folder: {FolderName}")]
12+
public static partial void ShowInsufficientPermission(ILogger logger, string folderName);
13+
14+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing update available snackbar for version: {NewVersion}, pre-release: {IsPreRelease}")]
15+
public static partial void ShowUpdateAvailable(ILogger logger, string newVersion, bool isPreRelease);
16+
17+
[LoggerMessage(Level = LogLevel.Warning, Message = "Showing failed to submit to wiki snackbar.")]
18+
public static partial void ShowFailedToSubmitToWiki(ILogger logger);
19+
20+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing submitted to wiki snackbar for UID: {UID}, Game: {GameName}, SteamID: {SteamID}, Compression: {CompressionMode}")]
21+
public static partial void ShowSubmittedToWiki(ILogger logger, string UID, string GameName, string SteamID, string CompressionMode);
22+
23+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing applied to all folders snackbar.")]
24+
public static partial void ShowAppliedToAllFolders(ILogger logger);
25+
26+
[LoggerMessage(Level = LogLevel.Warning, Message = "Showing cannot remove folder snackbar.")]
27+
public static partial void ShowCannotRemoveFolder(ILogger logger);
28+
29+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing added to queue snackbar.")]
30+
public static partial void ShowAddedToQueue(ILogger logger);
31+
32+
[LoggerMessage(Level = LogLevel.Information, Message = "Showing DirectStorage warning for: {DisplayName}")]
33+
public static partial void ShowDirectStorageWarning(ILogger logger, string displayName);
34+
35+
}

CompactGUI/Services/CustomSnackBarService.vb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
Imports CommunityToolkit.Mvvm.Input
22

33
Imports CompactGUI.Core.SharedMethods
4+
Imports CompactGUI.Logging
5+
6+
Imports Microsoft.Extensions.Logging
47

58
Imports Wpf.Ui.Controls
69

710
Public Class CustomSnackBarService
811
Inherits Wpf.Ui.SnackbarService
912

13+
Private ReadOnly logger As ILogger(Of CustomSnackBarService)
1014
Public _snackbar As Snackbar
1115

16+
Public Sub New(logger As ILogger(Of CustomSnackBarService))
17+
MyBase.New()
18+
Me.logger = logger
19+
End Sub
20+
1221
Public Sub ShowCustom(message As UIElement, title As String, appearance As ControlAppearance, Optional icon As IconElement = Nothing, Optional timeout As TimeSpan = Nothing)
1322

1423
If GetSnackbarPresenter() Is Nothing Then Throw New InvalidOperationException("The SnackbarPresenter was never set")
@@ -29,11 +38,11 @@ Public Class CustomSnackBarService
2938

3039
Dim messageString = ""
3140
For i = 0 To InvalidFolders.Count - 1
32-
If InvalidMessages(i) = FolderVerificationResult.InsufficientPermission Then
41+
SnackbarServiceLog.ShowInvalidFoldersMessage(logger, InvalidFolders(i), GetFolderVerificationMessage(InvalidMessages(i)))
42+
If InvalidFolders.Count = 1 AndAlso InvalidMessages(i) = FolderVerificationResult.InsufficientPermission Then
3343
ShowInsufficientPermission(InvalidFolders(i))
3444
Return
3545
End If
36-
3746
messageString &= $"{InvalidFolders(i)}: {GetFolderVerificationMessage(InvalidMessages(i))}" & vbCrLf
3847
Next
3948

@@ -55,6 +64,7 @@ Public Class CustomSnackBarService
5564
textBlock.Text = "Click to download"
5665

5766
' Show the custom snackbar
67+
SnackbarServiceLog.ShowUpdateAvailable(logger, newVersion, isPreRelease)
5868
ShowCustom(textBlock, $"Update Available ▸ Version {newVersion}", If(isPreRelease, ControlAppearance.Info, ControlAppearance.Success), timeout:=TimeSpan.FromSeconds(10))
5969

6070
Dim handler As MouseButtonEventHandler = Nothing
@@ -77,23 +87,28 @@ Public Class CustomSnackBarService
7787

7888
Public Sub ShowFailedToSubmitToWiki()
7989
Show("Failed to submit to wiki", "Please check your internet connection and try again", Wpf.Ui.Controls.ControlAppearance.Danger, Nothing, TimeSpan.FromSeconds(5))
90+
SnackbarServiceLog.ShowFailedToSubmitToWiki(logger)
8091
End Sub
8192

8293
Public Sub ShowSubmittedToWiki(steamsubmitdata As SteamSubmissionData, compressionMode As Integer)
8394
Show("Submitted to wiki", $"UID: {steamsubmitdata.UID}{vbCrLf}Game: {steamsubmitdata.GameName}{vbCrLf}SteamID: {steamsubmitdata.SteamID}{vbCrLf}Compression: {[Enum].GetName(GetType(Core.WOFCompressionAlgorithm), Core.WOFHelper.WOFConvertCompressionLevel(compressionMode))}", Wpf.Ui.Controls.ControlAppearance.Success, Nothing, TimeSpan.FromSeconds(10))
95+
SnackbarServiceLog.ShowSubmittedToWiki(logger, steamsubmitdata.UID, steamsubmitdata.GameName, steamsubmitdata.SteamID, steamsubmitdata.CompressionMode)
8496
End Sub
8597

8698

8799
Public Sub ShowAppliedToAllFolders()
88100
Show("Applied to all folders", "Compression options have been applied to all folders", Wpf.Ui.Controls.ControlAppearance.Success, Nothing, TimeSpan.FromSeconds(5))
101+
SnackbarServiceLog.ShowAppliedToAllFolders(logger)
89102
End Sub
90103

91104
Public Sub ShowCannotRemoveFolder()
92105
Show("Cannot remove folder", "Please wait until the current operation is finished", Wpf.Ui.Controls.ControlAppearance.Caution, Nothing, TimeSpan.FromSeconds(5))
106+
SnackbarServiceLog.ShowCannotRemoveFolder(logger)
93107
End Sub
94108

95109
Public Sub ShowAddedToQueue()
96110
Show("Success", "Added to Queue", Wpf.Ui.Controls.ControlAppearance.Success, Nothing, TimeSpan.FromSeconds(5))
111+
SnackbarServiceLog.ShowAddedToQueue(logger)
97112
End Sub
98113

99114
Public Sub ShowDirectStorageWarning(displayName As String)
@@ -102,6 +117,6 @@ Public Class CustomSnackBarService
102117
Wpf.Ui.Controls.ControlAppearance.Info,
103118
Nothing,
104119
TimeSpan.FromSeconds(20))
105-
120+
SnackbarServiceLog.ShowDirectStorageWarning(logger, displayName)
106121
End Sub
107122
End Class

0 commit comments

Comments
 (0)