Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddLocalFilesTask.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2016 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.casemodule;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.openide.util.NbBundle;
26 import org.sleuthkit.datamodel.AbstractFile;
27 import org.sleuthkit.datamodel.Content;
29 import org.sleuthkit.datamodel.LocalFilesDataSource;
30 import org.sleuthkit.datamodel.TskCoreException;
31 import org.sleuthkit.datamodel.TskDataException;
32 
38 class AddLocalFilesTask implements Runnable {
39 
40  private final String deviceId;
41  private final String rootVirtualDirectoryName;
42  private final List<String> localFilePaths;
43  private final DataSourceProcessorProgressMonitor progress;
44  private final DataSourceProcessorCallback callback;
45 
68  AddLocalFilesTask(String deviceId, String rootVirtualDirectoryName, List<String> localFilePaths, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback) {
69  this.deviceId = deviceId;
70  this.rootVirtualDirectoryName = rootVirtualDirectoryName;
71  this.localFilePaths = localFilePaths;
72  this.callback = callback;
73  this.progress = progressMonitor;
74  }
75 
81  @Override
82  public void run() {
83  List<Content> newDataSources = new ArrayList<>();
84  List<String> errors = new ArrayList<>();
85  try {
86  progress.setIndeterminate(true);
87  FileManager fileManager = Case.getCurrentCase().getServices().getFileManager();
88  LocalFilesDataSource newDataSource = fileManager.addLocalFilesDataSource(deviceId, rootVirtualDirectoryName, "", localFilePaths, new ProgressUpdater());
89  newDataSources.add(newDataSource.getRootDirectory());
90  } catch (TskDataException | TskCoreException ex) {
91  errors.add(ex.getMessage());
92  } finally {
93  DataSourceProcessorCallback.DataSourceProcessorResult result;
94  if (!errors.isEmpty()) {
95  result = DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS;
96  } else {
97  result = DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS;
98  }
99  callback.done(result, errors, newDataSources);
100  }
101  }
102 
107  private class ProgressUpdater implements FileManager.FileAddProgressUpdater {
108 
109  private int count;
110 
115  @Override
116  public void fileAdded(final AbstractFile file) {
117  ++count;
118  if (count % 10 == 0) {
119  progress.setProgressText(NbBundle.getMessage(this.getClass(),
120  "AddLocalFilesTask.localFileAdd.progress.text",
121  file.getParentPath(),
122  file.getName()));
123  }
124  }
125  }
126 }

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