2022-07-08 20:47:11 +02:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Interactivity;
|
2022-07-24 19:38:38 +02:00
|
|
|
using Avalonia.VisualTree;
|
|
|
|
using FluentAvalonia.UI.Controls;
|
|
|
|
using FluentAvalonia.UI.Navigation;
|
2022-07-08 20:47:11 +02:00
|
|
|
using Ryujinx.Ava.Common.Locale;
|
2022-12-29 15:24:05 +01:00
|
|
|
using Ryujinx.Ava.UI.Models;
|
|
|
|
using Ryujinx.Ava.UI.Windows;
|
2022-07-08 20:47:11 +02:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
using SixLabors.ImageSharp.Processing;
|
|
|
|
using System.IO;
|
|
|
|
using Image = SixLabors.ImageSharp.Image;
|
|
|
|
|
2022-12-29 15:24:05 +01:00
|
|
|
namespace Ryujinx.Ava.UI.Controls
|
2022-07-08 20:47:11 +02:00
|
|
|
{
|
2022-07-24 19:38:38 +02:00
|
|
|
public partial class ProfileImageSelectionDialog : UserControl
|
2022-07-08 20:47:11 +02:00
|
|
|
{
|
2022-07-24 19:38:38 +02:00
|
|
|
private ContentManager _contentManager;
|
|
|
|
private NavigationDialogHost _parent;
|
|
|
|
private TempProfile _profile;
|
2022-07-08 20:47:11 +02:00
|
|
|
|
|
|
|
public bool FirmwareFound => _contentManager.GetCurrentFirmwareVersion() != null;
|
|
|
|
|
|
|
|
public ProfileImageSelectionDialog()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2022-07-24 19:38:38 +02:00
|
|
|
AddHandler(Frame.NavigatedToEvent, (s, e) =>
|
|
|
|
{
|
|
|
|
NavigatedTo(e);
|
|
|
|
}, RoutingStrategies.Direct);
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
private void NavigatedTo(NavigationEventArgs arg)
|
2022-07-08 20:47:11 +02:00
|
|
|
{
|
2022-07-24 19:38:38 +02:00
|
|
|
if (Program.PreviewerDetached)
|
|
|
|
{
|
|
|
|
switch (arg.NavigationMode)
|
|
|
|
{
|
|
|
|
case NavigationMode.New:
|
|
|
|
(_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
|
|
|
|
_contentManager = _parent.ContentManager;
|
|
|
|
break;
|
|
|
|
case NavigationMode.Back:
|
|
|
|
_parent.GoBack();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataContext = this;
|
|
|
|
}
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private async void Import_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
OpenFileDialog dialog = new();
|
|
|
|
dialog.Filters.Add(new FileDialogFilter
|
|
|
|
{
|
|
|
|
Name = LocaleManager.Instance["AllSupportedFormats"],
|
|
|
|
Extensions = { "jpg", "jpeg", "png", "bmp" }
|
|
|
|
});
|
|
|
|
dialog.Filters.Add(new FileDialogFilter { Name = "JPEG", Extensions = { "jpg", "jpeg" } });
|
|
|
|
dialog.Filters.Add(new FileDialogFilter { Name = "PNG", Extensions = { "png" } });
|
|
|
|
dialog.Filters.Add(new FileDialogFilter { Name = "BMP", Extensions = { "bmp" } });
|
|
|
|
|
|
|
|
dialog.AllowMultiple = false;
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
string[] image = await dialog.ShowAsync(((TopLevel)_parent.GetVisualRoot()) as Window);
|
2022-07-08 20:47:11 +02:00
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
if (image.Length > 0)
|
|
|
|
{
|
|
|
|
string imageFile = image[0];
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
_profile.Image = ProcessProfileImage(File.ReadAllBytes(imageFile));
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
_parent.GoBack();
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
private void SelectFirmwareImage_OnClick(object sender, RoutedEventArgs e)
|
2022-07-08 20:47:11 +02:00
|
|
|
{
|
|
|
|
if (FirmwareFound)
|
|
|
|
{
|
2022-07-24 19:38:38 +02:00
|
|
|
_parent.Navigate(typeof(AvatarWindow), (_parent, _profile));
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
private static byte[] ProcessProfileImage(byte[] buffer)
|
2022-07-08 20:47:11 +02:00
|
|
|
{
|
|
|
|
using (Image image = Image.Load(buffer))
|
|
|
|
{
|
|
|
|
image.Mutate(x => x.Resize(256, 256));
|
|
|
|
|
|
|
|
using (MemoryStream streamJpg = new())
|
|
|
|
{
|
|
|
|
image.SaveAsJpeg(streamJpg);
|
|
|
|
|
2022-07-24 19:38:38 +02:00
|
|
|
return streamJpg.ToArray();
|
2022-07-08 20:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|