diff --git a/src/Lanceur.SharedKernel/Mixins/UriMixin.cs b/src/Lanceur.SharedKernel/Mixins/UriMixin.cs new file mode 100644 index 00000000..8daf0b95 --- /dev/null +++ b/src/Lanceur.SharedKernel/Mixins/UriMixin.cs @@ -0,0 +1,14 @@ +namespace Lanceur.SharedKernel.Mixins; + +public static class UriMixin +{ + #region Methods + + public static Uri ToUri(this string path, UriKind kind) => new(path, kind); + + public static Uri ToUriAbsolute(this string path) => path.ToUri(UriKind.Absolute); + + public static Uri ToUriRelative(this string path) => path.ToUri(UriKind.Relative); + + #endregion Methods +} \ No newline at end of file diff --git a/src/Lanceur/Assets/IconError.png b/src/Lanceur/Assets/IconError.png new file mode 100644 index 00000000..234385d4 Binary files /dev/null and b/src/Lanceur/Assets/IconError.png differ diff --git a/src/Lanceur/Assets/IconInfo.png b/src/Lanceur/Assets/IconInfo.png new file mode 100644 index 00000000..e281400f Binary files /dev/null and b/src/Lanceur/Assets/IconInfo.png differ diff --git a/src/Lanceur/Assets/IconWarn.png b/src/Lanceur/Assets/IconWarn.png new file mode 100644 index 00000000..e01493e2 Binary files /dev/null and b/src/Lanceur/Assets/IconWarn.png differ diff --git a/src/Lanceur/Lanceur.csproj b/src/Lanceur/Lanceur.csproj index d81a3e67..5a8b3550 100644 --- a/src/Lanceur/Lanceur.csproj +++ b/src/Lanceur/Lanceur.csproj @@ -47,4 +47,18 @@ Settings.Designer.cs + + + + PreserveNewest + + + + PreserveNewest + + + + + + \ No newline at end of file diff --git a/src/Lanceur/Ui/ToastNotification.cs b/src/Lanceur/Ui/ToastNotification.cs index 11f23320..a80ec93a 100644 --- a/src/Lanceur/Ui/ToastNotification.cs +++ b/src/Lanceur/Ui/ToastNotification.cs @@ -1,26 +1,77 @@ -using Microsoft.Toolkit.Uwp.Notifications; +using System.IO; +using System.Reflection; +using Lanceur.SharedKernel.Mixins; +using Microsoft.Toolkit.Uwp.Notifications; using System.Runtime.CompilerServices; +using System.Windows.Shapes; +using FileLocation = System.IO.Path; -namespace Lanceur.Ui +namespace Lanceur.Ui; + +public class ToastNotification : INotification { - public class ToastNotification : INotification + #region Enums + + private enum Level { - #region Methods + Information, + Warning, + Error + }; + + #endregion Enums - private void Show(string message, [CallerMemberName] string title = null) + #region Methods + + private static void Show(Level level, string message, [CallerMemberName] string title = null) + { + var uri = level switch { - new ToastContentBuilder() - .AddText(title) - .AddText(message) - .Show(); + Level.Information => Icon.Info, + Level.Warning => Icon.Warn, + Level.Error => Icon.Error, + _ => Icon.None + }; + new ToastContentBuilder() + .AddText(title) + .AddText(message) + .AddAppLogoOverride(uri.ToUriRelative(), ToastGenericAppLogoCrop.Circle) + .Show(); + } + + public void Error(string message) => Show(Level.Error, message); + + public void Information(string message) => Show(Level.Information, message); + + public void Warning(string message) => Show(Level.Warning, message); + + #endregion Methods + + #region Classes + + private static class Icon + { + #region Constructors + + static Icon() + { + var path = FileLocation.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + Info = FileLocation.Combine(path, @"Assets\IconInfo.png"); + Warn = FileLocation.Combine(path, @"Assets\IconWarn.png"); + Error = FileLocation.Combine(path, @"Assets\IconError.png"); } - public void Error(string message) => Show(message); + #endregion Constructors - public void Information(string message) => Show(message); + #region Properties - public void Warning(string message) => Show(message); + public static string Error { get; } + public static string Info { get; } + public static string Warn { get; } + public static string None => string.Empty; - #endregion Methods - } + #endregion Properties + }; + + #endregion Classes } \ No newline at end of file diff --git a/src/Libraries/System.SQLite.Updater/ScriptManager.cs b/src/Libraries/System.SQLite.Updater/ScriptManager.cs index f60cc85c..c6800da7 100644 --- a/src/Libraries/System.SQLite.Updater/ScriptManager.cs +++ b/src/Libraries/System.SQLite.Updater/ScriptManager.cs @@ -61,12 +61,11 @@ public ScriptCollection GetScripts() { var regex = new Regex(@"^.*?(\d{1,3}\.{0,1}\d{1,3}\.{0,1}\d{0,3}).*"); var match = regex.Matches(item.Key); - if (match.Count > 0 && match[0].Groups.Count >= 1) - { - var ver = match[0].Groups[1].Value.Trim('.'); - var version = new Version(ver); - src.Add(version, item.Value); - } + if (match.Count <= 0 || match[0].Groups.Count < 1) continue; + + var ver = match[0].Groups[1].Value.Trim('.'); + var version = new Version(ver); + src.Add(version, item.Value); } var ordered = src.OrderBy(x => x.Key); return new ScriptCollection(new Dictionary(ordered));