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;
|
2021-07-21 15:20:38 +00:00
|
|
|
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()
|
|
|
|
{
|
2021-07-16 20:55:03 +00:00
|
|
|
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;
|
|
|
|
|
2021-07-18 19:53:30 +00:00
|
|
|
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";
|
|
|
|
|
2021-07-21 15:20:38 +00:00
|
|
|
if (!DialogUtils.canOverwriteFile(path))
|
2021-07-01 21:54:10 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|