[Ryujinx] Address dotnet-format issues (#5395)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA2208 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address dotnet format CA1822 warnings

* Make dotnet format succeed in style mode

* Address dotnet format CA2208 warnings properly

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Format if-blocks correctly

* Another rebase, another dotnet format run

* Run dotnet format whitespace after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Fix build issues

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Second dotnet format pass

* Update src/Ryujinx/Modules/Updater/Updater.cs

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Add trailing commas and improve formatting

* Fix formatting and naming issues

* Rename nvStutterWorkaround to nvidiaStutterWorkaround

* Use using declarations and extend resource lifetimes

* Fix GTK issues

* Add formatting for generated files

* Add trailing commas

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
TSRBerry
2023-07-02 00:25:07 +02:00
committed by GitHub
parent 02b5c7ea89
commit 0684b00b3c
39 changed files with 1891 additions and 1830 deletions

View File

@@ -12,12 +12,12 @@ namespace Ryujinx.Ui.Widgets
private MenuItem _manageCheatMenuItem;
private MenuItem _openTitleModDirMenuItem;
private MenuItem _openTitleSdModDirMenuItem;
private Menu _extractSubMenu;
private Menu _extractSubMenu;
private MenuItem _extractMenuItem;
private MenuItem _extractRomFsMenuItem;
private MenuItem _extractExeFsMenuItem;
private MenuItem _extractLogoMenuItem;
private Menu _manageSubMenu;
private Menu _manageSubMenu;
private MenuItem _manageCacheMenuItem;
private MenuItem _purgePtcCacheMenuItem;
private MenuItem _purgeShaderCacheMenuItem;
@@ -31,7 +31,7 @@ namespace Ryujinx.Ui.Widgets
//
_openSaveUserDirMenuItem = new MenuItem("Open User Save Directory")
{
TooltipText = "Open the directory which contains Application's User Saves."
TooltipText = "Open the directory which contains Application's User Saves.",
};
_openSaveUserDirMenuItem.Activated += OpenSaveUserDir_Clicked;
@@ -40,7 +40,7 @@ namespace Ryujinx.Ui.Widgets
//
_openSaveDeviceDirMenuItem = new MenuItem("Open Device Save Directory")
{
TooltipText = "Open the directory which contains Application's Device Saves."
TooltipText = "Open the directory which contains Application's Device Saves.",
};
_openSaveDeviceDirMenuItem.Activated += OpenSaveDeviceDir_Clicked;
@@ -49,7 +49,7 @@ namespace Ryujinx.Ui.Widgets
//
_openSaveBcatDirMenuItem = new MenuItem("Open BCAT Save Directory")
{
TooltipText = "Open the directory which contains Application's BCAT Saves."
TooltipText = "Open the directory which contains Application's BCAT Saves.",
};
_openSaveBcatDirMenuItem.Activated += OpenSaveBcatDir_Clicked;
@@ -58,7 +58,7 @@ namespace Ryujinx.Ui.Widgets
//
_manageTitleUpdatesMenuItem = new MenuItem("Manage Title Updates")
{
TooltipText = "Open the Title Update management window"
TooltipText = "Open the Title Update management window",
};
_manageTitleUpdatesMenuItem.Activated += ManageTitleUpdates_Clicked;
@@ -67,7 +67,7 @@ namespace Ryujinx.Ui.Widgets
//
_manageDlcMenuItem = new MenuItem("Manage DLC")
{
TooltipText = "Open the DLC management window"
TooltipText = "Open the DLC management window",
};
_manageDlcMenuItem.Activated += ManageDlc_Clicked;
@@ -76,7 +76,7 @@ namespace Ryujinx.Ui.Widgets
//
_manageCheatMenuItem = new MenuItem("Manage Cheats")
{
TooltipText = "Open the Cheat management window"
TooltipText = "Open the Cheat management window",
};
_manageCheatMenuItem.Activated += ManageCheats_Clicked;
@@ -85,7 +85,7 @@ namespace Ryujinx.Ui.Widgets
//
_openTitleModDirMenuItem = new MenuItem("Open Mods Directory")
{
TooltipText = "Open the directory which contains Application's Mods."
TooltipText = "Open the directory which contains Application's Mods.",
};
_openTitleModDirMenuItem.Activated += OpenTitleModDir_Clicked;
@@ -94,7 +94,7 @@ namespace Ryujinx.Ui.Widgets
//
_openTitleSdModDirMenuItem = new MenuItem("Open Atmosphere Mods Directory")
{
TooltipText = "Open the alternative SD card atmosphere directory which contains the Application's Mods."
TooltipText = "Open the alternative SD card atmosphere directory which contains the Application's Mods.",
};
_openTitleSdModDirMenuItem.Activated += OpenTitleSdModDir_Clicked;
@@ -116,7 +116,7 @@ namespace Ryujinx.Ui.Widgets
//
_extractRomFsMenuItem = new MenuItem("RomFS")
{
TooltipText = "Extract the RomFS section from Application's current config (including updates)."
TooltipText = "Extract the RomFS section from Application's current config (including updates).",
};
_extractRomFsMenuItem.Activated += ExtractRomFs_Clicked;
@@ -125,7 +125,7 @@ namespace Ryujinx.Ui.Widgets
//
_extractExeFsMenuItem = new MenuItem("ExeFS")
{
TooltipText = "Extract the ExeFS section from Application's current config (including updates)."
TooltipText = "Extract the ExeFS section from Application's current config (including updates).",
};
_extractExeFsMenuItem.Activated += ExtractExeFs_Clicked;
@@ -134,7 +134,7 @@ namespace Ryujinx.Ui.Widgets
//
_extractLogoMenuItem = new MenuItem("Logo")
{
TooltipText = "Extract the Logo section from Application's current config (including updates)."
TooltipText = "Extract the Logo section from Application's current config (including updates).",
};
_extractLogoMenuItem.Activated += ExtractLogo_Clicked;
@@ -148,7 +148,7 @@ namespace Ryujinx.Ui.Widgets
//
_manageCacheMenuItem = new MenuItem("Cache Management")
{
Submenu = _manageSubMenu
Submenu = _manageSubMenu,
};
//
@@ -156,7 +156,7 @@ namespace Ryujinx.Ui.Widgets
//
_purgePtcCacheMenuItem = new MenuItem("Queue PPTC Rebuild")
{
TooltipText = "Trigger PPTC to rebuild at boot time on the next game launch."
TooltipText = "Trigger PPTC to rebuild at boot time on the next game launch.",
};
_purgePtcCacheMenuItem.Activated += PurgePtcCache_Clicked;
@@ -165,7 +165,7 @@ namespace Ryujinx.Ui.Widgets
//
_purgeShaderCacheMenuItem = new MenuItem("Purge Shader Cache")
{
TooltipText = "Delete the Application's shader cache."
TooltipText = "Delete the Application's shader cache.",
};
_purgeShaderCacheMenuItem.Activated += PurgeShaderCache_Clicked;
@@ -174,7 +174,7 @@ namespace Ryujinx.Ui.Widgets
//
_openPtcDirMenuItem = new MenuItem("Open PPTC Directory")
{
TooltipText = "Open the directory which contains the Application's PPTC cache."
TooltipText = "Open the directory which contains the Application's PPTC cache.",
};
_openPtcDirMenuItem.Activated += OpenPtcDir_Clicked;
@@ -183,7 +183,7 @@ namespace Ryujinx.Ui.Widgets
//
_openShaderCacheDirMenuItem = new MenuItem("Open Shader Cache Directory")
{
TooltipText = "Open the directory which contains the Application's shader cache."
TooltipText = "Open the directory which contains the Application's shader cache.",
};
_openShaderCacheDirMenuItem.Activated += OpenShaderCacheDir_Clicked;
@@ -217,4 +217,4 @@ namespace Ryujinx.Ui.Widgets
ShowAll();
}
}
}
}

View File

@@ -31,19 +31,19 @@ namespace Ryujinx.Ui.Widgets
{
public partial class GameTableContextMenu : Menu
{
private readonly MainWindow _parent;
private readonly VirtualFileSystem _virtualFileSystem;
private readonly AccountManager _accountManager;
private readonly HorizonClient _horizonClient;
private readonly MainWindow _parent;
private readonly VirtualFileSystem _virtualFileSystem;
private readonly AccountManager _accountManager;
private readonly HorizonClient _horizonClient;
private readonly BlitStruct<ApplicationControlProperty> _controlData;
private readonly string _titleFilePath;
private readonly string _titleName;
private readonly string _titleIdText;
private readonly ulong _titleId;
private readonly ulong _titleId;
private MessageDialog _dialog;
private bool _cancel;
private bool _cancel;
public GameTableContextMenu(MainWindow parent, VirtualFileSystem virtualFileSystem, AccountManager accountManager, HorizonClient horizonClient, string titleFilePath, string titleName, string titleId, BlitStruct<ApplicationControlProperty> controlData)
{
@@ -52,12 +52,12 @@ namespace Ryujinx.Ui.Widgets
InitializeComponent();
_virtualFileSystem = virtualFileSystem;
_accountManager = accountManager;
_horizonClient = horizonClient;
_titleFilePath = titleFilePath;
_titleName = titleName;
_titleIdText = titleId;
_controlData = controlData;
_accountManager = accountManager;
_horizonClient = horizonClient;
_titleFilePath = titleFilePath;
_titleName = titleName;
_titleIdText = titleId;
_controlData = controlData;
if (!ulong.TryParse(_titleIdText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out _titleId))
{
@@ -66,16 +66,16 @@ namespace Ryujinx.Ui.Widgets
return;
}
_openSaveUserDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0;
_openSaveDeviceDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0;
_openSaveBcatDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.BcatDeliveryCacheStorageSize > 0;
_openSaveUserDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0;
_openSaveDeviceDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0;
_openSaveBcatDirMenuItem.Sensitive = !Utilities.IsZeros(controlData.ByteSpan) && controlData.Value.BcatDeliveryCacheStorageSize > 0;
string fileExt = System.IO.Path.GetExtension(_titleFilePath).ToLower();
bool hasNca = fileExt == ".nca" || fileExt == ".nsp" || fileExt == ".pfs0" || fileExt == ".xci";
bool hasNca = fileExt == ".nca" || fileExt == ".nsp" || fileExt == ".pfs0" || fileExt == ".xci";
_extractRomFsMenuItem.Sensitive = hasNca;
_extractExeFsMenuItem.Sensitive = hasNca;
_extractLogoMenuItem.Sensitive = hasNca;
_extractLogoMenuItem.Sensitive = hasNca;
PopupAtPointer(null);
}
@@ -99,13 +99,13 @@ namespace Ryujinx.Ui.Widgets
control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
// The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
control.UserAccountSaveDataSize = 0x4000;
control.UserAccountSaveDataSize = 0x4000;
control.UserAccountSaveDataJournalSize = 0x4000;
Logger.Warning?.Print(LogClass.Application, "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
}
Uid user = new Uid((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low);
Uid user = new((ulong)_accountManager.LastOpenedUser.UserId.High, (ulong)_accountManager.LastOpenedUser.UserId.Low);
result = _horizonClient.Fs.EnsureApplicationSaveData(out _, new LibHac.Ncm.ApplicationId(titleId), in control, in user);
@@ -148,7 +148,7 @@ namespace Ryujinx.Ui.Widgets
}
string committedPath = System.IO.Path.Combine(saveRootPath, "0");
string workingPath = System.IO.Path.Combine(saveRootPath, "1");
string workingPath = System.IO.Path.Combine(saveRootPath, "1");
// If the committed directory exists, that path will be loaded the next time the savedata is mounted
if (Directory.Exists(committedPath))
@@ -170,25 +170,25 @@ namespace Ryujinx.Ui.Widgets
private void ExtractSection(NcaSectionType ncaSectionType, int programIndex = 0)
{
FileChooserNative fileChooser = new FileChooserNative("Choose the folder to extract into", _parent, FileChooserAction.SelectFolder, "Extract", "Cancel");
FileChooserNative fileChooser = new("Choose the folder to extract into", _parent, FileChooserAction.SelectFolder, "Extract", "Cancel");
ResponseType response = (ResponseType)fileChooser.Run();
string destination = fileChooser.Filename;
ResponseType response = (ResponseType)fileChooser.Run();
string destination = fileChooser.Filename;
fileChooser.Dispose();
if (response == ResponseType.Accept)
{
Thread extractorThread = new Thread(() =>
Thread extractorThread = new(() =>
{
Gtk.Application.Invoke(delegate
{
_dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Cancel, null)
{
Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png"),
SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(_titleFilePath)}...",
WindowPosition = WindowPosition.Center
Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png"),
SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(_titleFilePath)}...",
WindowPosition = WindowPosition.Center,
};
int dialogResponse = _dialog.Run();
@@ -199,139 +199,140 @@ namespace Ryujinx.Ui.Widgets
}
});
using (FileStream file = new FileStream(_titleFilePath, FileMode.Open, FileAccess.Read))
using FileStream file = new(_titleFilePath, FileMode.Open, FileAccess.Read);
Nca mainNca = null;
Nca patchNca = null;
if ((System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nsp") ||
(System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".pfs0") ||
(System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".xci"))
{
Nca mainNca = null;
Nca patchNca = null;
PartitionFileSystem pfs;
if ((System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nsp") ||
(System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".pfs0") ||
(System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".xci"))
if (System.IO.Path.GetExtension(_titleFilePath) == ".xci")
{
PartitionFileSystem pfs;
Xci xci = new(_virtualFileSystem.KeySet, file.AsStorage());
if (System.IO.Path.GetExtension(_titleFilePath) == ".xci")
pfs = xci.OpenPartition(XciPartitionType.Secure);
}
else
{
pfs = new PartitionFileSystem(file.AsStorage());
}
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
using var ncaFile = new UniqueRef<IFile>();
pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new(_virtualFileSystem.KeySet, ncaFile.Release().AsStorage());
if (nca.Header.ContentType == NcaContentType.Program)
{
Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage());
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
pfs = xci.OpenPartition(XciPartitionType.Secure);
}
else
{
pfs = new PartitionFileSystem(file.AsStorage());
}
foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
{
using var ncaFile = new UniqueRef<IFile>();
pfs.OpenFile(ref ncaFile.Ref, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.Release().AsStorage());
if (nca.Header.ContentType == NcaContentType.Program)
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);
if (nca.SectionExists(NcaSectionType.Data) && nca.Header.GetFsHeader(dataIndex).IsPatchSection())
{
patchNca = nca;
}
else
{
mainNca = nca;
}
patchNca = nca;
}
else
{
mainNca = nca;
}
}
}
else if (System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nca")
{
mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
}
}
else if (System.IO.Path.GetExtension(_titleFilePath).ToLower() == ".nca")
{
mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
}
if (mainNca == null)
{
Logger.Error?.Print(LogClass.Application, "Extraction failure. The main NCA is not present in the selected file.");
if (mainNca == null)
{
Logger.Error?.Print(LogClass.Application, "Extraction failure. The main NCA is not present in the selected file.");
Gtk.Application.Invoke(delegate
Gtk.Application.Invoke(delegate
{
GtkDialog.CreateErrorDialog("Extraction failure. The main NCA is not present in the selected file.");
});
return;
}
return;
}
(Nca updatePatchNca, _) = ApplicationLibrary.GetGameUpdateData(_virtualFileSystem, mainNca.Header.TitleId.ToString("x16"), programIndex, out _);
(Nca updatePatchNca, _) = ApplicationLibrary.GetGameUpdateData(_virtualFileSystem, mainNca.Header.TitleId.ToString("x16"), programIndex, out _);
if (updatePatchNca != null)
{
patchNca = updatePatchNca;
}
if (updatePatchNca != null)
{
patchNca = updatePatchNca;
}
int index = Nca.GetSectionIndexFromType(ncaSectionType, mainNca.Header.ContentType);
int index = Nca.GetSectionIndexFromType(ncaSectionType, mainNca.Header.ContentType);
bool sectionExistsInPatch = false;
if (patchNca != null)
{
sectionExistsInPatch = patchNca.CanOpenSection(index);
}
bool sectionExistsInPatch = false;
IFileSystem ncaFileSystem = sectionExistsInPatch ? mainNca.OpenFileSystemWithPatch(patchNca, index, IntegrityCheckLevel.ErrorOnInvalid)
if (patchNca != null)
{
sectionExistsInPatch = patchNca.CanOpenSection(index);
}
IFileSystem ncaFileSystem = sectionExistsInPatch ? mainNca.OpenFileSystemWithPatch(patchNca, index, IntegrityCheckLevel.ErrorOnInvalid)
: mainNca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid);
FileSystemClient fsClient = _horizonClient.Fs;
FileSystemClient fsClient = _horizonClient.Fs;
string source = DateTime.Now.ToFileTime().ToString()[10..];
string output = DateTime.Now.ToFileTime().ToString()[10..];
string source = DateTime.Now.ToFileTime().ToString()[10..];
string output = DateTime.Now.ToFileTime().ToString()[10..];
using var uniqueSourceFs = new UniqueRef<IFileSystem>(ncaFileSystem);
using var uniqueOutputFs = new UniqueRef<IFileSystem>(new LocalFileSystem(destination));
using var uniqueSourceFs = new UniqueRef<IFileSystem>(ncaFileSystem);
using var uniqueOutputFs = new UniqueRef<IFileSystem>(new LocalFileSystem(destination));
fsClient.Register(source.ToU8Span(), ref uniqueSourceFs.Ref);
fsClient.Register(output.ToU8Span(), ref uniqueOutputFs.Ref);
fsClient.Register(source.ToU8Span(), ref uniqueSourceFs.Ref);
fsClient.Register(output.ToU8Span(), ref uniqueOutputFs.Ref);
(Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");
(Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");
if (!canceled)
if (!canceled)
{
if (resultCode.Value.IsFailure())
{
if (resultCode.Value.IsFailure())
{
Logger.Error?.Print(LogClass.Application, $"LibHac returned error code: {resultCode.Value.ErrorCode}");
Logger.Error?.Print(LogClass.Application, $"LibHac returned error code: {resultCode.Value.ErrorCode}");
Gtk.Application.Invoke(delegate
Gtk.Application.Invoke(delegate
{
_dialog?.Dispose();
GtkDialog.CreateErrorDialog("Extraction failed. Read the log file for further information.");
});
}
else if (resultCode.Value.IsSuccess())
{
Gtk.Application.Invoke(delegate
}
else if (resultCode.Value.IsSuccess())
{
Gtk.Application.Invoke(delegate
{
_dialog?.Dispose();
MessageDialog dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
MessageDialog dialog = new(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
{
Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png"),
SecondaryText = "Extraction completed successfully.",
WindowPosition = WindowPosition.Center
Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png"),
SecondaryText = "Extraction completed successfully.",
WindowPosition = WindowPosition.Center,
};
dialog.Run();
dialog.Dispose();
});
}
}
fsClient.Unmount(source.ToU8Span());
fsClient.Unmount(output.ToU8Span());
}
});
extractorThread.Name = "GUI.NcaSectionExtractorThread";
extractorThread.IsBackground = true;
fsClient.Unmount(source.ToU8Span());
fsClient.Unmount(output.ToU8Span());
})
{
Name = "GUI.NcaSectionExtractorThread",
IsBackground = true,
};
extractorThread.Start();
}
}
@@ -339,7 +340,10 @@ namespace Ryujinx.Ui.Widgets
private (Result? result, bool canceled) CopyDirectory(FileSystemClient fs, string sourcePath, string destPath)
{
Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All);
if (rc.IsFailure()) return (rc, false);
if (rc.IsFailure())
{
return (rc, false);
}
using (sourceHandle)
{
@@ -369,7 +373,10 @@ namespace Ryujinx.Ui.Widgets
fs.CreateOrOverwriteFile(subDstPath, entry.Size);
rc = CopyFile(fs, subSrcPath, subDstPath);
if (rc.IsFailure()) return (rc, false);
if (rc.IsFailure())
{
return (rc, false);
}
}
}
}
@@ -377,22 +384,31 @@ namespace Ryujinx.Ui.Widgets
return (Result.Success, false);
}
public Result CopyFile(FileSystemClient fs, string sourcePath, string destPath)
public static Result CopyFile(FileSystemClient fs, string sourcePath, string destPath)
{
Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath.ToU8Span(), OpenMode.Read);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
using (sourceHandle)
{
rc = fs.OpenFile(out FileHandle destHandle, destPath.ToU8Span(), OpenMode.Write | OpenMode.AllowAppend);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
using (destHandle)
{
const int MaxBufferSize = 1024 * 1024;
rc = fs.GetFileSize(out long fileSize, sourceHandle);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
int bufferSize = (int)Math.Min(MaxBufferSize, fileSize);
@@ -405,10 +421,16 @@ namespace Ryujinx.Ui.Widgets
Span<byte> buf = buffer.AsSpan(0, toRead);
rc = fs.ReadFile(out long _, sourceHandle, offset, buf);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
rc = fs.WriteFile(destHandle, offset, buf, WriteOption.None);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
}
}
finally
@@ -417,7 +439,10 @@ namespace Ryujinx.Ui.Widgets
}
rc = fs.FlushFile(destHandle);
if (rc.IsFailure()) return rc;
if (rc.IsFailure())
{
return rc;
}
}
}
@@ -466,7 +491,7 @@ namespace Ryujinx.Ui.Widgets
private void OpenTitleModDir_Clicked(object sender, EventArgs args)
{
string modsBasePath = ModLoader.GetModsBasePath();
string modsBasePath = ModLoader.GetModsBasePath();
string titleModsPath = ModLoader.GetTitleDir(modsBasePath, _titleIdText);
OpenHelper.OpenFolder(titleModsPath);
@@ -474,8 +499,8 @@ namespace Ryujinx.Ui.Widgets
private void OpenTitleSdModDir_Clicked(object sender, EventArgs args)
{
string sdModsBasePath = ModLoader.GetSdModsBasePath();
string titleModsPath = ModLoader.GetTitleDir(sdModsBasePath, _titleIdText);
string sdModsBasePath = ModLoader.GetSdModsBasePath();
string titleModsPath = ModLoader.GetTitleDir(sdModsBasePath, _titleIdText);
OpenHelper.OpenFolder(titleModsPath);
}
@@ -497,9 +522,9 @@ namespace Ryujinx.Ui.Widgets
private void OpenPtcDir_Clicked(object sender, EventArgs args)
{
string ptcDir = System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu");
string ptcDir = System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu");
string mainPath = System.IO.Path.Combine(ptcDir, "0");
string mainPath = System.IO.Path.Combine(ptcDir, "0");
string backupPath = System.IO.Path.Combine(ptcDir, "1");
if (!Directory.Exists(ptcDir))
@@ -526,12 +551,12 @@ namespace Ryujinx.Ui.Widgets
private void PurgePtcCache_Clicked(object sender, EventArgs args)
{
DirectoryInfo mainDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "0"));
DirectoryInfo backupDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "1"));
DirectoryInfo mainDir = new(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "0"));
DirectoryInfo backupDir = new(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "cpu", "1"));
MessageDialog warningDialog = GtkDialog.CreateConfirmationDialog("Warning", $"You are about to queue a PPTC rebuild on the next boot of:\n\n<b>{_titleName}</b>\n\nAre you sure you want to proceed?");
List<FileInfo> cacheFiles = new List<FileInfo>();
List<FileInfo> cacheFiles = new();
if (mainDir.Exists)
{
@@ -551,7 +576,7 @@ namespace Ryujinx.Ui.Widgets
{
file.Delete();
}
catch(Exception e)
catch (Exception e)
{
GtkDialog.CreateErrorDialog($"Error purging PPTC cache {file.Name}: {e}");
}
@@ -563,12 +588,12 @@ namespace Ryujinx.Ui.Widgets
private void PurgeShaderCache_Clicked(object sender, EventArgs args)
{
DirectoryInfo shaderCacheDir = new DirectoryInfo(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "shader"));
DirectoryInfo shaderCacheDir = new(System.IO.Path.Combine(AppDataManager.GamesDirPath, _titleIdText, "cache", "shader"));
using MessageDialog warningDialog = GtkDialog.CreateConfirmationDialog("Warning", $"You are about to delete the shader cache for :\n\n<b>{_titleName}</b>\n\nAre you sure you want to proceed?");
List<DirectoryInfo> oldCacheDirectories = new List<DirectoryInfo>();
List<FileInfo> newCacheFiles = new List<FileInfo>();
List<DirectoryInfo> oldCacheDirectories = new();
List<FileInfo> newCacheFiles = new();
if (shaderCacheDir.Exists)
{

View File

@@ -10,14 +10,14 @@ namespace Ryujinx.Ui.Widgets
{
private static bool _isChoiceDialogOpen;
private GtkDialog(string title, string mainText, string secondaryText, MessageType messageType = MessageType.Other, ButtonsType buttonsType = ButtonsType.Ok)
private GtkDialog(string title, string mainText, string secondaryText, MessageType messageType = MessageType.Other, ButtonsType buttonsType = ButtonsType.Ok)
: base(null, DialogFlags.Modal, messageType, buttonsType, null)
{
Title = title;
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
Text = mainText;
SecondaryText = secondaryText;
WindowPosition = WindowPosition.Center;
Title = title;
Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
Text = mainText;
SecondaryText = secondaryText;
WindowPosition = WindowPosition.Center;
SecondaryUseMarkup = true;
Response += GtkDialog_Response;
@@ -80,7 +80,7 @@ namespace Ryujinx.Ui.Widgets
internal static ResponseType CreateCustomDialog(string title, string mainText, string secondaryText, Dictionary<int, string> buttons, MessageType messageType = MessageType.Other)
{
GtkDialog gtkDialog = new GtkDialog(title, mainText, secondaryText, messageType, ButtonsType.None);
GtkDialog gtkDialog = new(title, mainText, secondaryText, messageType, ButtonsType.None);
foreach (var button in buttons)
{
@@ -92,9 +92,9 @@ namespace Ryujinx.Ui.Widgets
internal static string CreateInputDialog(Window parent, string title, string mainText, uint inputMax)
{
GtkInputDialog gtkDialog = new GtkInputDialog(parent, title, mainText, inputMax);
ResponseType response = (ResponseType)gtkDialog.Run();
string responseText = gtkDialog.InputEntry.Text.TrimEnd();
GtkInputDialog gtkDialog = new(parent, title, mainText, inputMax);
ResponseType response = (ResponseType)gtkDialog.Run();
string responseText = gtkDialog.InputEntry.Text.TrimEnd();
gtkDialog.Dispose();

View File

@@ -12,26 +12,26 @@ namespace Ryujinx.Ui.Widgets
Title = title;
Label mainTextLabel = new Label
Label mainTextLabel = new()
{
Text = mainText
Text = mainText,
};
InputEntry = new Entry
{
MaxLength = (int)inputMax
MaxLength = (int)inputMax,
};
Label inputMaxTextLabel = new Label
Label inputMaxTextLabel = new()
{
Text = $"(Max length: {inputMax})"
Text = $"(Max length: {inputMax})",
};
((Box)MessageArea).PackStart(mainTextLabel, true, true, 0);
((Box)MessageArea).PackStart(InputEntry, true, true, 5);
((Box)MessageArea).PackStart(mainTextLabel, true, true, 0);
((Box)MessageArea).PackStart(InputEntry, true, true, 5);
((Box)MessageArea).PackStart(inputMaxTextLabel, true, true, 0);
ShowAll();
}
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Ryujinx.Ui.Widgets
{
public string FileName { get; private set; }
#pragma warning disable CS0649, IDE0044
#pragma warning disable CS0649, IDE0044 // Field is never assigned to, Add readonly modifier
[GUI] Entry _profileEntry;
[GUI] Label _errorMessage;
#pragma warning restore CS0649, IDE0044
@@ -54,4 +54,4 @@ namespace Ryujinx.Ui.Widgets
Respond(ResponseType.Cancel);
}
}
}
}

View File

@@ -6,9 +6,9 @@ namespace Ryujinx.Ui.Widgets
{
internal class UserErrorDialog : MessageDialog
{
private const string SetupGuideUrl = "https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide";
private const int OkResponseId = 0;
private const int SetupGuideResponseId = 1;
private const string SetupGuideUrl = "https://github.com/Ryujinx/Ryujinx/wiki/Ryujinx-Setup-&-Configuration-Guide";
private const int OkResponseId = 0;
private const int SetupGuideResponseId = 1;
private readonly UserError _userError;
@@ -16,7 +16,7 @@ namespace Ryujinx.Ui.Widgets
{
_userError = error;
WindowPosition = WindowPosition.Center;
WindowPosition = WindowPosition.Center;
SecondaryUseMarkup = true;
Response += UserErrorDialog_Response;
@@ -36,8 +36,8 @@ namespace Ryujinx.Ui.Widgets
SecondaryUseMarkup = true;
Title = $"Ryujinx error ({errorCode})";
Text = $"{errorCode}: {GetErrorTitle(error)}";
Title = $"Ryujinx error ({errorCode})";
Text = $"{errorCode}: {GetErrorTitle(error)}";
SecondaryText = GetErrorDescription(error);
if (isInSetupGuide)
@@ -46,34 +46,34 @@ namespace Ryujinx.Ui.Widgets
}
}
private string GetErrorCode(UserError error)
private static string GetErrorCode(UserError error)
{
return $"RYU-{(uint)error:X4}";
}
private string GetErrorTitle(UserError error)
private static string GetErrorTitle(UserError error)
{
return error switch
{
UserError.NoKeys => "Keys not found",
UserError.NoFirmware => "Firmware not found",
UserError.NoKeys => "Keys not found",
UserError.NoFirmware => "Firmware not found",
UserError.FirmwareParsingFailed => "Firmware parsing error",
UserError.ApplicationNotFound => "Application not found",
UserError.Unknown => "Unknown error",
_ => "Undefined error",
UserError.ApplicationNotFound => "Application not found",
UserError.Unknown => "Unknown error",
_ => "Undefined error",
};
}
private string GetErrorDescription(UserError error)
private static string GetErrorDescription(UserError error)
{
return error switch
{
UserError.NoKeys => "Ryujinx was unable to find your 'prod.keys' file",
UserError.NoFirmware => "Ryujinx was unable to find any firmwares installed",
UserError.NoKeys => "Ryujinx was unable to find your 'prod.keys' file",
UserError.NoFirmware => "Ryujinx was unable to find any firmwares installed",
UserError.FirmwareParsingFailed => "Ryujinx was unable to parse the provided firmware. This is usually caused by outdated keys.",
UserError.ApplicationNotFound => "Ryujinx couldn't find a valid application at the given path.",
UserError.Unknown => "An unknown error occured!",
_ => "An undefined error occured! This shouldn't happen, please contact a dev!",
UserError.ApplicationNotFound => "Ryujinx couldn't find a valid application at the given path.",
UserError.Unknown => "An unknown error occured!",
_ => "An undefined error occured! This shouldn't happen, please contact a dev!",
};
}
@@ -82,9 +82,9 @@ namespace Ryujinx.Ui.Widgets
return error switch
{
UserError.NoKeys or
UserError.NoFirmware or
UserError.NoFirmware or
UserError.FirmwareParsingFailed => true,
_ => false,
_ => false,
};
}
@@ -97,9 +97,9 @@ namespace Ryujinx.Ui.Widgets
return error switch
{
UserError.NoKeys => SetupGuideUrl + "#initial-setup---placement-of-prodkeys",
UserError.NoKeys => SetupGuideUrl + "#initial-setup---placement-of-prodkeys",
UserError.NoFirmware => SetupGuideUrl + "#initial-setup-continued---installation-of-firmware",
_ => SetupGuideUrl,
_ => SetupGuideUrl,
};
}
@@ -120,4 +120,4 @@ namespace Ryujinx.Ui.Widgets
new UserErrorDialog(error).Run();
}
}
}
}