bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java

56 lines
1.4 KiB
Java
Raw Normal View History

2021-06-27 20:41:38 +00:00
package the.bytecode.club.bytecodeviewer.resources.exporting.impl;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.ExportJar;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.resources.exporting.Exporter;
import the.bytecode.club.bytecodeviewer.util.DialogUtils;
2021-06-27 20:41:38 +00:00
import javax.swing.*;
import java.io.File;
/**
* @author Konloch
* @since 6/27/2021
*/
public class RunnableJarExporter implements Exporter
{
@Override
public void promptForExport()
{
if (BytecodeViewer.promptIfNoLoadedResources())
2021-06-27 20:41:38 +00:00
return;
Thread exportThread = new Thread(() ->
{
2021-07-11 13:55:30 +00:00
if (!BytecodeViewer.autoCompileSuccessful())
2021-06-27 20:41:38 +00:00
return;
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
2021-06-27 20:41:38 +00:00
"Select Jar Export",
"Jar Archives",
"jar");
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
2021-07-19 14:11:14 +00:00
Configuration.setLastSaveDirectory(fc.getSelectedFile());
2021-06-27 20:41:38 +00:00
File file = fc.getSelectedFile();
String path = file.getAbsolutePath();
//auto append .jar
if (!path.endsWith(".jar"))
path = path + ".jar";
if (!DialogUtils.canOverwriteFile(path))
return;
2021-06-27 20:41:38 +00:00
new ExportJar(path).setVisible(true);
}
2021-07-01 09:48:10 +00:00
}, "Runnable Jar Export");
2021-06-27 20:41:38 +00:00
exportThread.start();
}
}