-
-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for saving files in bundle #287
base: feature/single-file-bundles
Are you sure you want to change the base?
Support for saving files in bundle #287
Conversation
static readonly HashSet<char> invalidFileNameChar = new HashSet<char>(); | ||
static BundleNameCleaner() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New empty line between method definition and field definition
public static class SaveBundle { | ||
|
||
/// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary empty line here
static bool CanExecute(AsmEditorContext context) => SaveBundleContentsCommand.IsSingleFileBundle(context); | ||
static void Execute(AsmEditorContext context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line between method with full body and method between statement body
} | ||
public override bool IsVisible(AsmEditorContext context) => SaveBundleContentsCommand.CanExecute(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line between constructor and methods with statement bodies
} | ||
public override bool IsVisible(AsmEditorContext context) => SaveRawEntryCommand.CanExecute(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line between constructor and methods with statement bodies
static bool IsSingleFileBundle(AsmEditorContext context) => context.Nodes.Length == 1 && context.Nodes[0] is BundleDocumentNode; | ||
static bool CanExecute(AsmEditorContext context) => SaveBundleContentsCommand.IsSingleFileBundle(context); | ||
static void Execute(AsmEditorContext context) { | ||
var docNode = context.Nodes[0].GetDocumentNode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var docNode = context.Nodes[0].GetDocumentNode(); | |
var docNode = context.Nodes[0] as BundleDocumentNode; |
We can just safe cast it as the CanExecute
method has already checked whether the node is a BundleDocumentNode
static bool IsBundleSingleSelection(AsmEditorContext context) => context.Nodes.Length == 1 && context.Nodes[0] is IBundleEntryNode; | ||
static bool CanExecute(AsmEditorContext context) => SaveRawEntryCommand.IsBundleSingleSelection(context); | ||
static void Execute(AsmEditorContext context) { | ||
var bundleEntryNode = (IBundleEntryNode)context.Nodes[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var bundleEntryNode = (IBundleEntryNode)context.Nodes[0]; | |
var bundleEntryNode = context.Nodes[0] as IBundleEntryNode; | |
Debug2.Assert(bundleEntryNode is not null); |
Use safe cast here and debug assert. Furthermore, please assert that bundleEntryNode.BundleEntry is not null
Debug2.Assert(bundleDoc != null); | ||
Debug2.Assert(bundleDoc.SingleFileBundle != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use is not null
instead of != null
static bool CanExecute(AsmEditorContext context) => SaveRawEntryCommand.IsBundleSingleSelection(context); | ||
static void Execute(AsmEditorContext context) { | ||
var bundleEntryNode = (IBundleEntryNode)context.Nodes[0]; | ||
SaveBundle.Save([bundleEntryNode.BundleEntry!], dnSpy_AsmEditor_Resources.SaveRawEntry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the old new BundleEntry[] { bundleEntryNode.BundleEntry }
syntax instead
public override void Execute(AsmEditorContext context) => SaveRawEntryCommand.Execute(context); | ||
} | ||
|
||
static bool IsBundleSingleSelection(AsmEditorContext context) => context.Nodes.Length == 1 && context.Nodes[0] is IBundleEntryNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check whether the IBundleEntryNode.BundleEntry
is not null. Implementing this interface does not guarantee that the node has an entry!
Problem
As of commit 6d0f609, it does not support saving files inside the bundle.
Solution
Added an option in context menu to save files inside a bundle app.