make extraction cancelable

This commit is contained in:
Xpl0itR 2020-01-30 17:48:02 +00:00
commit c3daba0e7c
No known key found for this signature in database
GPG key ID: 91798184109676AD

View file

@ -26,6 +26,7 @@ namespace Ryujinx.Ui
private TreeIter _rowIter; private TreeIter _rowIter;
private VirtualFileSystem _virtualFileSystem; private VirtualFileSystem _virtualFileSystem;
private MessageDialog _dialog; private MessageDialog _dialog;
private bool _cancel;
#pragma warning disable CS0649 #pragma warning disable CS0649
#pragma warning disable IDE0044 #pragma warning disable IDE0044
@ -166,16 +167,20 @@ namespace Ryujinx.Ui
Gtk.Application.Invoke(delegate Gtk.Application.Invoke(delegate
{ {
_dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.None, null) _dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Cancel, null)
{ {
Title = "Ryujinx - NCA Section Extractor", Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"), Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
Text = "",
SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(sourceFile)}...", SecondaryText = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(sourceFile)}...",
WindowPosition = WindowPosition.Center WindowPosition = WindowPosition.Center
}; };
_dialog.Response += (sender, args) => _dialog.Dispose();
_dialog.Show(); int dialogResponse = _dialog.Run();
if (dialogResponse == (int)ResponseType.Cancel || dialogResponse == (int)ResponseType.DeleteEvent)
{
_cancel = true;
_dialog.Dispose();
}
}); });
using (FileStream file = new FileStream(sourceFile, FileMode.Open, FileAccess.Read)) using (FileStream file = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
@ -255,21 +260,33 @@ namespace Ryujinx.Ui
if (resultCode.IsFailure()) if (resultCode.IsFailure())
{ {
Logger.PrintError(LogClass.Application, $"LibHac returned error code: {resultCode.ErrorCode}"); if (resultCode.ErrorCode != "2468-1357")
Gtk.Application.Invoke(delegate
{ {
_dialog.Text = "Ryujinx has encountered an error"; Logger.PrintError(LogClass.Application, $"LibHac returned error code: {resultCode.ErrorCode}");
_dialog.SecondaryText = "Extraction failed. Read the log file for further information.";
_dialog.AddButton("OK", ResponseType.Ok); Gtk.Application.Invoke(delegate
}); {
_dialog?.Dispose();
GtkDialog.CreateErrorDialog("Extraction failed. Read the log file for further information.");
});
}
} }
else if (resultCode.IsSuccess()) else if (resultCode.IsSuccess())
{ {
Gtk.Application.Invoke(delegate Gtk.Application.Invoke(delegate
{ {
_dialog.SecondaryText = "Extraction has completed successfully."; _dialog?.Dispose();
_dialog.AddButton("OK", ResponseType.Ok);
MessageDialog dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
{
Title = "Ryujinx - NCA Section Extractor",
Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
SecondaryText = "Extraction has completed successfully.",
WindowPosition = WindowPosition.Center
};
dialog.Run();
dialog.Dispose();
}); });
} }
@ -283,7 +300,7 @@ namespace Ryujinx.Ui
} }
} }
private static Result CopyDirectory(FileSystemClient fs, string sourcePath, string destPath) private Result CopyDirectory(FileSystemClient fs, string sourcePath, string destPath)
{ {
Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All); Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All);
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
@ -292,6 +309,8 @@ namespace Ryujinx.Ui
{ {
foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePath, "*", SearchOptions.Default)) foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePath, "*", SearchOptions.Default))
{ {
if (_cancel) return new Result(468, 1357);
string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePath, entry.Name)); string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePath, entry.Name));
string subDstPath = PathTools.Normalize(PathTools.Combine(destPath, entry.Name)); string subDstPath = PathTools.Normalize(PathTools.Combine(destPath, entry.Name));
@ -316,7 +335,7 @@ namespace Ryujinx.Ui
return Result.Success; return Result.Success;
} }
public static Result CopyFile(FileSystemClient fs, string sourcePath, string destPath) public Result CopyFile(FileSystemClient fs, string sourcePath, string destPath)
{ {
Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath, OpenMode.Read); Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath, OpenMode.Read);
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;