bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java

92 lines
2.9 KiB
Java
Raw Normal View History

2021-06-26 15:10:02 +00:00
package the.bytecode.club.bytecodeviewer.resources.importing;
import java.io.File;
2021-07-14 10:25:02 +00:00
import org.apache.commons.io.FilenameUtils;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
2021-07-05 04:24:19 +00:00
import the.bytecode.club.bytecodeviewer.Settings;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* @author Konloch
*/
2021-06-26 12:59:51 +00:00
public class ImportResource implements Runnable
{
private final File[] files;
2021-06-26 12:59:51 +00:00
public ImportResource(File[] files) {this.files = files;}
@Override
public void run()
{
2021-06-26 12:59:51 +00:00
try
{
2021-06-26 14:11:23 +00:00
for (final File file : files)
2021-06-26 12:59:51 +00:00
{
2021-06-26 14:11:23 +00:00
final String fn = file.getName();
System.out.println("Opening..." + file.getAbsolutePath());
2021-06-26 14:21:23 +00:00
2021-07-10 16:05:08 +00:00
//check if file exists
2021-06-26 14:11:23 +00:00
if (!file.exists())
{
BytecodeViewer.showMessage("The file " + file.getAbsolutePath() + " could not be found.");
2021-07-05 04:24:19 +00:00
Settings.removeRecentFile(file);
2021-07-10 16:05:08 +00:00
continue;
2021-06-26 14:11:23 +00:00
}
2021-07-10 16:05:08 +00:00
//check if file is directory
if (file.isDirectory())
2021-06-26 14:11:23 +00:00
{
2021-07-10 16:05:08 +00:00
Import.DIRECTORY.getImporter().open(file);
}
2021-07-10 16:05:08 +00:00
//everything else import as a resource
2021-07-14 10:25:02 +00:00
else if(!importKnownFile(file))
2021-07-10 16:05:08 +00:00
Import.FILE.getImporter().open(file);
}
2021-06-26 14:21:23 +00:00
}
catch (final Exception e)
{
2021-07-07 02:51:10 +00:00
BytecodeViewer.handleException(e);
2021-06-26 14:21:23 +00:00
}
finally
{
2021-07-06 22:57:42 +00:00
BytecodeViewer.updateBusyStatus(false);
}
}
2021-07-14 10:11:59 +00:00
2021-07-14 10:25:02 +00:00
/**
* Imports a file using File-Specific importers/decoders
*/
public static boolean importKnownFile(File file) throws Exception
2021-07-14 10:11:59 +00:00
{
2021-07-14 10:25:02 +00:00
final String fn = FilenameUtils.getName(file.getName()).toLowerCase();
final String extension = fn.contains(":") ? null : FilenameUtils.getExtension(fn);
2021-07-14 10:11:59 +00:00
2021-07-14 10:29:36 +00:00
Import imp = Import.extensionMap.get(extension);
if(imp == null)
return false;
//import/decode the file using the file specific importer
imp.getImporter().open(file);
2021-07-14 10:11:59 +00:00
return true;
}
}