Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ConfigWizardPanel2.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.logicalimager.configuration;
20 
21 import com.google.gson.Gson;
22 import com.google.gson.GsonBuilder;
23 import com.google.gson.JsonIOException;
24 import java.io.File;
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;
39 
43 final class ConfigWizardPanel2 implements WizardDescriptor.Panel<WizardDescriptor> {
44 
45  private static final Logger LOGGER = Logger.getLogger(ConfigWizardPanel2.class.getName());
46 
51  private ConfigVisualPanel2 component;
52  private String configFilename;
53  private LogicalImagerConfig config;
54 
55  // Get the visual component for the panel. In this template, the component
56  // is kept separate. This can be more efficient: if the wizard is created
57  // but never displayed, or not all panels are displayed, it is better to
58  // create only those which really need to be visible.
59  @Override
60  public ConfigVisualPanel2 getComponent() {
61  if (component == null) {
62  component = new ConfigVisualPanel2();
63  }
64  return component;
65  }
66 
67  @Override
68  public HelpCtx getHelp() {
69  // Show no Help button for this panel:
70  return HelpCtx.DEFAULT_HELP;
71  // If you have context help:
72  // return new HelpCtx("help.key.here");
73  }
74 
75  @Override
76  public boolean isValid() {
77  // If it is always OK to press Next or Finish, then:
78  return true;
79  // If it depends on some condition (form filled out...) and
80  // this condition changes (last form field filled in...) then
81  // use ChangeSupport to implement add/removeChangeListener below.
82  // WizardDescriptor.ERROR/WARNING/INFORMATION_MESSAGE will also be useful.
83  }
84 
85  @Override
86  public void readSettings(WizardDescriptor wiz) {
87  // use wiz.getProperty to retrieve previous panel state
88  configFilename = (String) wiz.getProperty("configFilename"); // NON-NLS
89  config = (LogicalImagerConfig) wiz.getProperty("config"); // NON-NLS
90  component.setConfiguration(configFilename, config, (boolean) wiz.getProperty("newFile"));
91  }
92 
93  @Override
94  public void storeSettings(WizardDescriptor wiz) {
95  // use wiz.putProperty to remember current panel state
96  }
97 
98  @NbBundle.Messages({
99  "# {0} - configFilename",
100  "ConfigWizardPanel2.failedToSaveConfigMsg=Failed to save configuration file: {0}",
101  "# {0} - reason",
102  "ConfigWizardPanel2.reason=\nReason: ",
103  "ConfigWizardPanel2.failedToSaveExeMsg=Failed to save tsk_logical_imager.exe file",
104  })
105  void saveConfigFile() {
106  GsonBuilder gsonBuilder = new GsonBuilder()
107  .setPrettyPrinting()
108  .excludeFieldsWithoutExposeAnnotation()
109  .disableHtmlEscaping();
110  Gson gson = gsonBuilder.create();
111  String toJson = gson.toJson(config);
112  try {
113  List<String> lines = Arrays.asList(toJson.split("\\n"));
114  FileUtils.writeLines(new File(configFilename), "UTF-8", lines, System.getProperty("line.separator")); // NON-NLS
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); // NON-NLS
120  JOptionPane.showMessageDialog(component, Bundle.ConfigWizardPanel2_failedToSaveConfigMsg(configFilename)
121  + Bundle.ConfigWizardPanel2_reason(jioe.getMessage()));
122  }
123  try {
124  writeTskLogicalImagerExe(Paths.get(configFilename).getParent());
125  } catch (IOException ex) {
126  LOGGER.log(Level.SEVERE, "Failed to save tsk_logical_imager.exe file", ex); // NON-NLS
127  JOptionPane.showMessageDialog(component, Bundle.ConfigWizardPanel2_failedToSaveExeMsg()
128  + Bundle.ConfigWizardPanel2_reason(ex.getMessage()));
129  }
130  }
131 
132  private void writeTskLogicalImagerExe(Path destDir) throws IOException {
133  try (InputStream in = getClass().getResourceAsStream("tsk_logical_imager.exe")) { // NON-NLS
134  File destFile = Paths.get(destDir.toString(), "tsk_logical_imager.exe").toFile(); // NON-NLS
135  FileUtils.copyInputStreamToFile(in, destFile);
136  }
137  }
138 
139  @Override
140  public void addChangeListener(ChangeListener cl) {
141  // Not used
142  }
143 
144  @Override
145  public void removeChangeListener(ChangeListener cl) {
146  // Not used
147  }
148 
149 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.