Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
Installer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 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.core;
20 
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Handler;
25 import java.util.logging.Level;
26 import javafx.application.Platform;
27 import javafx.embed.swing.JFXPanel;
28 import org.openide.modules.ModuleInstall;
29 import org.openide.util.NbBundle;
30 import org.openide.windows.WindowManager;
34 
39 public class Installer extends ModuleInstall {
40 
41  private final List<ModuleInstall> packageInstallers;
42  private static final Logger logger = Logger.getLogger(Installer.class.getName());
43  private static volatile boolean javaFxInit = false;
44 
45  static {
47  }
48 
49  private static void loadDynLibraries() {
50  /* On Windows, we distribute dlls that libtsk_jni depend on.
51  * If libtsk_jni tries to load them, they will not be found by
52  * Windows because they are in special NetBeans folders. So, we
53  * manually load them from within Autopsy so that they are found
54  * via the NetBeans loading setup. These are copied by the build
55  * script when making the ZIP file. In a development environment
56  * they will need to be loaded from standard places in your system.
57  *
58  * On non-Windows platforms, we assume the dependncies are all installed
59  * and loadable (i.e. a 'make install' was done).
60  */
61  if (PlatformUtil.isWindowsOS()) {
62  try {
63  //Note: if shipping with a different CRT version, this will only print a warning
64  //and try to use linker mechanism to find the correct versions of libs.
65  //We should update this if we officially switch to a new version of CRT/compiler
66  System.loadLibrary("msvcr100"); //NON-NLS
67  System.loadLibrary("msvcp100"); //NON-NLS
68  logger.log(Level.INFO, "MS CRT libraries loaded"); //NON-NLS
69  } catch (UnsatisfiedLinkError e) {
70  logger.log(Level.SEVERE, "Error loading ms crt libraries, ", e); //NON-NLS
71  }
72 
73  try {
74  System.loadLibrary("zlib"); //NON-NLS
75  logger.log(Level.INFO, "ZLIB library loaded loaded"); //NON-NLS
76  } catch (UnsatisfiedLinkError e) {
77  logger.log(Level.SEVERE, "Error loading ZLIB library, ", e); //NON-NLS
78  }
79 
80  try {
81  System.loadLibrary("libewf"); //NON-NLS
82  logger.log(Level.INFO, "EWF library loaded"); //NON-NLS
83  } catch (UnsatisfiedLinkError e) {
84  logger.log(Level.SEVERE, "Error loading EWF library, ", e); //NON-NLS
85  }
86  }
87  }
88 
89  public Installer() {
90  logger.log(Level.INFO, "core installer created"); //NON-NLS
91  javaFxInit = false;
92  packageInstallers = new ArrayList<>();
93  packageInstallers.add(org.sleuthkit.autopsy.coreutils.Installer.getDefault());
94  packageInstallers.add(org.sleuthkit.autopsy.corecomponents.Installer.getDefault());
95  packageInstallers.add(org.sleuthkit.autopsy.datamodel.Installer.getDefault());
96  packageInstallers.add(org.sleuthkit.autopsy.ingest.Installer.getDefault());
97  }
98 
103  public static boolean isJavaFxInited() {
104  return javaFxInit;
105  }
106 
107  private static void initJavaFx() {
108  //initialize java fx if exists
109  System.setProperty("javafx.macosx.embedded", "true");
110  try {
111  // Creating a JFXPanel initializes JavaFX
112  new JFXPanel();
113  Platform.setImplicitExit(false);
114  javaFxInit = true;
115  } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
116  //in case javafx not present
117  final String msg = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.msg");
118  final String details = NbBundle.getMessage(Installer.class, "Installer.errorInitJavafx.details");
119  logger.log(Level.SEVERE, msg
120  + details, e);
121 
122  WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
123  @Override
124  public void run() {
125  MessageNotifyUtil.Notify.error(msg, details);
126  }
127  });
128  }
129  }
130 
131  private static void ensurePythonModulesFolderExists() {
132  File pythonModulesDir = new File(PlatformUtil.getUserPythonModulesPath());
133  pythonModulesDir.mkdir();
134  }
135 
136  @Override
137  public void restored() {
138  super.restored();
140  initJavaFx();
141  for (ModuleInstall mi : packageInstallers) {
142  try {
143  mi.restored();
144  logger.log(Level.INFO, "{0} restore succeeded", mi.getClass().getName()); //NON-NLS
145  } catch (Exception e) {
146  String msg = mi.getClass().getName() + " restore failed"; //NON-NLS
147  logger.log(Level.WARNING, msg, e);
148  }
149  }
150  logger.log(Level.INFO, "Autopsy Core restore completed"); //NON-NLS
151  }
152 
153  @Override
154  public void validate() throws IllegalStateException {
155  super.validate();
156 
157  logger.log(Level.INFO, "validate()"); //NON-NLS
158  for (ModuleInstall mi : packageInstallers) {
159  logger.log(Level.INFO, "{0} validate()", mi.getClass().getName()); //NON-NLS
160  try {
161  mi.validate();
162  } catch (Exception e) {
163  logger.log(Level.WARNING, "", e);
164  }
165  }
166  }
167 
168  @Override
169  public void uninstalled() {
170  super.uninstalled();
171 
172  logger.log(Level.INFO, "uninstalled()"); //NON-NLS
173 
174  for (ModuleInstall mi : packageInstallers) {
175  logger.log(Level.INFO, "{0} uninstalled()", mi.getClass().getName()); //NON-NLS
176  try {
177  mi.uninstalled();
178  } catch (Exception e) {
179  logger.log(Level.WARNING, "", e);
180  }
181  }
182  }
183 
184  @Override
185  public void close() {
186  super.close();
187 
188  logger.log(Level.INFO, "close()"); //NON-NLS
189 
190  //exit JavaFx plat
191  if (javaFxInit) {
192  Platform.exit();
193  }
194 
195  for (ModuleInstall mi : packageInstallers) {
196  logger.log(Level.INFO, "{0} close()", mi.getClass().getName()); //NON-NLS
197  try {
198  mi.close();
199  } catch (Exception e) {
200  logger.log(Level.WARNING, "", e);
201  }
202  }
203  for (Handler h : logger.getHandlers()) {
204  h.close(); //must call h.close or a .LCK file will remain.
205  }
206  }
207 }
static synchronized Installer getDefault()
Definition: Installer.java:49
static volatile boolean javaFxInit
Definition: Installer.java:43
static synchronized Installer getDefault()
Definition: Installer.java:38
static synchronized Installer getDefault()
Definition: Installer.java:31
final List< ModuleInstall > packageInstallers
Definition: Installer.java:41
static Logger getLogger(String name)
Definition: Logger.java:131
static synchronized Installer getDefault()
Definition: Installer.java:35

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.