19 package org.sleuthkit.autopsy.logicalimager.configuration;
21 import com.google.gson.Gson;
22 import com.google.gson.GsonBuilder;
23 import com.google.gson.JsonIOException;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.util.Arrays;
30 import java.util.List;
31 import java.util.logging.Level;
32 import javax.swing.JOptionPane;
33 import javax.swing.event.ChangeListener;
34 import org.apache.commons.io.FileUtils;
35 import org.openide.WizardDescriptor;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
43 final class ConfigWizardPanel2
implements WizardDescriptor.Panel<WizardDescriptor> {
45 private static final Logger LOGGER = Logger.
getLogger(ConfigWizardPanel2.class.getName());
51 private ConfigVisualPanel2 component;
52 private String configFilename;
53 private LogicalImagerConfig config;
60 public ConfigVisualPanel2 getComponent() {
61 if (component == null) {
62 component =
new ConfigVisualPanel2();
68 public HelpCtx getHelp() {
70 return HelpCtx.DEFAULT_HELP;
76 public boolean isValid() {
86 public void readSettings(WizardDescriptor wiz) {
88 configFilename = (String) wiz.getProperty(
"configFilename");
89 config = (LogicalImagerConfig) wiz.getProperty(
"config");
90 component.setConfiguration(configFilename, config, (
boolean) wiz.getProperty(
"newFile"));
94 public void storeSettings(WizardDescriptor wiz) {
99 "# {0} - configFilename",
100 "ConfigWizardPanel2.failedToSaveConfigMsg=Failed to save configuration file: {0}",
102 "ConfigWizardPanel2.reason=\nReason: ",
103 "ConfigWizardPanel2.failedToSaveExeMsg=Failed to save tsk_logical_imager.exe file",
105 void saveConfigFile() {
106 GsonBuilder gsonBuilder =
new GsonBuilder()
108 .excludeFieldsWithoutExposeAnnotation()
109 .disableHtmlEscaping();
110 Gson gson = gsonBuilder.create();
111 String toJson = gson.toJson(config);
113 List<String> lines = Arrays.asList(toJson.split(
"\\n"));
114 FileUtils.writeLines(
new File(configFilename),
"UTF-8", lines, System.getProperty(
"line.separator"));
115 }
catch (IOException ex) {
116 JOptionPane.showMessageDialog(component, Bundle.ConfigWizardPanel2_failedToSaveConfigMsg(configFilename)
117 + Bundle.ConfigWizardPanel2_reason(ex.getMessage()));
118 }
catch (JsonIOException jioe) {
119 LOGGER.log(Level.SEVERE,
"Failed to save configuration file: " + configFilename, jioe);
120 JOptionPane.showMessageDialog(component, Bundle.ConfigWizardPanel2_failedToSaveConfigMsg(configFilename)
121 + Bundle.ConfigWizardPanel2_reason(jioe.getMessage()));
124 writeTskLogicalImagerExe(Paths.get(configFilename).getParent());
125 }
catch (IOException ex) {
126 LOGGER.log(Level.SEVERE,
"Failed to save tsk_logical_imager.exe file", ex);
127 JOptionPane.showMessageDialog(component, Bundle.ConfigWizardPanel2_failedToSaveExeMsg()
128 + Bundle.ConfigWizardPanel2_reason(ex.getMessage()));
132 private void writeTskLogicalImagerExe(Path destDir)
throws IOException {
133 try (InputStream in = getClass().getResourceAsStream(
"tsk_logical_imager.exe")) {
134 File destFile = Paths.get(destDir.toString(),
"tsk_logical_imager.exe").toFile();
135 FileUtils.copyInputStreamToFile(in, destFile);
140 public void addChangeListener(ChangeListener cl) {
145 public void removeChangeListener(ChangeListener cl) {
synchronized static Logger getLogger(String name)