mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-10-11 19:51:04 +02:00
misc: chore: Use explicit types & fix object creation
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public static List<(DownloadableContentModel, bool IsEnabled)> LoadDownloadableContentsJson(VirtualFileSystem vfs, ulong applicationIdBase)
|
||||
{
|
||||
var downloadableContentJsonPath = PathToGameDLCJson(applicationIdBase);
|
||||
string downloadableContentJsonPath = PathToGameDLCJson(applicationIdBase);
|
||||
|
||||
if (!File.Exists(downloadableContentJsonPath))
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
try
|
||||
{
|
||||
var downloadableContentContainerList = JsonHelper.DeserializeFromFile(downloadableContentJsonPath,
|
||||
List<DownloadableContentContainer> downloadableContentContainerList = JsonHelper.DeserializeFromFile(downloadableContentJsonPath,
|
||||
_serializerContext.ListDownloadableContentContainer);
|
||||
return LoadDownloadableContents(vfs, downloadableContentContainerList);
|
||||
}
|
||||
@@ -76,13 +76,13 @@ namespace Ryujinx.UI.Common.Helper
|
||||
downloadableContentContainerList.Add(container);
|
||||
}
|
||||
|
||||
var downloadableContentJsonPath = PathToGameDLCJson(applicationIdBase);
|
||||
string downloadableContentJsonPath = PathToGameDLCJson(applicationIdBase);
|
||||
JsonHelper.SerializeToFile(downloadableContentJsonPath, downloadableContentContainerList, _serializerContext.ListDownloadableContentContainer);
|
||||
}
|
||||
|
||||
private static List<(DownloadableContentModel, bool IsEnabled)> LoadDownloadableContents(VirtualFileSystem vfs, List<DownloadableContentContainer> downloadableContentContainers)
|
||||
{
|
||||
var result = new List<(DownloadableContentModel, bool IsEnabled)>();
|
||||
List<(DownloadableContentModel, bool IsEnabled)> result = new();
|
||||
|
||||
foreach (DownloadableContentContainer downloadableContentContainer in downloadableContentContainers)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
continue;
|
||||
}
|
||||
|
||||
var content = new DownloadableContentModel(nca.Header.TitleId,
|
||||
DownloadableContentModel content = new(nca.Header.TitleId,
|
||||
downloadableContentContainer.ContainerPath,
|
||||
downloadableContentNca.FullPath);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
{
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(@$"Software\Classes\{ext}");
|
||||
|
||||
var openCmd = key?.OpenSubKey(@"shell\open\command");
|
||||
RegistryKey openCmd = key?.OpenSubKey(@"shell\open\command");
|
||||
|
||||
if (openCmd is null)
|
||||
{
|
||||
@@ -143,7 +143,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
}
|
||||
else
|
||||
{
|
||||
using var key = Registry.CurrentUser.CreateSubKey(keyString);
|
||||
using RegistryKey key = Registry.CurrentUser.CreateSubKey(keyString);
|
||||
|
||||
if (key is null)
|
||||
{
|
||||
@@ -151,7 +151,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
}
|
||||
|
||||
Logger.Debug?.Print(LogClass.Application, $"Adding type association {ext}");
|
||||
using var openCmd = key.CreateSubKey(@"shell\open\command");
|
||||
using RegistryKey openCmd = key.CreateSubKey(@"shell\open\command");
|
||||
openCmd?.SetValue("", $"\"{Environment.ProcessPath}\" \"%1\"");
|
||||
Logger.Debug?.Print(LogClass.Application, $"Added type association {ext}");
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var searchPath in pathVar.Split(":", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))
|
||||
foreach (string searchPath in pathVar.Split(":", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
string binaryPath = Path.Combine(searchPath, binary);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
{
|
||||
ObjectiveC.NSString nsStringPath = new(path);
|
||||
ObjectiveC.Object nsUrl = new("NSURL");
|
||||
var urlPtr = nsUrl.GetFromMessage("fileURLWithPath:", nsStringPath);
|
||||
ObjectiveC.Object urlPtr = nsUrl.GetFromMessage("fileURLWithPath:", nsStringPath);
|
||||
|
||||
ObjectiveC.Object nsArray = new("NSArray");
|
||||
ObjectiveC.Object urlArray = nsArray.GetFromMessage("arrayWithObject:", urlPtr);
|
||||
@@ -96,7 +96,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
{
|
||||
ObjectiveC.NSString nsStringPath = new(url);
|
||||
ObjectiveC.Object nsUrl = new("NSURL");
|
||||
var urlPtr = nsUrl.GetFromMessage("URLWithString:", nsStringPath);
|
||||
ObjectiveC.Object urlPtr = nsUrl.GetFromMessage("URLWithString:", nsStringPath);
|
||||
|
||||
ObjectiveC.Object nsWorkspace = new("NSWorkspace");
|
||||
ObjectiveC.Object sharedWorkspace = nsWorkspace.GetFromMessage("sharedWorkspace");
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace Ryujinx.UI.Common.Helper
|
||||
iconPath += ".ico";
|
||||
|
||||
MemoryStream iconDataStream = new(iconData);
|
||||
using var image = SKBitmap.Decode(iconDataStream);
|
||||
using SKBitmap image = SKBitmap.Decode(iconDataStream);
|
||||
image.Resize(new SKImageInfo(128, 128), new SKSamplingOptions(SKFilterMode.Linear));
|
||||
SaveBitmapAsIcon(image, iconPath);
|
||||
|
||||
var shortcut = Shortcut.CreateShortcut(basePath, GetArgsString(applicationFilePath, applicationId), iconPath, 0);
|
||||
Shortcut shortcut = Shortcut.CreateShortcut(basePath, GetArgsString(applicationFilePath, applicationId), iconPath, 0);
|
||||
shortcut.StringData.NameString = cleanedAppName;
|
||||
shortcut.WriteToFile(Path.Combine(desktopPath, cleanedAppName + ".lnk"));
|
||||
}
|
||||
@@ -31,12 +31,12 @@ namespace Ryujinx.UI.Common.Helper
|
||||
private static void CreateShortcutLinux(string applicationFilePath, string applicationId, byte[] iconData, string iconPath, string desktopPath, string cleanedAppName)
|
||||
{
|
||||
string basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx.sh");
|
||||
var desktopFile = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-template.desktop");
|
||||
string desktopFile = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-template.desktop");
|
||||
iconPath += ".png";
|
||||
|
||||
var image = SKBitmap.Decode(iconData);
|
||||
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using var file = File.OpenWrite(iconPath);
|
||||
SKBitmap image = SKBitmap.Decode(iconData);
|
||||
using SKData data = image.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using FileStream file = File.OpenWrite(iconPath);
|
||||
data.SaveTo(file);
|
||||
|
||||
using StreamWriter outputFile = new(Path.Combine(desktopPath, cleanedAppName + ".desktop"));
|
||||
@@ -47,8 +47,8 @@ namespace Ryujinx.UI.Common.Helper
|
||||
private static void CreateShortcutMacos(string appFilePath, string applicationId, byte[] iconData, string desktopPath, string cleanedAppName)
|
||||
{
|
||||
string basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx");
|
||||
var plistFile = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-template.plist");
|
||||
var shortcutScript = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-launch-script.sh");
|
||||
string plistFile = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-template.plist");
|
||||
string shortcutScript = EmbeddedResources.ReadAllText("Ryujinx.UI.Common/shortcut-launch-script.sh");
|
||||
// Macos .App folder
|
||||
string contentFolderPath = Path.Combine("/Applications", cleanedAppName + ".app", "Contents");
|
||||
string scriptFolderPath = Path.Combine(contentFolderPath, "MacOS");
|
||||
@@ -77,9 +77,9 @@ namespace Ryujinx.UI.Common.Helper
|
||||
}
|
||||
|
||||
const string IconName = "icon.png";
|
||||
var image = SKBitmap.Decode(iconData);
|
||||
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using var file = File.OpenWrite(Path.Combine(resourceFolderPath, IconName));
|
||||
SKBitmap image = SKBitmap.Decode(iconData);
|
||||
using SKData data = image.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using FileStream file = File.OpenWrite(Path.Combine(resourceFolderPath, IconName));
|
||||
data.SaveTo(file);
|
||||
|
||||
// plist file
|
||||
@@ -124,7 +124,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
private static string GetArgsString(string appFilePath, string applicationId)
|
||||
{
|
||||
// args are first defined as a list, for easier adjustments in the future
|
||||
var argsList = new List<string>();
|
||||
List<string> argsList = new();
|
||||
|
||||
if (!string.IsNullOrEmpty(CommandLineState.BaseDirPathArg))
|
||||
{
|
||||
@@ -157,7 +157,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
fs.Write(header);
|
||||
// Writing actual data
|
||||
using var data = source.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using SKData data = source.Encode(SKEncodedImageFormat.Png, 100);
|
||||
data.SaveTo(fs);
|
||||
// Getting data length (file length minus header)
|
||||
long dataLength = fs.Length - header.Length;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public static List<(TitleUpdateModel Update, bool IsSelected)> LoadTitleUpdatesJson(VirtualFileSystem vfs, ulong applicationIdBase)
|
||||
{
|
||||
var titleUpdatesJsonPath = PathToGameUpdatesJson(applicationIdBase);
|
||||
string titleUpdatesJsonPath = PathToGameUpdatesJson(applicationIdBase);
|
||||
|
||||
if (!File.Exists(titleUpdatesJsonPath))
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
try
|
||||
{
|
||||
var titleUpdateWindowData = JsonHelper.DeserializeFromFile(titleUpdatesJsonPath, _serializerContext.TitleUpdateMetadata);
|
||||
TitleUpdateMetadata titleUpdateWindowData = JsonHelper.DeserializeFromFile(titleUpdatesJsonPath, _serializerContext.TitleUpdateMetadata);
|
||||
return LoadTitleUpdates(vfs, titleUpdateWindowData, applicationIdBase);
|
||||
}
|
||||
catch
|
||||
@@ -51,7 +51,7 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
public static void SaveTitleUpdatesJson(VirtualFileSystem vfs, ulong applicationIdBase, List<(TitleUpdateModel, bool IsSelected)> updates)
|
||||
{
|
||||
var titleUpdateWindowData = new TitleUpdateMetadata
|
||||
TitleUpdateMetadata titleUpdateWindowData = new()
|
||||
{
|
||||
Selected = "",
|
||||
Paths = [],
|
||||
@@ -73,13 +73,13 @@ namespace Ryujinx.UI.Common.Helper
|
||||
}
|
||||
}
|
||||
|
||||
var titleUpdatesJsonPath = PathToGameUpdatesJson(applicationIdBase);
|
||||
string titleUpdatesJsonPath = PathToGameUpdatesJson(applicationIdBase);
|
||||
JsonHelper.SerializeToFile(titleUpdatesJsonPath, titleUpdateWindowData, _serializerContext.TitleUpdateMetadata);
|
||||
}
|
||||
|
||||
private static List<(TitleUpdateModel Update, bool IsSelected)> LoadTitleUpdates(VirtualFileSystem vfs, TitleUpdateMetadata titleUpdateMetadata, ulong applicationIdBase)
|
||||
{
|
||||
var result = new List<(TitleUpdateModel, bool IsSelected)>();
|
||||
List<(TitleUpdateModel, bool IsSelected)> result = new();
|
||||
|
||||
IntegrityCheckLevel checkLevel = ConfigurationState.Instance.System.EnableFsIntegrityChecks
|
||||
? IntegrityCheckLevel.ErrorOnInvalid
|
||||
@@ -121,8 +121,8 @@ namespace Ryujinx.UI.Common.Helper
|
||||
nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None)
|
||||
.ThrowIfFailure();
|
||||
|
||||
var displayVersion = controlData.DisplayVersionString.ToString();
|
||||
var update = new TitleUpdateModel(content.ApplicationId, content.Version.Version,
|
||||
string displayVersion = controlData.DisplayVersionString.ToString();
|
||||
TitleUpdateModel update = new(content.ApplicationId, content.Version.Version,
|
||||
displayVersion, path);
|
||||
|
||||
result.Add((update, path == titleUpdateMetadata.Selected));
|
||||
|
||||
@@ -140,10 +140,10 @@ namespace Ryujinx.UI.Common.Helper
|
||||
|
||||
// An input string can either look like "01:23:45" or "1d, 01:23:45" if the timespan represents a duration of more than a day.
|
||||
// Here, we split the input string to check if it's the former or the latter.
|
||||
var valueSplit = timeSpanString.Split(", ");
|
||||
string[] valueSplit = timeSpanString.Split(", ");
|
||||
if (valueSplit.Length > 1)
|
||||
{
|
||||
var dayPart = valueSplit[0].Split("d")[0];
|
||||
string dayPart = valueSplit[0].Split("d")[0];
|
||||
if (int.TryParse(dayPart, out int days))
|
||||
{
|
||||
returnTimeSpan = returnTimeSpan.Add(TimeSpan.FromDays(days));
|
||||
|
||||
Reference in New Issue
Block a user