Skip to content

Commit

Permalink
Major Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Nov 5, 2024
1 parent fc4710b commit 4a89ae3
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 68 deletions.
52 changes: 31 additions & 21 deletions src/Portal/Sucrose.Portal/Extension/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BitmapImage Load(string ImagePath, bool Decode = true, int Width = 360)

if (!SPMI.ImageStream.ContainsKey(ImagePath))
{
SPMI.ImageStream[ImagePath] = new(ImagePath, FileMode.Open, FileAccess.Read);
SPMI.ImageStream[ImagePath] = new(ImagePath, FileMode.Open, FileAccess.Read, FileShare.Read);
}

SPMI.Images[ImagePath].BeginInit();
Expand All @@ -38,6 +38,7 @@ public BitmapImage Load(string ImagePath, bool Decode = true, int Width = 360)
}

SPMI.Images[ImagePath].EndInit();
SPMI.Images[ImagePath].Freeze();
}

return SPMI.Images[ImagePath];
Expand All @@ -52,7 +53,7 @@ public BitmapImage LoadOptimal(string ImagePath, bool Decode = true, int Width =
{
BitmapImage Image = new();

using FileStream Stream = new(ImagePath, FileMode.Open, FileAccess.Read);
using FileStream Stream = new(ImagePath, FileMode.Open, FileAccess.Read, FileShare.Read);

Image.BeginInit();

Expand All @@ -71,14 +72,6 @@ public BitmapImage LoadOptimal(string ImagePath, bool Decode = true, int Width =

Image.Freeze();

Image.StreamSource.Flush();

Stream.Flush();
Stream.Close();
Stream.Dispose();

Dispose();

return Image;
}

Expand All @@ -91,8 +84,17 @@ public void Remove(string ImagePath)
{
if (!string.IsNullOrEmpty(ImagePath))
{
SPMI.Images.Remove(ImagePath);
SPMI.ImageStream.Remove(ImagePath);
if (SPMI.Images.ContainsKey(ImagePath))
{
SPMI.Images[ImagePath].StreamSource?.Dispose();
SPMI.Images.Remove(ImagePath);
}

if (SPMI.ImageStream.ContainsKey(ImagePath))
{
SPMI.ImageStream[ImagePath].Dispose();
SPMI.ImageStream.Remove(ImagePath);
}
}
}

Expand All @@ -103,8 +105,19 @@ public async Task RemoveAsync(string ImagePath)

public void Clear()
{
SPMI.Images.Clear();
foreach (FileStream Stream in SPMI.ImageStream.Values)
{
Stream.Dispose();
}

SPMI.ImageStream.Clear();

foreach (BitmapImage Image in SPMI.Images.Values)
{
Image.StreamSource?.Dispose();
}

SPMI.Images.Clear();
}

public async Task ClearAsync()
Expand All @@ -114,19 +127,16 @@ public async Task ClearAsync()

public void Dispose()
{
if (!string.IsNullOrEmpty(ImagePath))
{
SPMI.ImageStream[ImagePath].Dispose();
SPMI.Images[ImagePath].StreamSource.Dispose();
}
Clear();

GC.Collect();
GC.SuppressFinalize(this);
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
await Task.Run(Dispose);
await ClearAsync();

GC.SuppressFinalize(this);
}
}
}
10 changes: 9 additions & 1 deletion src/Portal/Sucrose.Portal/Views/Controls/LibraryCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using SSSHP = Sucrose.Shared.Space.Helper.Processor;
using SSSMI = Sucrose.Shared.Space.Manage.Internal;
using SSTHI = Sucrose.Shared.Theme.Helper.Info;
using SSWEW = Sucrose.Shared.Watchdog.Extension.Watch;
using SXAGAB = Sucrose.XamlAnimatedGif.AnimationBehavior;

namespace Sucrose.Portal.Views.Controls
Expand Down Expand Up @@ -414,7 +415,14 @@ await Application.Current.Dispatcher.InvokeAsync(async () =>

if (File.Exists(ImagePath))
{
Imagine.Source = await Loader.LoadOptimalAsync(ImagePath);
try
{
Imagine.Source = await Loader.LoadOptimalAsync(ImagePath);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}
}

await Task.Delay(100);
Expand Down
11 changes: 9 additions & 2 deletions src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public partial class StoreCard : UserControl, IDisposable
private readonly string Agent;
private readonly string Guid;
private readonly string Key;
private SSTHI Info;
private bool State;
private SSTHI Info;
private bool Error;

internal StoreCard(string Theme, KeyValuePair<string, SSSIW> Wallpaper, string Agent, string Key)
Expand Down Expand Up @@ -466,7 +466,14 @@ private async void StoreCard_Loaded(object sender, RoutedEventArgs e)

if (File.Exists(ImagePath))
{
Imagine.Source = await Loader.LoadOptimalAsync(ImagePath);
try
{
Imagine.Source = await Loader.LoadOptimalAsync(ImagePath);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}
}

if (Info.AppVersion.CompareTo(SHV.Entry()) > 0)
Expand Down
45 changes: 41 additions & 4 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeCreate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using SSSHC = Sucrose.Shared.Space.Helper.Copy;
using SSTHI = Sucrose.Shared.Theme.Helper.Info;
using SSTHV = Sucrose.Shared.Theme.Helper.Various;
using SSWEW = Sucrose.Shared.Watchdog.Extension.Watch;

namespace Sucrose.Portal.Views.Controls
{
Expand Down Expand Up @@ -159,7 +160,16 @@ private async void GifArea_Drop(object sender, DragEventArgs e)
{
GifDescription.Text = SPETC.GetDescription(Path.GetFileNameWithoutExtension(Record), SSDEWT.Gif);
GifTitle.Text = SPETC.GetTitle(Path.GetFileNameWithoutExtension(Record));
GifImagine.Source = await Loader.LoadAsync(Record);

try
{
GifImagine.Source = await Loader.LoadAsync(Record);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}

GifDelete.Visibility = Visibility.Visible;
GifIcon.Visibility = Visibility.Collapsed;
GifText.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -237,7 +247,16 @@ private async void VideoArea_Drop(object sender, DragEventArgs e)
{
VideoDescription.Text = SPETC.GetDescription(Path.GetFileNameWithoutExtension(Record), SSDEWT.Video);
VideoTitle.Text = SPETC.GetTitle(Path.GetFileNameWithoutExtension(Record));
VideoImagine.Source = await Loader.LoadAsync(Record);

try
{
VideoImagine.Source = await Loader.LoadAsync(Record);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}

VideoDelete.Visibility = Visibility.Visible;
VideoIcon.Visibility = Visibility.Collapsed;
VideoText.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -532,7 +551,16 @@ private async void GifArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs
{
GifDescription.Text = SPETC.GetDescription(Path.GetFileNameWithoutExtension(FileDialog.FileName), SSDEWT.Gif);
GifTitle.Text = SPETC.GetTitle(Path.GetFileNameWithoutExtension(FileDialog.FileName));
GifImagine.Source = await Loader.LoadAsync(FileDialog.FileName);

try
{
GifImagine.Source = await Loader.LoadAsync(FileDialog.FileName);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}

GifDelete.Visibility = Visibility.Visible;
GifIcon.Visibility = Visibility.Collapsed;
GifText.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -572,7 +600,16 @@ private async void VideoArea_MouseLeftButtonUp(object sender, MouseButtonEventAr
{
VideoDescription.Text = SPETC.GetDescription(Path.GetFileNameWithoutExtension(FileDialog.FileName), SSDEWT.Video);
VideoTitle.Text = SPETC.GetTitle(Path.GetFileNameWithoutExtension(FileDialog.FileName));
VideoImagine.Source = await Loader.LoadAsync(FileDialog.FileName);

try
{
VideoImagine.Source = await Loader.LoadAsync(FileDialog.FileName);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}

VideoDelete.Visibility = Visibility.Visible;
VideoIcon.Visibility = Visibility.Collapsed;
VideoText.Visibility = Visibility.Collapsed;
Expand Down
12 changes: 10 additions & 2 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeDelete.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SSSHT = Sucrose.Shared.Space.Helper.Tags;
using SSSSS = Skylark.Struct.Storage.StorageStruct;
using SSTHI = Sucrose.Shared.Theme.Helper.Info;
using SSWEW = Sucrose.Shared.Watchdog.Extension.Watch;

namespace Sucrose.Portal.Views.Controls
{
Expand All @@ -41,7 +42,7 @@ private string Size(string Path)
return $"{SHN.Numeral(Data.Value, true, true, 1, '0', SECNT.None)} {Data.Short}";
}

private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
private async void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
ThemeTitle.Text = Info.Title;
ThemeDescription.Text = Info.Description;
Expand All @@ -68,7 +69,14 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e)

if (File.Exists(ImagePath))
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath, true, 600);
try
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath, true, 600);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}
}
}

Expand Down
28 changes: 18 additions & 10 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeEdit.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SSSHV = Sucrose.Shared.Space.Helper.Versionly;
using SSTHI = Sucrose.Shared.Theme.Helper.Info;
using SSTHV = Sucrose.Shared.Theme.Helper.Various;
using SSWEW = Sucrose.Shared.Watchdog.Extension.Watch;

namespace Sucrose.Portal.Views.Controls
{
Expand All @@ -27,7 +28,15 @@ public ThemeEdit() : base(SPMI.ContentDialogService.GetDialogHost())
InitializeComponent();
}

private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
private void ContentDialog_PreviewKeyDown(object sender, KeyEventArgs e)
{
if ((e.Key == Key.Enter || e.Key == Key.Escape) && (ThemeTitle.IsFocused || ThemeAuthor.IsFocused || ThemeContact.IsFocused || ThemeArguments.IsFocused || ThemeDescription.IsFocused))
{
e.Handled = true;
}
}

private async void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
ThemeTitle.Text = Info.Title;
ThemeAuthor.Text = Info.Author;
Expand All @@ -45,15 +54,14 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e)

if (File.Exists(ImagePath))
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath, true, 600);
}
}

private void ContentDialog_PreviewKeyDown(object sender, KeyEventArgs e)
{
if ((e.Key == Key.Enter || e.Key == Key.Escape) && (ThemeTitle.IsFocused || ThemeAuthor.IsFocused || ThemeContact.IsFocused || ThemeArguments.IsFocused || ThemeDescription.IsFocused))
{
e.Handled = true;
try
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath, true, 600);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}
}
}

Expand Down
33 changes: 21 additions & 12 deletions src/Portal/Sucrose.Portal/Views/Controls/ThemeReport.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -25,6 +26,7 @@
using SSSPMI = Sucrose.Shared.Space.Manage.Internal;
using SSTHI = Sucrose.Shared.Theme.Helper.Info;
using SSTHV = Sucrose.Shared.Theme.Helper.Various;
using SSWEW = Sucrose.Shared.Watchdog.Extension.Watch;
using TextBlock = Wpf.Ui.Controls.TextBlock;
using TextBox = Wpf.Ui.Controls.TextBox;

Expand All @@ -46,13 +48,28 @@ public ThemeReport() : base(SPMI.ContentDialogService.GetDialogHost())
InitializeComponent();
}

private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
private void ContentDialog_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key is Key.Enter or Key.Escape)
{
e.Handled = true;
}
}

private async void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
string ImagePath = Path.Combine(Theme, Info.Thumbnail);

if (File.Exists(ImagePath))
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath);
try
{
ThemeThumbnail.Source = Loader.LoadOptimal(ImagePath);
}
catch (Exception Exception)
{
await SSWEW.Watch_CatchException(Exception);
}
}

ThemeTitle.Text = Info.Title;
Expand Down Expand Up @@ -197,7 +214,7 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e)

HttpResponseMessage Response = new()
{
StatusCode = System.Net.HttpStatusCode.BadGateway
StatusCode = HttpStatusCode.BadGateway
};

Client.DefaultRequestHeaders.Add("User-Agent", SMMG.UserAgent);
Expand Down Expand Up @@ -225,7 +242,7 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e)

Response = new()
{
StatusCode = System.Net.HttpStatusCode.BadGateway
StatusCode = HttpStatusCode.BadGateway
};

try
Expand Down Expand Up @@ -282,14 +299,6 @@ private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
};
}

private void ContentDialog_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key is Key.Enter or Key.Escape)
{
e.Handled = true;
}
}

protected override void OnButtonClick(ContentDialogButton Button)
{
if (!ReporterReport.IsEnabled)
Expand Down
Loading

0 comments on commit 4a89ae3

Please sign in to comment.