mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-16 17:57:43 +00:00
2197 added duplicate profile name detection
This commit is contained in:
parent
a818e0be7a
commit
96fb0438c7
@ -22,29 +22,33 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
||||
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
|
||||
|
||||
class IngestProfileList {
|
||||
class IngestProfileMap {
|
||||
|
||||
private static final String PROFILE_FOLDER = "Profiles";
|
||||
private static final String PROFILE_NAME_KEY = "Profile_Name";
|
||||
private static final String PROFILE_DESC_KEY = "Profile_Description";
|
||||
private static final String PROFILE_FILTER_KEY = "Profile_Filter";
|
||||
private List<IngestProfile> profileList = null;
|
||||
private TreeMap<String, IngestProfile> profileMap = null;
|
||||
private static final Object PROFILE_LOCK = new Object();
|
||||
|
||||
List<IngestProfile> getIngestProfileList() {
|
||||
if (profileList == null) {
|
||||
/**
|
||||
* Gets the collection of profiles which currently exist.
|
||||
*
|
||||
* @return profileList
|
||||
*/
|
||||
TreeMap<String, IngestProfile> getIngestProfileMap() {
|
||||
if (profileMap == null) {
|
||||
loadProfileList();
|
||||
}
|
||||
return profileList;
|
||||
return profileMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,17 +59,15 @@ class IngestProfileList {
|
||||
File dir = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER).toFile();
|
||||
File[] directoryListing = dir.listFiles();
|
||||
|
||||
profileMap = new TreeMap<>();
|
||||
if (directoryListing != null) {
|
||||
profileList = new ArrayList<>();
|
||||
for (File child : directoryListing) {
|
||||
String name = child.getName().split("\\.")[0];
|
||||
String context = PROFILE_FOLDER + File.separator + name;
|
||||
String desc = ModuleSettings.getConfigSetting(context, PROFILE_DESC_KEY);
|
||||
String fileIngestFilter = ModuleSettings.getConfigSetting(context, PROFILE_FILTER_KEY);
|
||||
profileList.add(new IngestProfile(name, desc, fileIngestFilter));
|
||||
profileMap.put(name, new IngestProfile(name, desc, fileIngestFilter));
|
||||
}
|
||||
} else {
|
||||
profileList = Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,21 +79,12 @@ class IngestProfileList {
|
||||
readFilesFromDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of profiles which currently exist.
|
||||
*
|
||||
* @return profileList
|
||||
*/
|
||||
List<IngestProfile> getProfileList() {
|
||||
return this.profileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the list of profiles which currently exist to disk.
|
||||
*/
|
||||
void saveProfileList() {
|
||||
//save last used profile
|
||||
for (IngestProfile profile : getIngestProfileList()) {
|
||||
for (IngestProfile profile : getIngestProfileMap().values()) {
|
||||
IngestProfile.saveProfile(profile);
|
||||
}
|
||||
}
|
@ -19,10 +19,11 @@
|
||||
package org.sleuthkit.autopsy.ingest;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.TreeMap;
|
||||
import org.openide.DialogDisplayer;
|
||||
import org.openide.NotifyDescriptor;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfileList.IngestProfile;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile;
|
||||
|
||||
/**
|
||||
* Panel to display options for profile creation.
|
||||
@ -60,6 +61,9 @@ public class ProfilePanel extends IngestModuleGlobalSettingsPanel {
|
||||
jPanel1.add(ingestSettingsPanel, 0);
|
||||
}
|
||||
|
||||
String getProfileName(){
|
||||
return profileNameField.getText();
|
||||
}
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
@ -183,6 +187,7 @@ public class ProfilePanel extends IngestModuleGlobalSettingsPanel {
|
||||
DialogDisplayer.getDefault().notify(notifyDesc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.sleuthkit.autopsy.ingest;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
@ -26,7 +27,8 @@ import javax.swing.event.ListSelectionListener;
|
||||
import org.netbeans.spi.options.OptionsPanelController;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfileList.IngestProfile;
|
||||
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
||||
import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile;
|
||||
import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
|
||||
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
|
||||
|
||||
@ -41,7 +43,8 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
|
||||
"ProfileSettingsPanel.newProfileButton.text=New Profile",
|
||||
"ProfileSettingsPanel.editProfileButton.text=Edit Profile",
|
||||
"ProfileSettingsPanel.deleteProfileButton.text=Delete Profile",
|
||||
"ProfileSettingsPanel.messages.filterLoadFailed=Failed to load file ingest filter"
|
||||
"ProfileSettingsPanel.messages.filterLoadFailed=Failed to load file ingest filter",
|
||||
"ProfileSettingsPanel.doFileSetsDialog.duplicateProfile.text=Profile with name {0} already exists."
|
||||
})
|
||||
|
||||
private final DefaultListModel<IngestProfile> profilesListModel = new DefaultListModel<>();
|
||||
@ -311,6 +314,15 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
|
||||
option = JOptionPane.showConfirmDialog(null, panel, Bundle.ProfileSettingsPanel_title(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
||||
} while (option == JOptionPane.OK_OPTION && !panel.isValidDefinition());
|
||||
|
||||
TreeMap<String, IngestProfile> profileMap = new IngestProfileMap().getIngestProfileMap();
|
||||
|
||||
if (profileMap.containsKey(panel.getProfileName()) && selectedProfile == null) {
|
||||
MessageNotifyUtil.Message.error(NbBundle.getMessage(this.getClass(),
|
||||
"ProfileSettingsPanel.doFileSetsDialog.duplicateProfile.text",
|
||||
panel.getProfileName()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
panel.saveSettings();
|
||||
load();
|
||||
@ -335,9 +347,8 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
|
||||
public void load() {
|
||||
int currentIndex = profileList.getSelectedIndex();
|
||||
profilesListModel.clear();
|
||||
IngestProfileList iList = new IngestProfileList();
|
||||
iList.loadProfileList();
|
||||
for (IngestProfile profile : iList.getProfileList()) {
|
||||
IngestProfileMap profileMap = new IngestProfileMap();
|
||||
for (IngestProfile profile : profileMap.getIngestProfileMap().values()) {
|
||||
profilesListModel.addElement(profile);
|
||||
}
|
||||
if (newProfileButton.isEnabled()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user