Support for saving files in bundle#287
Support for saving files in bundle#287CursedSheep wants to merge 1 commit intodnSpyEx:feature/single-file-bundlesfrom
Conversation
| static readonly HashSet<char> invalidFileNameChar = new HashSet<char>(); | ||
| static BundleNameCleaner() { |
There was a problem hiding this comment.
New empty line between method definition and field definition
| public static class SaveBundle { | ||
|
|
||
| /// <summary> |
| static bool CanExecute(AsmEditorContext context) => SaveBundleContentsCommand.IsSingleFileBundle(context); | ||
| static void Execute(AsmEditorContext context) { |
There was a problem hiding this comment.
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.
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.
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.
| 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.
| 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.
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.
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.
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.