Autopsy  4.21.0
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 2022 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.modules.hashdatabase.infrastructure;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Paths;
24 import java.util.logging.Level;
25 import org.apache.commons.io.FileUtils;
26 import org.openide.modules.ModuleInstall;
27 import org.python.icu.text.MessageFormat;
31 
35 public class Installer extends ModuleInstall {
36 
37  private static final String LEGACY_SERIALIZATION_XML_FILE_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "hashsets.xml").toString();
38  private static final String LEGACY_SERIALIZATION_FILE_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "hashLookup.settings").toString(); //NON-NLS
39  private static final String LEGACY_HASH_DATABASE_DEFAULT_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), "HashDatabases").toString();
40 
41  private static final Logger logger = Logger.getLogger(Installer.class.getName());
42  private static final long serialVersionUID = 1L;
43  private static Installer instance;
44 
53  public synchronized static Installer getDefault() {
54  if (instance == null) {
55  instance = new Installer();
56  }
57  return instance;
58  }
59 
65  private Installer() {
66  super();
67  }
68 
69  @Override
70  public void restored() {
71  // copy user dir hash dbs from legacy to new if old path exists and new does not.
72  File legacyDbPath = new File(LEGACY_HASH_DATABASE_DEFAULT_PATH);
73  File dbPath = new File(HashConfigPaths.getInstance().getDefaultDbPath());
74  if (legacyDbPath.exists() && !dbPath.exists()) {
75  try {
76  dbPath.getParentFile().mkdirs();
77  FileUtils.copyDirectory(legacyDbPath, dbPath);
78  } catch (IOException ex) {
79  logger.log(Level.WARNING, MessageFormat.format("There was an error copying legacy path hash dbs from {0} to {1}", legacyDbPath, dbPath), ex);
80  }
81  }
82 
83  // copy hash db settings to new location.
84  File legacySettingsFile = new File(LEGACY_SERIALIZATION_FILE_PATH);
85  File settingsFile = new File(HashConfigPaths.getInstance().getSettingsPath());
86  if (legacySettingsFile.exists() && !settingsFile.exists()) {
87  try {
88  settingsFile.getParentFile().mkdirs();
89  FileUtils.copyFile(legacySettingsFile, settingsFile);
90  } catch (IOException ex) {
91  logger.log(Level.WARNING, MessageFormat.format("There was an error copying legacy hash db settings from {0} to {1}", legacySettingsFile, settingsFile), ex);
92  }
93  }
94 
95  File legacyXmlSettingsFile = new File(LEGACY_SERIALIZATION_XML_FILE_PATH);
96  File xmlSettingsFile = new File(HashConfigPaths.getInstance().getXmlSettingsPath());
97  if (legacyXmlSettingsFile.exists() && !xmlSettingsFile.exists()) {
98  try {
99  xmlSettingsFile.getParentFile().mkdirs();
100  FileUtils.copyFile(legacyXmlSettingsFile, xmlSettingsFile);
101  } catch (IOException ex) {
102  logger.log(Level.WARNING, MessageFormat.format("There was an error copying legacy xml hash db settings from {0} to {1}", legacyXmlSettingsFile, xmlSettingsFile), ex);
103  }
104  }
105 
107  }
108 
109 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.