|
|
@@ -26,12 +26,13 @@ using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading;
|
|
|
using Path = System.IO.Path;
|
|
|
+using TimeSpan = System.TimeSpan;
|
|
|
|
|
|
namespace Ryujinx.Ui.App.Common
|
|
|
{
|
|
|
public class ApplicationLibrary
|
|
|
{
|
|
|
- public event EventHandler<ApplicationAddedEventArgs> ApplicationAdded;
|
|
|
+ public event EventHandler<ApplicationAddedEventArgs> ApplicationAdded;
|
|
|
public event EventHandler<ApplicationCountUpdatedEventArgs> ApplicationCountUpdated;
|
|
|
|
|
|
private readonly byte[] _nspIcon;
|
|
|
@@ -41,11 +42,11 @@ namespace Ryujinx.Ui.App.Common
|
|
|
private readonly byte[] _nsoIcon;
|
|
|
|
|
|
private readonly VirtualFileSystem _virtualFileSystem;
|
|
|
- private Language _desiredTitleLanguage;
|
|
|
- private CancellationTokenSource _cancellationToken;
|
|
|
+ private Language _desiredTitleLanguage;
|
|
|
+ private CancellationTokenSource _cancellationToken;
|
|
|
|
|
|
- private static readonly ApplicationJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
|
|
- private static readonly TitleUpdateMetadataJsonSerializerContext TitleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
|
|
+ private static readonly ApplicationJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
|
|
+ private static readonly TitleUpdateMetadataJsonSerializerContext _titleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
|
|
|
|
|
public ApplicationLibrary(VirtualFileSystem virtualFileSystem)
|
|
|
{
|
|
|
@@ -60,7 +61,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
private static byte[] GetResourceBytes(string resourceName)
|
|
|
{
|
|
|
- Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName);
|
|
|
+ Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName);
|
|
|
byte[] resourceByteArray = new byte[resourceStream.Length];
|
|
|
|
|
|
resourceStream.Read(resourceByteArray);
|
|
|
@@ -83,7 +84,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage)
|
|
|
{
|
|
|
- int numApplicationsFound = 0;
|
|
|
+ int numApplicationsFound = 0;
|
|
|
int numApplicationsLoaded = 0;
|
|
|
|
|
|
_desiredTitleLanguage = desiredTitleLanguage;
|
|
|
@@ -114,14 +115,14 @@ namespace Ryujinx.Ui.App.Common
|
|
|
IEnumerable<string> files = Directory.EnumerateFiles(appDir, "*", SearchOption.AllDirectories).Where(file =>
|
|
|
{
|
|
|
return
|
|
|
- (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value) ||
|
|
|
+ (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.Ui.ShownFileTypes.NSP.Value) ||
|
|
|
(Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.Ui.ShownFileTypes.PFS0.Value) ||
|
|
|
- (Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value) ||
|
|
|
- (Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value) ||
|
|
|
- (Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value) ||
|
|
|
- (Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value);
|
|
|
+ (Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.Ui.ShownFileTypes.XCI.Value) ||
|
|
|
+ (Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.Ui.ShownFileTypes.NCA.Value) ||
|
|
|
+ (Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.Ui.ShownFileTypes.NRO.Value) ||
|
|
|
+ (Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.Ui.ShownFileTypes.NSO.Value);
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
foreach (string app in files)
|
|
|
{
|
|
|
if (_cancellationToken.Token.IsCancellationRequested)
|
|
|
@@ -459,27 +460,27 @@ namespace Ryujinx.Ui.App.Common
|
|
|
FileSize = (fileSize < 1) ? (fileSize * 1024).ToString("0.##") + " MiB" : fileSize.ToString("0.##") + " GiB",
|
|
|
FileSizeBytes = fileSize,
|
|
|
Path = applicationPath,
|
|
|
- ControlHolder = controlHolder
|
|
|
+ ControlHolder = controlHolder,
|
|
|
};
|
|
|
|
|
|
numApplicationsLoaded++;
|
|
|
|
|
|
- OnApplicationAdded(new ApplicationAddedEventArgs()
|
|
|
+ OnApplicationAdded(new ApplicationAddedEventArgs
|
|
|
{
|
|
|
- AppData = data
|
|
|
+ AppData = data,
|
|
|
});
|
|
|
|
|
|
- OnApplicationCountUpdated(new ApplicationCountUpdatedEventArgs()
|
|
|
+ OnApplicationCountUpdated(new ApplicationCountUpdatedEventArgs
|
|
|
{
|
|
|
NumAppsFound = numApplicationsFound,
|
|
|
- NumAppsLoaded = numApplicationsLoaded
|
|
|
+ NumAppsLoaded = numApplicationsLoaded,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- OnApplicationCountUpdated(new ApplicationCountUpdatedEventArgs()
|
|
|
+ OnApplicationCountUpdated(new ApplicationCountUpdatedEventArgs
|
|
|
{
|
|
|
NumAppsFound = numApplicationsFound,
|
|
|
- NumAppsLoaded = numApplicationsLoaded
|
|
|
+ NumAppsLoaded = numApplicationsLoaded,
|
|
|
});
|
|
|
}
|
|
|
finally
|
|
|
@@ -505,13 +506,13 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
// Return the ControlFS
|
|
|
controlFs = controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
|
|
|
- titleId = controlNca?.Header.TitleId.ToString("x16");
|
|
|
+ titleId = controlNca?.Header.TitleId.ToString("x16");
|
|
|
}
|
|
|
|
|
|
- public ApplicationMetadata LoadAndSaveMetaData(string titleId, Action<ApplicationMetadata> modifyFunction = null)
|
|
|
+ public static ApplicationMetadata LoadAndSaveMetaData(string titleId, Action<ApplicationMetadata> modifyFunction = null)
|
|
|
{
|
|
|
string metadataFolder = Path.Combine(AppDataManager.GamesDirPath, titleId, "gui");
|
|
|
- string metadataFile = Path.Combine(metadataFolder, "metadata.json");
|
|
|
+ string metadataFile = Path.Combine(metadataFolder, "metadata.json");
|
|
|
|
|
|
ApplicationMetadata appMetadata;
|
|
|
|
|
|
@@ -521,12 +522,12 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
appMetadata = new ApplicationMetadata();
|
|
|
|
|
|
- JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata);
|
|
|
+ JsonHelper.SerializeToFile(metadataFile, appMetadata, _serializerContext.ApplicationMetadata);
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- appMetadata = JsonHelper.DeserializeFromFile(metadataFile, SerializerContext.ApplicationMetadata);
|
|
|
+ appMetadata = JsonHelper.DeserializeFromFile(metadataFile, _serializerContext.ApplicationMetadata);
|
|
|
}
|
|
|
catch (JsonException)
|
|
|
{
|
|
|
@@ -539,7 +540,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
{
|
|
|
modifyFunction(appMetadata);
|
|
|
|
|
|
- JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata);
|
|
|
+ JsonHelper.SerializeToFile(metadataFile, appMetadata, _serializerContext.ApplicationMetadata);
|
|
|
}
|
|
|
|
|
|
return appMetadata;
|
|
|
@@ -703,7 +704,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- catch(Exception)
|
|
|
+ catch (Exception)
|
|
|
{
|
|
|
Logger.Warning?.Print(LogClass.Application, $"Could not retrieve a valid icon for the app. Default icon will be used. Errored File: {applicationPath}");
|
|
|
}
|
|
|
@@ -713,7 +714,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
private static string ConvertSecondsToFormattedString(double seconds)
|
|
|
{
|
|
|
- System.TimeSpan time = System.TimeSpan.FromSeconds(seconds);
|
|
|
+ TimeSpan time = TimeSpan.FromSeconds(seconds);
|
|
|
|
|
|
string timeString;
|
|
|
if (time.Days != 0)
|
|
|
@@ -840,7 +841,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
|
|
|
|
|
|
- Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage());
|
|
|
+ Nca nca = new(fileSystem.KeySet, ncaFile.Release().AsStorage());
|
|
|
|
|
|
int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
|
|
|
|
|
|
@@ -884,7 +885,7 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
|
|
|
|
|
|
- Nca nca = new Nca(fileSystem.KeySet, ncaFile.Release().AsStorage());
|
|
|
+ Nca nca = new(fileSystem.KeySet, ncaFile.Release().AsStorage());
|
|
|
|
|
|
int ncaProgramIndex = (int)(nca.Header.TitleId & 0xF);
|
|
|
|
|
|
@@ -925,12 +926,12 @@ namespace Ryujinx.Ui.App.Common
|
|
|
|
|
|
if (File.Exists(titleUpdateMetadataPath))
|
|
|
{
|
|
|
- updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, TitleSerializerContext.TitleUpdateMetadata).Selected;
|
|
|
+ updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, _titleSerializerContext.TitleUpdateMetadata).Selected;
|
|
|
|
|
|
if (File.Exists(updatePath))
|
|
|
{
|
|
|
- FileStream file = new FileStream(updatePath, FileMode.Open, FileAccess.Read);
|
|
|
- PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
|
|
|
+ FileStream file = new(updatePath, FileMode.Open, FileAccess.Read);
|
|
|
+ PartitionFileSystem nsp = new(file.AsStorage());
|
|
|
|
|
|
return GetGameUpdateDataFromPartition(fileSystem, nsp, titleIdBase.ToString("x16"), programIndex);
|
|
|
}
|
|
|
@@ -941,4 +942,3 @@ namespace Ryujinx.Ui.App.Common
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|