Fixed bug that prevented Ghidra from reopening with an empty project

This commit is contained in:
dragonmacher
2026-05-28 16:28:59 -04:00
parent 3f8fd55f18
commit b2e71dd242
2 changed files with 28 additions and 13 deletions

View File

@@ -78,7 +78,8 @@ public interface ProjectManager {
/**
* Set the projectLocator of last opened (active) project; this projectLocator is returned
* in the getLastOpenedProject() method.
* @param projectLocator project location of last project that was opened
* @param projectLocator project location of last project that was opened. A null value signals
* that the user closed the project.
*/
public void setLastOpenedProject(ProjectLocator projectLocator);
@@ -125,7 +126,7 @@ public interface ProjectManager {
public boolean deleteProject(ProjectLocator projectLocator);
/**
* Returns true if a project with the given projectLocator exists.
* {@return true if a project with the given projectLocator exists}
* @param projectLocator project location
*/
public boolean projectExists(ProjectLocator projectLocator);
@@ -141,13 +142,13 @@ public interface ProjectManager {
boolean forceConnect);
/**
* Get the information that was last used to access a repository
* managed by a Ghidra server.
* {@return the information that was last used to access a repository managed by a Ghidra
* server}
*/
public ServerInfo getMostRecentServerInfo();
/**
* Return the user's ToolChest
* {@return the user's ToolChest}
*/
public ToolChest getUserToolChest();

View File

@@ -21,6 +21,7 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -54,6 +55,8 @@ public class DefaultProjectManager implements ProjectManager {
private static final String VIEWED_PROJECTS = "ViewedProjects";
private static final String SERVER_INFO = "ServerInfo";
private static final int RECENT_PROJECTS_LIMIT = 6;
private static final String PROJECT_CLOSED_BY_USER_VALUE = "PROJECT_CLOSED;NO_PROJECT_OPEN";
private static String PROJECT_PATH_SEPARATOR = ";";
private List<ProjectLocator> recentlyOpenedProjectsList;
@@ -186,20 +189,26 @@ public class DefaultProjectManager implements ProjectManager {
@Override
public ProjectLocator getLastOpenedProject() {
String projectPath = Preferences.getProperty(LAST_OPENED_PROJECT, null, true);
if (projectPath == null || projectPath.trim().length() == 0) {
if (StringUtils.isBlank(projectPath)) {
return null;
}
if (PROJECT_CLOSED_BY_USER_VALUE.equals(projectPath)) {
return null;
}
return getLocatorFromProjectPath(projectPath);
}
/**
* Update the last opened project preference.
*/
@Override
public void setLastOpenedProject(ProjectLocator projectLocator) {
Preferences.setProperty(LAST_OPENED_PROJECT,
projectLocator != null ? projectLocator.toString() : null);
String value = PROJECT_CLOSED_BY_USER_VALUE;
if (projectLocator != null) {
value = projectLocator.toString();
}
Preferences.setProperty(LAST_OPENED_PROJECT, value);
Preferences.store();
}
@@ -576,8 +585,13 @@ public class DefaultProjectManager implements ProjectManager {
Preferences.setProperty(SERVER_INFO,
serverInfo.getServerName() + ":" + serverInfo.getPortNumber());
}
Preferences.setProperty(LAST_OPENED_PROJECT,
lastOpenedProject != null ? lastOpenedProject.toString() : null);
String value = PROJECT_CLOSED_BY_USER_VALUE;
if (lastOpenedProject != null) {
value = lastOpenedProject.toString();
}
Preferences.setProperty(LAST_OPENED_PROJECT, value);
Preferences.store();
}