Saving After Actions

This commit is contained in:
Konloch 2021-07-01 02:06:12 -07:00
parent 5175316002
commit 373fc38ad2
4 changed files with 40 additions and 15 deletions

View file

@ -215,7 +215,7 @@ public class BytecodeViewer
* @param cli is it running CLI mode or not * @param cli is it running CLI mode or not
*/ */
public static void boot(boolean cli) { public static void boot(boolean cli) {
cleanup(); cleanupAsync();
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
for (Process proc : createdProcesses) for (Process proc : createdProcesses)
proc.destroy(); proc.destroy();
@ -523,10 +523,14 @@ public class BytecodeViewer
*/ */
public static void openFiles(final File[] files, boolean recentFiles) { public static void openFiles(final File[] files, boolean recentFiles) {
if (recentFiles) if (recentFiles)
{
for (File f : files) for (File f : files)
if (f.exists()) if (f.exists())
Settings.addRecentFile(f); Settings.addRecentFile(f);
SettingsSerializer.saveSettingsAsync();
}
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
Configuration.needsReDump = true; Configuration.needsReDump = true;
Thread t = new Thread(new ImportResource(files)); Thread t = new Thread(new ImportResource(files));
@ -588,7 +592,17 @@ public class BytecodeViewer
/** /**
* Clears the temp directory * Clears the temp directory
*/ */
public static void cleanup() { public static void cleanupAsync()
{
Thread cleanupThread = new Thread(BytecodeViewer::cleanup);
cleanupThread.start();
}
/**
* Clears the temp directory
*/
public static void cleanup()
{
File tempF = new File(tempDirectory); File tempF = new File(tempDirectory);
try { try {

View file

@ -62,7 +62,8 @@ public class FernFlowerDecompiler extends InternalDecompiler
} }
@Override @Override
public String decompileClassNode(final ClassNode cn, byte[] b) { public String decompileClassNode(final ClassNode cn, byte[] b)
{
String start = tempDirectory + fs + MiscUtils.getUniqueName("", ".class"); String start = tempDirectory + fs + MiscUtils.getUniqueName("", ".class");
final File tempClass = new File(start + ".class"); final File tempClass = new File(start + ".class");
@ -99,7 +100,7 @@ public class FernFlowerDecompiler extends InternalDecompiler
} else { } else {
try { try {
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath())); org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler.main(generateMainMethod(tempClass.getAbsolutePath(), new File(tempDirectory).getAbsolutePath()));
} catch (StackOverflowError | Exception e) { } catch (Throwable e) {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(new PrintWriter(sw));
e.printStackTrace(); e.printStackTrace();

View file

@ -407,7 +407,7 @@ public class MainViewerGUI extends JFrame
{ {
Configuration.rstaTheme = t; Configuration.rstaTheme = t;
item.setSelected(true); item.setSelected(true);
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
}); });
rstaThemes.put(t, item); rstaThemes.put(t, item);
@ -429,7 +429,7 @@ public class MainViewerGUI extends JFrame
Configuration.rstaTheme = theme.getRSTATheme(); Configuration.rstaTheme = theme.getRSTATheme();
rstaThemes.get(Configuration.rstaTheme).setSelected(true); rstaThemes.get(Configuration.rstaTheme).setSelected(true);
item.setSelected(true); item.setSelected(true);
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
try try
{ {
@ -457,7 +457,7 @@ public class MainViewerGUI extends JFrame
item.addActionListener(e -> item.addActionListener(e ->
{ {
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
MiscUtils.setLanguage(l); MiscUtils.setLanguage(l);
}); });
@ -566,7 +566,7 @@ public class MainViewerGUI extends JFrame
bytecodeDecompilerSettingsSecondaryMenu.add(appendBracketsToLabels); bytecodeDecompilerSettingsSecondaryMenu.add(appendBracketsToLabels);
deleteForeignOutdatedLibs.addActionListener(arg0 -> showForeignLibraryWarning()); deleteForeignOutdatedLibs.addActionListener(arg0 -> showForeignLibraryWarning());
forcePureAsciiAsText.addActionListener(arg0 -> SettingsSerializer.saveSettings()); forcePureAsciiAsText.addActionListener(arg0 -> SettingsSerializer.saveSettingsAsync());
setPython2.addActionListener(arg0 -> selectPythonC()); setPython2.addActionListener(arg0 -> selectPythonC());
setJRERT.addActionListener(arg0 -> selectJRERTLibrary()); setJRERT.addActionListener(arg0 -> selectJRERTLibrary());
setPython3.addActionListener(arg0 -> selectPythonC3()); setPython3.addActionListener(arg0 -> selectPythonC3());
@ -574,12 +574,12 @@ public class MainViewerGUI extends JFrame
setJavac.addActionListener(arg0 -> selectJavac()); setJavac.addActionListener(arg0 -> selectJavac());
showFileInTabTitle.addActionListener(arg0 -> { showFileInTabTitle.addActionListener(arg0 -> {
Configuration.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected(); Configuration.displayParentInTab = BytecodeViewer.viewer.showFileInTabTitle.isSelected();
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
BytecodeViewer.refreshAllTabTitles(); BytecodeViewer.refreshAllTabTitles();
}); });
simplifyNameInTabTitle.addActionListener(arg0 -> { simplifyNameInTabTitle.addActionListener(arg0 -> {
Configuration.simplifiedTabNames = BytecodeViewer.viewer.simplifyNameInTabTitle.isSelected(); Configuration.simplifiedTabNames = BytecodeViewer.viewer.simplifyNameInTabTitle.isSelected();
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
BytecodeViewer.refreshAllTabTitles(); BytecodeViewer.refreshAllTabTitles();
}); });
} }
@ -736,11 +736,14 @@ public class MainViewerGUI extends JFrame
public synchronized void clearBusyStatus() public synchronized void clearBusyStatus()
{ {
for (int i = 0; i < waitIcons.length; i++) SwingUtilities.invokeLater(()->
{ {
waitIcons[i].setIcon(null); for (JMenuItem waitIcon : waitIcons)
waitIcons[i].updateUI(); {
} waitIcon.setIcon(null);
waitIcon.updateUI();
}
});
} }
public synchronized void updateBusyStatus(final boolean busy) { public synchronized void updateBusyStatus(final boolean busy) {
@ -866,6 +869,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python = fc.getSelectedFile().getAbsolutePath(); Configuration.python = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -882,6 +886,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.javac = fc.getSelectedFile().getAbsolutePath(); Configuration.javac = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -898,6 +903,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.java = fc.getSelectedFile().getAbsolutePath(); Configuration.java = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -914,6 +920,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.python3 = fc.getSelectedFile().getAbsolutePath(); Configuration.python3 = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -934,6 +941,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.library = fc.getSelectedFile().getAbsolutePath(); Configuration.library = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -950,6 +958,7 @@ public class MainViewerGUI extends JFrame
try { try {
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.rt = fc.getSelectedFile().getAbsolutePath(); Configuration.rt = fc.getSelectedFile().getAbsolutePath();
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
} }
@ -970,6 +979,7 @@ public class MainViewerGUI extends JFrame
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
BytecodeViewer.startPlugin(fc.getSelectedFile()); BytecodeViewer.startPlugin(fc.getSelectedFile());
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.viewer.updateBusyStatus(false);
SettingsSerializer.saveSettingsAsync();
} catch (Exception e1) { } catch (Exception e1) {
new ExceptionUI(e1); new ExceptionUI(e1);
} }

View file

@ -197,7 +197,7 @@ public class ClassViewer extends ResourceViewer
+ "test or export your changes.\nYou can set compile automatically on refresh or on save " + "test or export your changes.\nYou can set compile automatically on refresh or on save "
+ "in the settings menu."); + "in the settings menu.");
SettingsSerializer.saveSettings(); SettingsSerializer.saveSettingsAsync();
} }
} }
} }