GP-4057 Corrected ProjectLocator bug and corrected use of various

directory preferences to varefy directory existance.
This commit is contained in:
ghidra1 2023-11-20 16:35:20 -05:00
parent bb4a9ccbb1
commit af160d946d
14 changed files with 66 additions and 30 deletions

View File

@ -394,9 +394,9 @@ public class RestoreDialog extends ReusableDialogComponentProvider {
jarFileChooser.setTitle("Restore a Ghidra Project - Archive");
String lastDirSelected = Preferences.getProperty(ArchivePlugin.LAST_ARCHIVE_DIR);
if (lastDirSelected != null) {
File file = new File(lastDirSelected);
if (file.exists()) {
jarFileChooser.setCurrentDirectory(file);
File dir = new File(lastDirSelected);
if (dir.isDirectory()) {
jarFileChooser.setCurrentDirectory(dir);
}
}
File jarFile = null;

View File

@ -261,9 +261,9 @@ public class ExportToHeaderAction extends DockingAction {
String lastDirSelected = Preferences.getProperty(LAST_DATA_TYPE_EXPORT_DIRECTORY);
if (lastDirSelected != null) {
File file = new File(lastDirSelected);
if (file.exists()) {
fileChooser.setCurrentDirectory(file);
File dir = new File(lastDirSelected);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}

View File

@ -94,7 +94,10 @@ public class ExportPatternFileActionListener implements ActionListener {
gFileChooser.setFileFilter(xmlFilter);
String baseDir = Preferences.getProperty(XML_EXPORT_DIR_PROPERTY);
if (baseDir != null) {
gFileChooser.setCurrentDirectory(new File(baseDir));
File dir = new File(baseDir);
if (dir.isDirectory()) {
gFileChooser.setCurrentDirectory(dir);
}
}
gFileChooser.setTitle("Select Export File");
File outFile = gFileChooser.getSelectedFile();

View File

@ -233,7 +233,10 @@ public class FunctionBitPatternsMainProvider extends ComponentProviderAdapter
fileChooser.setTitle("Select Directory Containing XML Files");
String baseDir = Preferences.getProperty(PATTERN_INFO_DIR);
if (baseDir != null) {
fileChooser.setCurrentDirectory(new File(baseDir));
File dir = new File(baseDir);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}
File xmlDir = fileChooser.getSelectedFile();
fileChooser.dispose();

View File

@ -64,7 +64,10 @@ public class ImportPatternFileActionListener implements ActionListener {
fileChooser.setTitle("Select Pattern File");
String baseDir = Preferences.getProperty(XML_IMPORT_DIR_PROPERTY);
if (baseDir != null) {
fileChooser.setCurrentDirectory(new File(baseDir));
File dir = new File(baseDir);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}
ExtensionFileFilter xmlFilter = new ExtensionFileFilter("xml", "XML Files");
fileChooser.setFileFilter(xmlFilter);

View File

@ -932,9 +932,11 @@ public class KeyBindingUtils {
private static File getStartingDir() {
String lastDirectoryPath = Preferences.getProperty(LAST_KEY_BINDING_EXPORT_DIRECTORY);
if (lastDirectoryPath != null) {
return new File(lastDirectoryPath);
File dir = new File(lastDirectoryPath);
if (dir.isDirectory()) {
return dir;
}
}
return new File(System.getProperty("user.home"));
}

View File

@ -310,9 +310,12 @@ public class PathManager {
}
});
}
String dir = Preferences.getProperty(preferenceForLastSelectedDir);
if (dir != null) {
fileChooser.setCurrentDirectory(new File(dir));
String dirPath = Preferences.getProperty(preferenceForLastSelectedDir);
if (dirPath != null) {
File dir = new File(dirPath);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}
List<File> files = fileChooser.getSelectedFiles();

View File

@ -312,9 +312,12 @@ public class PathnameTablePanel extends JPanel {
}
});
}
String dir = Preferences.getProperty(preferenceForLastSelectedDir);
if (dir != null) {
fileChooser.setCurrentDirectory(new File(dir));
String dirPath = Preferences.getProperty(preferenceForLastSelectedDir);
if (dirPath != null) {
File dir = new File(dirPath);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}
List<File> files = fileChooser.getSelectedFiles();

View File

@ -137,15 +137,22 @@ class SelectProjectPanel extends AbstractWizardJPanel {
directoryField = new JTextField(25);
directoryField.setName("Project Directory");
String lastDirSelected = Preferences.getProperty(Preferences.LAST_NEW_PROJECT_DIRECTORY);
if (lastDirSelected != null) {
directoryField.setText(lastDirSelected);
File projectDirectory = null;
String projectDirPath = Preferences.getProperty(Preferences.LAST_NEW_PROJECT_DIRECTORY);
if (projectDirPath != null) {
// if it exists, use last directory where project was created
projectDirectory = new File(projectDirPath);
if (!projectDirectory.isDirectory()) {
projectDirectory = null;
}
}
else {
File projectDirectory = new File(GenericRunInfo.getProjectsDirPath());
directoryField.setText(projectDirectory.getAbsolutePath());
if (projectDirectory == null) {
// otherwise, use last project directory or default
projectDirectory = new File(GenericRunInfo.getProjectsDirPath());
}
directoryField.setCaretPosition(directoryField.getText().length() - 1);
projectDirPath = projectDirectory.getAbsolutePath();
directoryField.setText(projectDirPath);
directoryField.setCaretPosition(projectDirPath.length() - 1);
JLabel projectNameLabel = new GDLabel("Project Name:", SwingConstants.RIGHT);
projectNameField = new JTextField(25);
projectNameField.setName("Project Name");

View File

@ -423,7 +423,10 @@ class ToolActionManager implements ToolChestChangeListener {
String importDir = Preferences.getProperty(Preferences.LAST_TOOL_IMPORT_DIRECTORY);
if (importDir != null) {
fileChooser.setCurrentDirectory(new File(importDir));
File dir = new File(importDir);
if (dir.isDirectory()) {
fileChooser.setCurrentDirectory(dir);
}
}
fileChooser.rescanCurrentDirectory();

View File

@ -125,8 +125,8 @@ public class ProjectLocator {
scanIndex = 4;
}
checkInvalidChar("path", path, scanIndex);
if (!path.endsWith(File.separator)) {
path += File.separator;
if (!path.endsWith("/")) {
path += "/";
}
return path;
}

View File

@ -394,7 +394,10 @@ public class SaveToolConfigDialog extends DialogComponentProvider implements Lis
new ExtensionFileFilter(new String[] { "gif", "jpg", "bmp", "png" }, "Image Files"));
String iconDir = Preferences.getProperty(LAST_ICON_DIRECTORY);
if (iconDir != null) {
chooser.setCurrentDirectory(new File(iconDir));
File dir = new File(iconDir);
if (dir.isDirectory()) {
chooser.setCurrentDirectory(dir);
}
}
File file = chooser.getSelectedFile();
chooser.dispose();

View File

@ -145,7 +145,10 @@ class ToolServicesImpl implements ToolServices {
String exportDir = Preferences.getProperty(Preferences.LAST_TOOL_EXPORT_DIRECTORY);
if (exportDir != null) {
newFileChooser.setCurrentDirectory(new File(exportDir));
File dir = new File(exportDir);
if (dir.isDirectory()) {
newFileChooser.setCurrentDirectory(dir);
}
}
newFileChooser.setTitle("Export Tool");

View File

@ -401,7 +401,10 @@ public class SpecExtensionPanel extends JPanel {
private static File getStartingDir() {
String lastDirectoryPath = Preferences.getProperty(LAST_EXPORT_DIRECTORY);
if (lastDirectoryPath != null) {
return new File(lastDirectoryPath);
File dir = new File(lastDirectoryPath);
if (dir.isDirectory()) {
return dir;
}
}
return new File(System.getProperty("user.home"));