Use RSTA's file type detector

This commit is contained in:
Nico Mexis 2022-01-03 20:05:56 +01:00
parent dda0604696
commit 54fc4e5e48
No known key found for this signature in database
GPG key ID: 27D6E17CE092AB78
4 changed files with 12 additions and 8 deletions

View file

@ -3,11 +3,13 @@ package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Font; import java.awt.Font;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.fife.ui.rsyntaxtextarea.FileTypeUtil;
import org.imgscalr.Scalr; import org.imgscalr.Scalr;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
@ -19,7 +21,6 @@ import the.bytecode.club.bytecodeviewer.resources.Resource;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.resources.ResourceType; import the.bytecode.club.bytecodeviewer.resources.ResourceType;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -143,7 +144,7 @@ public class FileViewer extends ResourceViewer
} }
textArea.setCodeFoldingEnabled(true); textArea.setCodeFoldingEnabled(true);
textArea.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(nameLowerCase, contentsAsString).getSyntaxConstant()); textArea.setSyntaxEditingStyle(FileTypeUtil.get().guessContentType(new File(nameLowerCase)));
textArea.setText(contentsAsString); textArea.setText(contentsAsString);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue())); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
textArea.setCaretPosition(0); textArea.setCaretPosition(0);

View file

@ -15,6 +15,7 @@ import javax.swing.JPanel;
import me.konloch.kontainer.io.DiskReader; import me.konloch.kontainer.io.DiskReader;
import me.konloch.kontainer.io.DiskWriter; import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.compress.utils.FileNameUtils; import org.apache.commons.compress.utils.FileNameUtils;
import org.fife.ui.rsyntaxtextarea.FileTypeUtil;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
@ -26,7 +27,6 @@ import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenu;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenuItem; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenuItem;
import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.DialogUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage;
import static the.bytecode.club.bytecodeviewer.Constants.fs; import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory; import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
@ -88,7 +88,7 @@ public class PluginWriter extends JFrame
area.setOnCtrlS(this::save); area.setOnCtrlS(this::save);
area.setText(content); area.setText(content);
area.setCaretPosition(0); area.setCaretPosition(0);
area.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(pluginName, content).getSyntaxConstant()); area.setSyntaxEditingStyle(FileTypeUtil.get().guessContentType(new File(pluginName)));
content = null; content = null;
JButton run = new JButton("Run"); JButton run = new JButton("Run");

View file

@ -29,8 +29,9 @@ import javax.swing.ImageIcon;
public enum ResourceType public enum ResourceType
{ {
//TODO tar/gzip? // TODO tar/gzip?
//TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage // TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage
// or from org.fife.ui.rsyntaxtextarea.FileTypeUtil or from org.fife.ui.rsyntaxtextarea.SyntaxConstants
CLASS_FILE(IconResources.classIcon, "class"), CLASS_FILE(IconResources.classIcon, "class"),
JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"),

View file

@ -23,7 +23,9 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
/** /**
* @author ThexXTURBOXx * @author ThexXTURBOXx
* @deprecated See {@link org.fife.ui.rsyntaxtextarea.FileTypeUtil#guessContentType(java.io.File)}
*/ */
@Deprecated
public enum SyntaxLanguage public enum SyntaxLanguage
{ {
XML(SyntaxConstants.SYNTAX_STYLE_XML, XML(SyntaxConstants.SYNTAX_STYLE_XML,