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:
dev747368 2024-10-28 20:32:10 +00:00
parent 87c5523a06
commit cdf309cfc7
7 changed files with 40 additions and 29 deletions

View File

@ -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;

View File

@ -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",

View File

@ -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);
}
});
}

View File

@ -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();

View File

@ -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) {

View File

@ -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));

View File

@ -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));