mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-24 21:21:56 +00:00
GP-5031 PR #7070 followup, invert '.' dot logic, use ext for txt, jpg
Invert the file name extension convention from yes-leading-dot to no-leading-dot, to match other classes that specify extensions. Use the filename ext for the txt and image fsbfilehandlers.
This commit is contained in:
parent
87c5523a06
commit
cdf309cfc7
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -56,7 +56,7 @@ public enum FileAttributeType {
|
||||
|
||||
SYMLINK_DEST_ATTR("Symbolic link destination", MISC_INFO, String.class),
|
||||
COMMENT_ATTR("Comment", MISC_INFO, String.class),
|
||||
FILENAME_EXT_OVERRIDE("Extension override", MISC_INFO, String.class),
|
||||
FILENAME_EXT_OVERRIDE("Extension override", MISC_INFO, String.class), // no leading '.'
|
||||
|
||||
UNKNOWN_ATTRIBUTE("Other attribute", ADDITIONAL_INFO, Object.class);
|
||||
|
||||
@ -64,7 +64,7 @@ public enum FileAttributeType {
|
||||
private final FileAttributeTypeGroup group;
|
||||
private final Class<?> valueType;
|
||||
|
||||
private FileAttributeType(String displayName, FileAttributeTypeGroup group,
|
||||
FileAttributeType(String displayName, FileAttributeTypeGroup group,
|
||||
Class<?> valueType) {
|
||||
this.displayName = displayName;
|
||||
this.group = group;
|
||||
|
@ -59,16 +59,13 @@ public class ImporterUtilities {
|
||||
|
||||
/**
|
||||
* File extension filter for well known 'loadable' files for GhidraFileChoosers.
|
||||
*
|
||||
* TODO: will be refactored to use file_extension_icon.xml file info.
|
||||
*/
|
||||
public static final GhidraFileFilter LOADABLE_FILES_FILTER = ExtensionFileFilter.forExtensions(
|
||||
"Loadable files", "exe", "dll", "obj", "drv", "bin", "hex", "o", "a", "so", "class", "lib");
|
||||
"Loadable files", "exe", "dll", "obj", "drv", "bin", "hex", "o", "a", "so", "class", "lib",
|
||||
"dylib");
|
||||
|
||||
/**
|
||||
* File extension filter for well known 'container' files for GhidraFileChoosers.
|
||||
*
|
||||
* TODO: will be refactored to use file_extension_icon.xml file info.
|
||||
*/
|
||||
public static final GhidraFileFilter CONTAINER_FILES_FILTER =
|
||||
ExtensionFileFilter.forExtensions("Container files", "zip", "tar", "tgz", "jar", "gz",
|
||||
|
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -194,16 +194,16 @@ public class FSBComponentProvider extends ComponentProviderAdapter
|
||||
|
||||
String ext = node.getFilenameExtOverride();
|
||||
if (ext != null && !ext.isEmpty()) {
|
||||
if (!ext.startsWith(".")) {
|
||||
Msg.error(this, "Extension override '" + ext + "' does not begin with a dot");
|
||||
if (ext.startsWith(".")) {
|
||||
Msg.error(this,
|
||||
"Extension override '" + ext + "' should not begin with a dot");
|
||||
} else {
|
||||
filename += ext;
|
||||
filename += "." + ext;
|
||||
}
|
||||
}
|
||||
|
||||
Icon icon = fsbIcons.getIcon(filename, overlays);
|
||||
setIcon(icon);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -88,6 +88,13 @@ public class FSBFileNode extends FSBNode {
|
||||
return filenameExtOverride;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileExtension() {
|
||||
return filenameExtOverride != null && !filenameExtOverride.isEmpty()
|
||||
? filenameExtOverride
|
||||
: super.getFileExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return file.hashCode();
|
||||
|
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -22,6 +22,8 @@ import java.util.stream.Collectors;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
import docking.widgets.tree.GTreeSlowLoadingNode;
|
||||
import ghidra.formats.gfilesystem.*;
|
||||
@ -65,6 +67,15 @@ public abstract class FSBNode extends GTreeSlowLoadingNode {
|
||||
return getFSRL().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension of this node's name, or "" if none
|
||||
*
|
||||
* @return extension of this node's name, or "" if none
|
||||
*/
|
||||
public String getFileExtension() {
|
||||
return FilenameUtils.getExtension(getName());
|
||||
}
|
||||
|
||||
public FSBRootNode getFSBRootNode() {
|
||||
GTreeNode node = getParent();
|
||||
while (node != null) {
|
||||
|
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -22,8 +22,6 @@ import java.util.Set;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import docking.action.DockingAction;
|
||||
import docking.action.builder.ActionBuilder;
|
||||
import docking.widgets.label.GIconLabel;
|
||||
@ -48,9 +46,7 @@ public class ImageFSBFileHandler implements FSBFileHandler {
|
||||
|
||||
@Override
|
||||
public boolean fileDefaultAction(FSBFileNode fileNode) {
|
||||
FSRL fsrl = fileNode.getFSRL();
|
||||
String extension = FilenameUtils.getExtension(fsrl.getName().toLowerCase());
|
||||
if (COMMON_IMAGE_EXTENSIONS.contains(extension)) {
|
||||
if (COMMON_IMAGE_EXTENSIONS.contains(fileNode.getFileExtension().toLowerCase())) {
|
||||
FSBComponentProvider fsbComponent = context.fsbComponent();
|
||||
fsbComponent.runTask(monitor -> doViewAsImage(fileNode.getFSRL(),
|
||||
fsbComponent.getComponent(), monitor));
|
||||
|
@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -46,7 +46,7 @@ public class TextFSBFileHandler implements FSBFileHandler {
|
||||
|
||||
@Override
|
||||
public boolean fileDefaultAction(FSBFileNode fileNode) {
|
||||
if (fileNode.getName().toLowerCase().endsWith(".txt")) {
|
||||
if (fileNode.getFileExtension().equalsIgnoreCase("txt")) {
|
||||
FSBComponentProvider fsbComponent = context.fsbComponent();
|
||||
fsbComponent.runTask(
|
||||
monitor -> doViewAsText(fileNode.getFSRL(), fsbComponent.getComponent(), monitor));
|
||||
|
Loading…
Reference in New Issue
Block a user