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

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