mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Minor refactor for tool closing bug in extension apps
This commit is contained in:
parent
a63b39d14f
commit
24532a377d
1 changed files with 42 additions and 41 deletions
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -277,45 +277,46 @@ public abstract class StandAloneApplication implements GenericStandAloneApplicat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ToolServices getToolServices() {
|
public ToolServices getToolServices() {
|
||||||
return new ToolServicesAdapter() {
|
return new StandAloneToolServices();
|
||||||
|
|
||||||
@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 {
|
|
||||||
if (os != null) {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
savedToolFile.delete();
|
|
||||||
}
|
|
||||||
catch (Exception exc) {
|
|
||||||
// cleanup, don't care
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static class StandAloneToolServices extends ToolServicesAdapter {
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
if (os != null) {
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
savedToolFile.delete();
|
||||||
|
}
|
||||||
|
catch (Exception exc) {
|
||||||
|
// cleanup, don't care
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue