Ghidra is a software reverse engineering (SRE) framework
Minor refactor for tool closing bug in extension apps
dragonmacher24532a377dbf
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/StandAloneApplication.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/StandAloneApplication.javaindex 68fd6d10bc..4e8471d484 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/StandAloneApplication.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/StandAloneApplication.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -277,45 +277,46 @@ public abstract class StandAloneApplication implements GenericStandAloneApplicat@Overridepublic ToolServices getToolServices() {- return new ToolServicesAdapter() {+ return new StandAloneToolServices();+ }- @Override- public void closeTool(PluginTool t) {- System.exit(0);- }+ protected static class StandAloneToolServices extends ToolServicesAdapter {- @Override- public void saveTool(PluginTool saveTool) {- Element toolElement = saveTool.saveToXml(true);- Element dataStateElement = saveTool.saveDataStateToXml(false);- Element rootElement = new Element("Root");- rootElement.addContent(toolElement);- rootElement.addContent(dataStateElement);- File savedToolFile =- new File(Application.getUserSettingsDirectory(), SAVED_TOOL_FILE);- OutputStream os = null;+ @Override+ public void closeTool(PluginTool t) {+ System.exit(0);+ }++ @Override+ public void saveTool(PluginTool saveTool) {+ Element toolElement = saveTool.saveToXml(true);+ Element dataStateElement = saveTool.saveDataStateToXml(false);+ Element rootElement = new Element("Root");+ rootElement.addContent(toolElement);+ rootElement.addContent(dataStateElement);+ File savedToolFile =+ new File(Application.getUserSettingsDirectory(), SAVED_TOOL_FILE);+ OutputStream os = null;+ try {+ os = new FileOutputStream(savedToolFile);+ Document doc = new Document(rootElement);+ XMLOutputter xmlout = new GenericXMLOutputter();+ xmlout.output(doc, os);+ os.close();+ }+ catch (Exception e) {+ Msg.error(this, "Error saving tool", e);try {- os = new FileOutputStream(savedToolFile);- Document doc = new Document(rootElement);- XMLOutputter xmlout = new GenericXMLOutputter();- xmlout.output(doc, os);- os.close();- }- catch (Exception e) {- Msg.error(this, "Error saving tool", e);- try {- if (os != null) {- os.close();- }- savedToolFile.delete();- }- catch (Exception exc) {- // cleanup, don't care+ if (os != null) {+ os.close();}+ savedToolFile.delete();+ }+ catch (Exception exc) {+ // cleanup, don't care}-}- };- }+ }+ }}