Java Code Examples for docking.widgets.filechooser.GhidraFileChooser

The following examples show how to use docking.widgets.filechooser.GhidraFileChooser. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExportTool() throws Exception {

	// export using the menu action
	createTool();

	DockingActionIf exportAction = getAction("Untitled", "Export Tool");
	performAction(exportAction, "Untitled", false);
	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, exportFile);

	pressButtonByText(chooser, "Export");
	waitForSwing();
	assertTrue(exportFile.exists());
}
 
Example 2
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExportToolOverwriteCancel() throws Exception {
	// export using the menu action
	createTool();

	DockingActionIf exportAction = getAction("Untitled", "Export Tool");
	performAction(exportAction, "Untitled", false);
	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, exportFile);
	pressButtonByText(chooser, "Export");
	waitForSwing();

	performAction(exportAction, "Untitled", false);

	chooser = waitForDialogComponent(GhidraFileChooser.class);
	setSelectedFile(chooser, exportFile);

	JButton b = findButtonByText(chooser, "Export");
	pressButton(b, false);
	OptionDialog optD = waitForDialogComponent(OptionDialog.class);
	assertNotNull(optD);
	assertEquals("Overwrite?", optD.getTitle());

	pressButtonByText(optD.getComponent(), "Cancel");
}
 
Example 3
Source Project: ghidra   Source File: PathnameTablePanelTest.java    License: Apache License 2.0 6 votes vote down vote up
private void selectFromFileChooser() throws Exception {
	final GhidraFileChooser fileChooser = waitForDialogComponent(GhidraFileChooser.class);
	assertNotNull(fileChooser);

	JButton chooseButton = findButtonByText(fileChooser, "OK");
	assertNotNull(chooseButton);

	//JTextField filenameTextField = (JTextField)findComponentByName(fileChooser.getComponent(), "filenameTextField");
	//setJTextField(filenameTextField, "fred.h");
	runSwing(() -> fileChooser.setSelectedFile(
		new File(fileChooser.getCurrentDirectory(), "fred.h")));

	waitForUpdateOnChooser(fileChooser);

	pressButton(chooseButton, true);
	waitForPostedSwingRunnables();
}
 
Example 4
Source Project: ghidra   Source File: KeyBindingUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static File getFileFromUser(File startingDir) {
	KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	Component activeComponent = kfm.getActiveWindow();
	GhidraFileChooser fileChooser = new GhidraFileChooser(activeComponent);
	fileChooser.setTitle("Please Select A File");
	fileChooser.setFileFilter(FILE_FILTER);
	fileChooser.setApproveButtonText("OK");
	fileChooser.setCurrentDirectory(startingDir);

	File selectedFile = fileChooser.getSelectedFile();

	// make sure the file has the correct extension
	if ((selectedFile != null) &&
		!selectedFile.getName().endsWith(PREFERENCES_FILE_EXTENSION)) {
		selectedFile = new File(selectedFile.getAbsolutePath() + PREFERENCES_FILE_EXTENSION);
	}

	// save off the last location to which the user navigated so we can
	// return them to that spot if they user the dialog again.
	Preferences.setProperty(LAST_KEY_BINDING_EXPORT_DIRECTORY,
		fileChooser.getCurrentDirectory().getAbsolutePath());

	return selectedFile;
}
 
Example 5
Source Project: ghidra   Source File: SaveImageAction.java    License: Apache License 2.0 6 votes vote down vote up
private static File getExportFile() {

		GhidraFileChooser chooser = new GhidraFileChooser(null);
		chooser.setTitle("Export Image As...");
		chooser.setApproveButtonText("Save As");
		chooser.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);
		chooser.setMultiSelectionEnabled(false);

		File selected = chooser.getSelectedFile(true);

		if (chooser.wasCancelled()) {
			return null;
		}

		return selected;

	}
 
Example 6
Source Project: ghidra   Source File: GTable.java    License: Apache License 2.0 6 votes vote down vote up
private File chooseExportFile() {
	GhidraFileChooser chooser = createExportFileChooser();
	File file = chooser.getSelectedFile();
	if (file == null) {
		return null;
	}
	if (file.exists()) {
		int result = OptionDialog.showYesNoDialog(GTable.this, "Overwrite?",
			"File exists. Do you want to overwrite?");

		if (result != OptionDialog.OPTION_ONE) {
			return null;
		}
	}
	storeLastExportDirectory(file);
	return file;
}
 
Example 7
Source Project: ghidra   Source File: AbstractDockingTest.java    License: Apache License 2.0 6 votes vote down vote up
public static void waitForUpdateOnChooser(GhidraFileChooser chooser) throws Exception {
	// make sure swing has handled any pending changes
	waitForSwing();

	// Use an artificially high wait period that won't be reached most of the time.  We
	// need this because file choosers use the native filesystem, which can have 'hiccups'
	int timeoutMillis = PRIVATE_LONG_WAIT_TIMEOUT;
	int totalTime = 0;
	while (pendingUpdate(chooser) && (totalTime < timeoutMillis)) {
		Thread.sleep(DEFAULT_WAIT_DELAY);
		totalTime += DEFAULT_WAIT_DELAY;
	}

	if (totalTime >= timeoutMillis) {
		Assert.fail("Timed-out waiting for directory to load");
	}

	// make sure swing has handled any pending changes
	waitForSwing();
}
 
Example 8
Source Project: ghidra   Source File: DebugDecompilerAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void decompilerActionPerformed(DecompilerActionContext context) {
	JComponent parentComponent = context.getDecompilerPanel();
	GhidraFileChooser fileChooser = new GhidraFileChooser(parentComponent);
	fileChooser.setTitle("Please Choose Output File");
	fileChooser.setFileFilter(new ExtensionFileFilter(new String[] { "xml" }, "XML Files"));
	File file = fileChooser.getSelectedFile();
	if (file == null) {
		return;
	}
	if (file.exists()) {
		if (OptionDialog.showYesNoDialog(parentComponent, "Overwrite Existing File?",
			"Do you want to overwrite the existing file?") == OptionDialog.OPTION_TWO) {
			return;
		}
	}
	controller.setStatusMessage("Dumping debug info to " + file.getAbsolutePath());
	controller.refreshDisplay(controller.getProgram(), controller.getLocation(), file);
}
 
Example 9
Source Project: ghidra   Source File: PopulateFidDialog.java    License: Apache License 2.0 6 votes vote down vote up
private JComponent buildSymbolsFileField() {
		JPanel panel = new JPanel(new BorderLayout());
		symbolsFileTextField = new JTextField();
		panel.add(symbolsFileTextField, BorderLayout.CENTER);
		JButton browseButton = createBrowseButton();
		browseButton.addActionListener(e -> {
			GhidraFileChooser chooser = new GhidraFileChooser(tool.getToolFrame());
			chooser.setTitle("Choose Common Symbols File");
			chooser.setFileSelectionMode(GhidraFileChooser.FILES_ONLY);
//			chooser.setFileFilter(null);
			File selectedFile = chooser.getSelectedFile();
			if (selectedFile != null) {
				symbolsFileTextField.setText(selectedFile.getAbsolutePath());
			}
		});
		symbolsFileTextField.getDocument().addUndoableEditListener(e -> updateOkEnablement());
		panel.add(browseButton, BorderLayout.EAST);
		return panel;
	}
 
Example 10
Source Project: ghidra   Source File: GraphExporterDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void chooseDestinationFile() {
	GhidraFileChooser chooser = new GhidraFileChooser(getComponent());
	chooser.setSelectedFile(getLastExportDirectory());
	chooser.setTitle("Select Output File");
	chooser.setApproveButtonText("Select Output File");
	chooser.setApproveButtonToolTipText("Select File");
	chooser.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);

	chooser.setSelectedFileFilter(GhidraFileFilter.ALL);
	GraphExportFormat exporter = getSelectedExporter();
	if (exporter != null) {
		chooser.setFileFilter(
			new ExtensionFileFilter(exporter.getDefaultFileExtension(), exporter.toString()));
	}
	String filePath = filePathTextField.getText().trim();
	File currentFile = filePath.isEmpty() ? null : new File(filePath);
	if (currentFile != null) {
		chooser.setSelectedFile(currentFile);
	}
	File file = chooser.getSelectedFile();
	if (file != null) {
		setLastExportDirectory(file);
		filePathTextField.setText(file.getAbsolutePath());
	}
}
 
Example 11
Source Project: ghidra   Source File: ExporterDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void chooseDestinationFile() {
	GhidraFileChooser chooser = new GhidraFileChooser(getComponent());
	chooser.setSelectedFile(getLastExportDirectory());
	chooser.setTitle("Select Output File");
	chooser.setApproveButtonText("Select Output File");
	chooser.setApproveButtonToolTipText("Select File");
	chooser.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);

	chooser.setSelectedFileFilter(GhidraFileFilter.ALL);
	Exporter exporter = getSelectedExporter();
	if (exporter != null && exporter.getDefaultFileExtension() != null) {
		chooser.setFileFilter(
			new ExtensionFileFilter(exporter.getDefaultFileExtension(), exporter.getName()));
	}
	String filePath = filePathTextField.getText().trim();
	File currentFile = filePath.isEmpty() ? null : new File(filePath);
	if (currentFile != null) {
		chooser.setSelectedFile(currentFile);
	}
	File file = chooser.getSelectedFile();
	if (file != null) {
		setLastExportDirectory(file);
		filePathTextField.setText(file.getAbsolutePath());
	}
}
 
Example 12
Source Project: ghidra   Source File: GhidraScriptAskMethodsTest.java    License: Apache License 2.0 6 votes vote down vote up
private void waitForUpdateOnDirectory(GhidraFileChooser chooser) throws Exception {
	// make sure swing has handled any pending changes
	waitForSwing();

	// artificially high wait period that won't be reached most of the time
	int timeoutMillis = TIMEOUT_MILLIS;
	int totalTime = 0;

	while (hasPendingUpdate(chooser) && (totalTime < timeoutMillis)) {
		Thread.sleep(50);
		totalTime += 50;
	}

	if (totalTime >= timeoutMillis) {
		Assert.fail("Timed-out waiting for directory to load");
	}

	// make sure swing has handled any pending changes
	waitForSwing();
}
 
Example 13
Source Project: ghidra   Source File: AbstractCreateArchiveTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void waitForUpdateOnDirectory(GhidraFileChooser chooser) throws Exception {
	// make sure swing has handled any pending changes
	waitForPostedSwingRunnables();

	// artificially high wait period that won't be reached most of the time
	int timeoutMillis = 5000;
	int totalTime = 0;
	while (chooserIsPendingUpdate(chooser) && (totalTime < timeoutMillis)) {
		Thread.sleep(50);
		totalTime += 50;
	}

	if (totalTime >= timeoutMillis) {
		Assert.fail("Timed-out waiting for directory to load");
	}

	// make sure swing has handled any pending changes
	waitForPostedSwingRunnables();
}
 
Example 14
Source Project: ghidra   Source File: StructureEditorArchiveTest.java    License: Apache License 2.0 6 votes vote down vote up
private void createNewArchive(String archiveName, boolean deleteExisting) throws Exception {
	File archiveFile = new File(getTestDirectoryPath(), archiveName);
	if (deleteExisting) {
		archiveFile.delete();
	}

	final DockingActionIf action = getAction(plugin, "New File Data Type Archive");

	DataTypeTestUtils.performAction(action, dtTree, false);

	GhidraFileChooser chooser =
		waitForDialogComponent(tool.getToolFrame(), GhidraFileChooser.class, 10000);
	assertNotNull("Never found chooser!", chooser);
	selectFileInChooser(chooser, archiveFile);

	// hit "Create Archive" button
	JButton saveAsButton = findButtonByText(chooser, "Create Archive");
	pressButton(saveAsButton);
	waitForPostedSwingRunnables();

}
 
Example 15
Source Project: ghidra   Source File: OptionsDialogTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFileChooserEditor() throws Exception {

	ScrollableOptionsEditor editor = showOptions(ToolConstants.TOOL_OPTIONS);

	pressBrowseButton(editor, "My PathName");

	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);
	assertNotNull(chooser);
	assertEquals("Choose Path", chooser.getTitle());

	File file = createTempFile("MyFile.txt");
	file.deleteOnExit();
	writeTempFile(file.getAbsolutePath());
	runSwing(() -> chooser.setSelectedFile(file));
	waitForUpdateOnChooser(chooser);

	JButton openButton = findButtonByText(chooser, "Choose Path");
	pressButton(openButton);
	waitForSwing();

	JTextField pathField = getEditorTextField(editor, "My PathName");
	assertEquals(file.getAbsolutePath(), pathField.getText());
}
 
Example 16
Source Project: ghidra   Source File: ToolSaving3Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExportDefaultTool() throws Exception {

	//
	// Verify a 'default' tool does not contain 'config state' when written
	//

	PluginTool tool1 = launchTool(DEFAULT_TEST_TOOL_NAME);
	DockingActionIf exportAction = getAction(tool1, "Export Default Tool");
	performAction(exportAction, false);

	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);
	File exportedFile = createTempFile("ExportedDefaultTool", ToolUtils.TOOL_EXTENSION);
	chooser.setSelectedFile(exportedFile);
	waitForUpdateOnChooser(chooser);
	pressButtonByText(chooser, "Export");

	OptionDialog overwriteDialog = waitForDialogComponent(OptionDialog.class);
	pressButtonByText(overwriteDialog, "Overwrite");
	waitForCondition(() -> exportedFile.length() > 0);

	assertExportedFileDoesNotContainsLine(exportedFile, "PLUGIN_STATE");
}
 
Example 17
Source Project: ghidra   Source File: ToolSaving3Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExportedToolContainsConfigSettings() throws Exception {

	//
	// Regression test: ensure that an exported tool contains config settings
	//

	PluginTool tool1 = launchTool(DEFAULT_TEST_TOOL_NAME);
	DockingActionIf exportAction = getAction(tool1, "Export Tool");
	performAction(exportAction, false);

	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);
	File exportedFile = createTempFile("ExportedTool", ToolUtils.TOOL_EXTENSION);
	chooser.setSelectedFile(exportedFile);
	waitForUpdateOnChooser(chooser);
	pressButtonByText(chooser, "Export");

	OptionDialog overwriteDialog = waitForDialogComponent(OptionDialog.class);
	pressButtonByText(overwriteDialog, "Overwrite");
	waitForCondition(() -> exportedFile.length() > 0);

	assertExportedFileContainsLine(exportedFile, "PLUGIN_STATE");
}
 
Example 18
Source Project: dragondance   Source File: DragonHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String askFile(Component parent, String title, String okButtonText) {
	
	GhidraFileChooser gfc = new GhidraFileChooser(parent);
	
	if (!Globals.LastFileDialogPath.isEmpty()) {
		File def = new File(Globals.LastFileDialogPath);
		gfc.setSelectedFile(def);
	}
	
	gfc.setTitle(title);
	gfc.setApproveButtonText(okButtonText);
	gfc.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);
	
	File file = gfc.getSelectedFile();
	
	if (file == null) {
		return null;
	}
	
	if (!file.exists())
		return null;
	
	Globals.LastFileDialogPath =  Util.getDirectoryOfFile(file.getAbsolutePath());
	
	if (Globals.LastFileDialogPath == null)
		Globals.LastFileDialogPath = System.getProperty("user.dir");
	
	return file.getAbsolutePath();
}
 
Example 19
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testImportTool() throws Exception {
	// action for import a tool
	final ToolChest tc = frontEndTool.getToolServices().getToolChest();
	int count = tc.getToolCount();

	String toolNamePrefix = "TestCodeBrowser";
	final File cbFile = ResourceManager.getResourceFile(
		"defaultTools/" + toolNamePrefix + ToolUtils.TOOL_EXTENSION);
	assertNotNull(cbFile);

	DockingActionIf importAction = getAction("Import Tool");
	performAction(importAction, false);

	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, cbFile);

	pressButtonByText(chooser, "Import");
	waitForSwing();
	assertEquals(count + 1, tc.getToolCount());

	ToolTemplate[] configs = tc.getToolTemplates();
	final ArrayList<String> list = new ArrayList<>();
	for (ToolTemplate config : configs) {
		if (config.getName().startsWith(toolNamePrefix + "_")) {
			list.add(config.getName());
		}
	}
	assertTrue(list.size() > 0);
	Collections.sort(list);
	runSwing(() -> tc.remove(list.get(list.size() - 1)));
}
 
Example 20
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExportToolOverwrite() throws Exception {
	// export using the menu action
	createTool();

	DockingActionIf exportAction = getAction("Untitled", "Export Tool");
	performAction(exportAction, "Untitled", false);
	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, exportFile);
	pressButtonByText(chooser, "Export");
	waitForSwing();

	performAction(exportAction, "Untitled", false);
	chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, exportFile);
	JButton b = findButtonByText(chooser, "Export");
	pressButton(b, false);
	OptionDialog optD = waitForDialogComponent(OptionDialog.class);
	assertNotNull(optD);
	assertEquals("Overwrite?", optD.getTitle());

	pressButtonByText(optD.getComponent(), "Overwrite");
	waitForSwing();
	assertTrue(exportFile.exists());
}
 
Example 21
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExportToolOverwriteNo() throws Exception {
	// export using the menu action
	createTool();

	DockingActionIf exportAction = getAction("Untitled", "Export Tool");
	performAction(exportAction, "Untitled", false);
	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);

	setSelectedFile(chooser, exportFile);
	pressButtonByText(chooser, "Export");
	waitForSwing();

	performAction(exportAction, "Untitled", false);

	chooser = waitForDialogComponent(GhidraFileChooser.class);
	setSelectedFile(chooser, exportFile);

	JButton b = findButtonByText(chooser, "Export");
	pressButton(b, false);
	waitForSwing();

	OptionDialog optD = waitForDialogComponent(OptionDialog.class);
	assertNotNull(optD);
	assertEquals("Overwrite?", optD.getTitle());

	pressButtonByText(optD.getComponent(), "Cancel");
	chooser = waitForDialogComponent(GhidraFileChooser.class);
	pressButtonByText(chooser, "Cancel");
}
 
Example 22
Source Project: ghidra   Source File: ToolActionManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExportToolFromIcon() throws Exception {
	createTool();

	DockingActionIf exportAction = getAction("Export Tool");
	performToolButtonAction(exportAction, "Untitled", false, false);
	GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);
	setSelectedFile(chooser, exportFile);

	pressButtonByText(chooser, "Export");
	waitForSwing();
	assertTrue(exportFile.exists());
}
 
Example 23
Source Project: ghidra   Source File: ImporterPluginScreenShots.java    License: Apache License 2.0 5 votes vote down vote up
private ImporterDialog selectFileForImport(String fileToImport) throws Exception {
	GhidraFileChooser fileChooser = waitForDialogComponent(GhidraFileChooser.class);

	File testDataFile = getTestDataFile(fileToImport);
	fileChooser.setSelectedFile(testDataFile);
	waitForUpdateOnChooser(fileChooser);

	pressButtonByName(fileChooser.getComponent(), "OK");

	ImporterDialog importerDialog = waitForDialogComponent(ImporterDialog.class);
	assertNotNull(importerDialog);
	return importerDialog;
}
 
Example 24
Source Project: ghidra   Source File: ImporterPluginScreenShots.java    License: Apache License 2.0 5 votes vote down vote up
private BatchImportDialog selectDirForBatchImport(String rootDir) throws Exception {
	GhidraFileChooser fileChooser = waitForDialogComponent(GhidraFileChooser.class);

	File testDataFile = getTestDataDir("pe");
	fileChooser.setSelectedFile(testDataFile);
	waitForUpdateOnChooser(fileChooser);

	pressButtonByName(fileChooser.getComponent(), "OK");

	BatchImportDialog dialog = waitForDialogComponent(BatchImportDialog.class);
	assertNotNull(dialog);
	return dialog;
}
 
Example 25
Source Project: ghidra   Source File: FrontEndPluginScreenShots.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testViewOtherProjects()
		throws IOException, LockException, InvalidNameException, CancelledException {
	ProjectTestUtils.deleteProject(TEMP_DIR, OTHER_PROJECT);
	Project project = env.getProject();
	program = env.getProgram("WinHelloCPP.exe");
	ProjectData projectData = project.getProjectData();
	projectData.getRootFolder().createFile("HelloCpp.exe", program, TaskMonitor.DUMMY);

	project.close();

	Project otherProject = ProjectTestUtils.getProject(TEMP_DIR, OTHER_PROJECT);

	Language language = getZ80_LANGUAGE();
	ProjectTestUtils.createProgramFile(otherProject, "Program1", language,
		language.getDefaultCompilerSpec(), null);
	ProjectTestUtils.createProgramFile(otherProject, "Program2", language,
		language.getDefaultCompilerSpec(), null);

	otherProject.close();
	waitForSwing();
	project = ProjectTestUtils.getProject(TEMP_DIR, PROJECT_NAME);

	performAction("View Project", "FrontEndPlugin", false);
	final GhidraFileChooser fileChooser = (GhidraFileChooser) getDialog();
	runSwing(() -> fileChooser.setSelectedFile(new File(TEMP_DIR, OTHER_PROJECT)));
	pressButtonOnDialog("Select Project");
	setToolSize(500, 600);
	captureToolWindow(700, 600);

	ProjectTestUtils.deleteProject(TEMP_DIR, OTHER_PROJECT);
	ProjectTestUtils.deleteProject(TEMP_DIR, OTHER_PROJECT);

}
 
Example 26
Source Project: ghidra   Source File: GTable.java    License: Apache License 2.0 5 votes vote down vote up
private GhidraFileChooser createExportFileChooser() {
	GhidraFileChooser chooser = new GhidraFileChooser(GTable.this);
	chooser.setTitle(GTableToCSV.TITLE);
	chooser.setApproveButtonText("OK");

	String filepath = Preferences.getProperty(LAST_EXPORT_FILE);
	if (filepath != null) {
		chooser.setSelectedFile(new File(filepath));
	}

	return chooser;
}
 
Example 27
Source Project: ghidra   Source File: ToolServicesImpl.java    License: Apache License 2.0 5 votes vote down vote up
private File chooseToolFile(ToolTemplate tool) {
	GhidraFileChooser fileChooser = getFileChooser();

	File exportFile = null;
	while (exportFile == null) {
		exportFile = fileChooser.getSelectedFile(); // show the chooser
		if (exportFile == null) {
			return null; // user cancelled
		}

		Preferences.setProperty(Preferences.LAST_TOOL_EXPORT_DIRECTORY, exportFile.getParent());
		if (!exportFile.getName().endsWith(ToolUtils.TOOL_EXTENSION)) {
			exportFile = new File(exportFile.getAbsolutePath() + ToolUtils.TOOL_EXTENSION);
		}

		if (exportFile.exists()) {
			int result = OptionDialog.showOptionDialog(null, "Overwrite?",
				"Overwrite existing file: '" + exportFile.getName() + "'?", "Overwrite",
				OptionDialog.QUESTION_MESSAGE);
			if (result != OptionDialog.OPTION_ONE) {
				exportFile = null; // user chose not to overwrite
			}
		}
	}

	return exportFile;
}
 
Example 28
Source Project: ghidra   Source File: ToolServicesImpl.java    License: Apache License 2.0 5 votes vote down vote up
private GhidraFileChooser getFileChooser() {
	GhidraFileChooser newFileChooser = new GhidraFileChooser(null);
	newFileChooser.setFileFilter(new GhidraFileFilter() {
		@Override
		public boolean accept(File file, GhidraFileChooserModel model) {
			if (file == null) {
				return false;
			}

			if (file.isDirectory()) {
				return true;
			}

			return file.getAbsolutePath().toLowerCase().endsWith("tool");
		}

		@Override
		public String getDescription() {
			return "Tools";
		}
	});

	String exportDir = Preferences.getProperty(Preferences.LAST_TOOL_EXPORT_DIRECTORY);
	if (exportDir != null) {
		newFileChooser.setCurrentDirectory(new File(exportDir));
	}

	newFileChooser.setTitle("Export Tool");
	newFileChooser.setApproveButtonText("Export");

	return newFileChooser;
}
 
Example 29
Source Project: ghidra   Source File: EditActionManager.java    License: Apache License 2.0 5 votes vote down vote up
private GhidraFileChooser createCertFileChooser() {

		GhidraFileChooser fileChooser = new GhidraFileChooser(tool.getToolFrame());
		fileChooser.setTitle("Select Certificate (req'd for PKI authentication only)");
		fileChooser.setApproveButtonText("Set Certificate");
		fileChooser.setFileFilter(ApplicationKeyManagerFactory.CERTIFICATE_FILE_FILTER);
		fileChooser.setFileSelectionMode(GhidraFileChooser.FILES_ONLY);
		fileChooser.setHelpLocation(new HelpLocation(plugin.getName(), "Set_PKI_Certificate"));
		return fileChooser;
	}
 
Example 30
Source Project: ghidra   Source File: SaveToolConfigDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Pop up a file chooser for the user to look for icon images.
 */
private void browseForIcons() {
	GhidraFileChooser iconFileChooser = new GhidraFileChooser(getComponent());
	iconFileChooser.setFileSelectionMode(GhidraFileChooser.FILES_ONLY);
	iconFileChooser.setTitle("Choose Icon");
	iconFileChooser.setApproveButtonToolTipText("Choose Icon");
	iconFileChooser.setFileFilter(
		new ExtensionFileFilter(new String[] { "gif", "jpg", "bmp", "png" }, "Image Files"));
	String iconDir = Preferences.getProperty(LAST_ICON_DIRECTORY);
	if (iconDir != null) {
		iconFileChooser.setCurrentDirectory(new File(iconDir));
	}
	File file = iconFileChooser.getSelectedFile();
	if (file == null) {
		return;
	}

	String filename = file.getAbsolutePath();
	iconField.setText(filename);

	ToolIconURL url = new ToolIconURL(filename);
	iconListModel.addElement(url);
	iconList.setSelectedValue(url, true);
	setPicture(url);

	Preferences.setProperty(LAST_ICON_DIRECTORY, file.getParent());
}