Java Code Examples for ghidra.program.model.listing.Program#unlock()

The following examples show how to use ghidra.program.model.listing.Program#unlock() . 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 File: ProgramSaveManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the given program for changes and performs the save if necessary.  The user
 * is prompted before the save is performed.
 * @param program program to be closed
 * @return true if the program can be closed, or false if the operation was cancelled by
 * the user
 */
boolean canClose(Program program) {
	if (program == null ||
		(program.getDomainFile().getConsumers().size() > 1 && !tool.hasToolListeners())) {
		return true;
	}
	if (acquireSaveLock(program, "Close")) {
		try {
			return handleChangedProgram(program);
		}
		finally {
			program.unlock();
		}
	}
	return false;
}
 
Example 2
Source File: ProgramSaveManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void saveAs(Program program) {
	if (!getSaveAsLock(program)) {
		return;
	}
	try {
		DataTreeDialog dialog = getSaveDialog();
		String filename = program.getDomainFile().getName();
		dialog.setTitle("Save As (" + filename + ")");
		dialog.setNameText(filename + ".1");
		dialog.setSelectedFolder(program.getDomainFile().getParent());
		treeDialogCancelled = true;
		tool.showDialog(dialog);
		if (!treeDialogCancelled) {
			saveAs(program, dialog.getDomainFolder(), dialog.getNameText());
		}
	}
	finally {
		program.unlock();
	}
}
 
Example 3
Source File: ProgramSaveManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
boolean canCloseAll() {
		Program[] programs = programMgr.getAllOpenPrograms();
		List<Program> saveList = new ArrayList<>();
		List<Program> lockList = new ArrayList<>();
		try {
			for (int i = 0; i < programs.length; i++) {
//				if (programs[i].isTemporary()) {
//					continue;
//				}
				if (isOnlyToolConsumer(programs[i])) {
					if (!acquireSaveLock(programs[i], "Close")) {
						return false;
					}
					lockList.add(programs[i]);
					saveList.add(programs[i]);
				}
				else if (isAnalysisTool(programs[i])) {
					if (!acquireSaveLock(programs[i], "Close")) {
						return false;
					}
					lockList.add(programs[i]);
				}
			}

			return saveChangedPrograms(saveList);
		}
		finally {
			Iterator<Program> it = lockList.iterator();
			while (it.hasNext()) {
				Program p = it.next();
				p.unlock();
			}
		}
	}
 
Example 4
Source File: ProgramSaveManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void save(Program program) {

		tool.prepareToSave(program);
		if (acquireSaveLock(program, "Save")) {

			try {
				SaveFileTask task = new SaveFileTask(program.getDomainFile());
				new TaskLauncher(task, tool.getToolFrame());
			}
			finally {
				program.unlock();
			}
		}
	}