Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommandLineManager.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.commandlineingest;
20 
21 import java.io.File;
22 import java.nio.file.Paths;
23 import java.util.logging.Level;
28 
32 class CommandLineManager {
33 
34  private static final Logger LOGGER = Logger.getLogger(CommandLineOpenCaseManager.class.getName());
35 
43  Case openCase(String casePath) throws CaseActionException {
44 
45  String metadataFilePath;
46  if (casePath.endsWith(".aut") && (new File(casePath)).isFile()) {
47  LOGGER.log(Level.INFO, "Opening case {0}", casePath);
48  metadataFilePath = casePath;
49  } else {
50  LOGGER.log(Level.INFO, "Opening case in directory {0}", casePath);
51  metadataFilePath = findAutFile(casePath);
52  }
53  Case.openAsCurrentCase(metadataFilePath);
54 
55  Case newCase = Case.getCurrentCase();
56  LOGGER.log(Level.INFO, "Opened case {0}", newCase.getName());
57 
58  return newCase;
59  }
60 
70  private String findAutFile(String caseDirectory) throws CaseActionException {
71  File caseFolder = Paths.get(caseDirectory).toFile();
72  if (caseFolder.exists()) {
73  /*
74  * Search for '*.aut' files.
75  */
76  File[] fileArray = caseFolder.listFiles();
77  if (fileArray == null) {
78  throw new CaseActionException("No files found in case directory");
79  }
80  String autFilePath = null;
81  for (File file : fileArray) {
82  String name = file.getName().toLowerCase();
83  if (autFilePath == null && name.endsWith(getFileExtension())) {
84  return file.getAbsolutePath();
85  }
86  }
87  throw new CaseActionException("No .aut files found in case directory");
88  }
89  throw new CaseActionException("Case directory was not found");
90  }
91 
92 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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