Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageWriterService.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.imagewriter;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.openide.DialogDescriptor;
24 import org.openide.DialogDisplayer;
25 import org.openide.NotifyDescriptor;
26 import org.openide.util.NbBundle;
27 import org.openide.util.lookup.ServiceProvider;
28 import org.openide.util.lookup.ServiceProviders;
31 
32 @ServiceProviders(value = {@ServiceProvider(service = AutopsyService.class)})
33 
41 public class ImageWriterService implements AutopsyService {
42 
43  private static final List<ImageWriter> imageWriters = new ArrayList<>(); // Contains all Image Writer objects
44  private static final Object imageWritersLock = new Object(); // Get this lock before accessing currentImageWriters
45 
50  public static void createImageWriter(Long imageId, ImageWriterSettings settings){
51 
52  // ImageWriter objects are created during the addImageTask. They can not arrive while
53  // we're closing case resources so we don't need to worry about one showing up while
54  // doing our close/cleanup.
55  synchronized(imageWritersLock){
56  ImageWriter writer = new ImageWriter(imageId, settings);
57  writer.subscribeToEvents();
58  imageWriters.add(writer);
59  }
60  }
61 
62  @Override
63  public String getServiceName() {
64  return NbBundle.getMessage(this.getClass(), "ImageWriterService.serviceName");
65  }
66 
67  @Override
69  context.getProgressIndicator().progress(NbBundle.getMessage(this.getClass(), "ImageWriterService.waitingForVHDs"));
70 
71  synchronized(imageWritersLock){
72  // If any of our ImageWriter objects haven't started the finish task, set the cancel flag
73  // to make sure they don't start now. The reason they haven't started is that
74  // ingest was not complete, and the user already confirmed that they want to exit
75  // even though ingest is not complete so we will take that to mean that they
76  // also don't want to wait for Image Writer.
77  for(ImageWriter writer: imageWriters){
78  writer.cancelIfNotStarted();
79  }
80 
81  // Test whether any finishImage tasks are in progress
82  boolean jobsAreInProgress = false;
83  for(ImageWriter writer: imageWriters){
84  if(writer.jobIsInProgress()){
85  jobsAreInProgress = true;
86  break;
87  }
88  }
89 
90  if(jobsAreInProgress){
91  // If jobs are in progress, ask the user if they want to wait for them to complete
92  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
93  NbBundle.getMessage(this.getClass(), "ImageWriterService.shouldWait"),
94  NbBundle.getMessage(this.getClass(), "ImageWriterService.localDisk"),
95  NotifyDescriptor.YES_NO_OPTION,
96  NotifyDescriptor.WARNING_MESSAGE);
97  descriptor.setValue(NotifyDescriptor.NO_OPTION);
98  Object response = DialogDisplayer.getDefault().notify(descriptor);
99 
100  if(response == DialogDescriptor.NO_OPTION){
101  // Cancel all the jobs
102  for(ImageWriter writer: imageWriters){
103  writer.cancelJob();
104  }
105  }
106 
107  // Wait for all finishImage jobs to complete. If the jobs got cancelled
108  // this will be very fast.
109  for(ImageWriter writer: imageWriters){
110  writer.waitForJobToFinish();
111  }
112 
113  }
114 
115  // Stop listening for events
116  for(ImageWriter writer: imageWriters){
117  writer.unsubscribeFromEvents();
118  }
119 
120  // Clear out the list of Image Writers
121  imageWriters.clear();
122  }
123  }
124 }
static void createImageWriter(Long imageId, ImageWriterSettings settings)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.