2022-12-13 01:27:30 +00:00
|
|
|
|
using Avalonia.Controls;
|
2022-12-18 01:28:41 +00:00
|
|
|
|
using LibHac;
|
2022-12-18 21:13:21 +00:00
|
|
|
|
using Ryujinx.Ava.Common;
|
2022-12-13 01:27:30 +00:00
|
|
|
|
using Ryujinx.Ava.Common.Locale;
|
|
|
|
|
using Ryujinx.Ava.Ui.Windows;
|
|
|
|
|
using Ryujinx.Common.Logging;
|
2022-12-18 01:28:41 +00:00
|
|
|
|
using Ryujinx.HLE.FileSystem;
|
2022-12-18 21:13:21 +00:00
|
|
|
|
using Ryujinx.Ui.App.Common;
|
2022-12-13 22:33:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-12-18 21:13:21 +00:00
|
|
|
|
using System.Globalization;
|
2022-12-13 01:27:30 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-12-18 21:13:21 +00:00
|
|
|
|
using UserId = LibHac.Fs.UserId;
|
|
|
|
|
using UserProfile = Ryujinx.Ava.Ui.Models.UserProfile;
|
2022-12-13 01:27:30 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Ava.Ui.Controls
|
|
|
|
|
{
|
2022-12-18 01:28:41 +00:00
|
|
|
|
internal class SaveDataImporter
|
2022-12-13 01:27:30 +00:00
|
|
|
|
{
|
2022-12-18 21:13:21 +00:00
|
|
|
|
private readonly SaveDataFileManager saveDataFileManager;
|
2022-12-13 01:27:30 +00:00
|
|
|
|
|
2022-12-18 21:13:21 +00:00
|
|
|
|
public SaveDataImporter(List<ApplicationData> applications, UserProfile userProfile, HorizonClient horizonClient, VirtualFileSystem virtualFileSystem)
|
2022-12-13 01:27:30 +00:00
|
|
|
|
{
|
2022-12-18 21:13:21 +00:00
|
|
|
|
UserId userId = new UserId(
|
|
|
|
|
ulong.Parse(userProfile.UserId.High.ToString(), NumberStyles.HexNumber),
|
|
|
|
|
ulong.Parse(userProfile.UserId.Low.ToString(), NumberStyles.HexNumber));
|
|
|
|
|
|
|
|
|
|
saveDataFileManager = new SaveDataFileManager(applications, userProfile, horizonClient, virtualFileSystem, userId);
|
2022-12-13 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 01:28:41 +00:00
|
|
|
|
public async void RestoreSavedataBackup(MainWindow mainWindow)
|
2022-12-13 01:27:30 +00:00
|
|
|
|
{
|
2022-12-18 01:28:41 +00:00
|
|
|
|
string[] backupZipFiles = await ShowFolderDialog(mainWindow);
|
2022-12-13 01:27:30 +00:00
|
|
|
|
|
2022-12-18 21:13:21 +00:00
|
|
|
|
//Single because we set AllowMultiple = False in folder dialog options and want only one backup file. => Our export
|
|
|
|
|
saveDataFileManager.RestoreSavedataBackup(backupZipFiles.Single());
|
2022-12-13 01:27:30 +00:00
|
|
|
|
|
2022-12-18 01:28:41 +00:00
|
|
|
|
Logger.Info.Value.Print(LogClass.Application, $"Done extracting savedata backup!", nameof(SaveDataImporter));
|
2022-12-13 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 01:28:41 +00:00
|
|
|
|
private async Task<string[]> ShowFolderDialog(MainWindow mainWindow)
|
2022-12-13 01:27:30 +00:00
|
|
|
|
{
|
|
|
|
|
OpenFileDialog dialog = new()
|
|
|
|
|
{
|
|
|
|
|
Title = LocaleManager.Instance["OpenFileDialogTitle"],
|
|
|
|
|
AllowMultiple = false,
|
2022-12-13 22:33:19 +00:00
|
|
|
|
Filters = new List<FileDialogFilter>(new[] { new FileDialogFilter() { Extensions = new List<string>() { "zip" } } })
|
2022-12-13 01:27:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-12-18 01:28:41 +00:00
|
|
|
|
return await dialog.ShowAsync(mainWindow);
|
2022-12-13 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|