mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-06-26 22:29:04 +00:00
I fixed the remaining Linux file picker issues after testing on Steam Deck. User profile images, mod manager, title manager, and DLC directory were still using the old file picker methods and not the helper methods. I could only apply the helper method to user profiles, but I came up with a workaround for the others. The reason for the draft PR: I'd ideally like to fix the other three at the helper level, so maybe @greem can help with that since since he wrote the initial implementation. Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/24
121 lines
4.1 KiB
C#
121 lines
4.1 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Platform.Storage;
|
|
using Avalonia.VisualTree;
|
|
using FluentAvalonia.UI.Controls;
|
|
using FluentAvalonia.UI.Navigation;
|
|
using Gommon;
|
|
using Ryujinx.Ava.Common.Locale;
|
|
using Ryujinx.Ava.UI.Controls;
|
|
using Ryujinx.Ava.UI.Models;
|
|
using Ryujinx.Ava.UI.ViewModels;
|
|
using Ryujinx.Ava.Utilities;
|
|
using Ryujinx.HLE.FileSystem;
|
|
using SkiaSharp;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Ryujinx.Ava.UI.Views.User
|
|
{
|
|
public partial class UserProfileImageSelectorView : RyujinxControl<UserProfileImageSelectorViewModel>
|
|
{
|
|
private ContentManager _contentManager;
|
|
private NavigationDialogHost _parent;
|
|
private TempProfile _profile;
|
|
|
|
public UserProfileImageSelectorView()
|
|
{
|
|
InitializeComponent();
|
|
AddHandler(Frame.NavigatedToEvent, (s, e) =>
|
|
{
|
|
NavigatedTo(e);
|
|
}, RoutingStrategies.Direct);
|
|
}
|
|
|
|
private void NavigatedTo(NavigationEventArgs arg)
|
|
{
|
|
if (Program.PreviewerDetached)
|
|
{
|
|
switch (arg.NavigationMode)
|
|
{
|
|
case NavigationMode.New:
|
|
(_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
|
|
_contentManager = _parent.ContentManager;
|
|
|
|
((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.ProfileImageSelectionHeader]}";
|
|
|
|
if (Program.PreviewerDetached)
|
|
{
|
|
DataContext = ViewModel = new UserProfileImageSelectorViewModel();
|
|
ViewModel.FirmwareFound = _contentManager.GetCurrentFirmwareVersion() != null;
|
|
}
|
|
|
|
break;
|
|
case NavigationMode.Back:
|
|
if (_profile.Image != null)
|
|
{
|
|
_parent.GoBack();
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private async void Import_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Optional<IStorageFile> result = await ((Window)this.GetVisualRoot()!).StorageProvider.OpenSingleFilePickerAsync(new FilePickerOpenOptions
|
|
{
|
|
AllowMultiple = false,
|
|
FileTypeFilter = new List<FilePickerFileType>
|
|
{
|
|
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
|
|
{
|
|
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
|
|
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
|
|
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
|
|
},
|
|
},
|
|
});
|
|
|
|
if (result.HasValue)
|
|
{
|
|
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result.Value.Path.LocalPath));
|
|
_parent.GoBack();
|
|
}
|
|
}
|
|
|
|
private void GoBack(object sender, RoutedEventArgs e)
|
|
{
|
|
_parent.GoBack();
|
|
}
|
|
|
|
private void SelectFirmwareImage_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ViewModel.FirmwareFound)
|
|
{
|
|
_parent.Navigate(typeof(UserFirmwareAvatarSelectorView), (_parent, _profile));
|
|
}
|
|
}
|
|
|
|
private static byte[] ProcessProfileImage(byte[] buffer)
|
|
{
|
|
using SKBitmap bitmap = SKBitmap.Decode(buffer);
|
|
|
|
SKBitmap resizedBitmap = bitmap.Resize(new SKImageInfo(256, 256), SKFilterQuality.High);
|
|
|
|
using MemoryStream streamJpg = new();
|
|
|
|
if (resizedBitmap != null)
|
|
{
|
|
using SKImage image = SKImage.FromBitmap(resizedBitmap);
|
|
using SKData dataJpeg = image.Encode(SKEncodedImageFormat.Jpeg, 100);
|
|
|
|
dataJpeg.SaveTo(streamJpg);
|
|
}
|
|
|
|
return streamJpg.ToArray();
|
|
}
|
|
}
|
|
}
|