GP-1164: Removing spaces from application name when creating user

settings/cache/temp directories
This commit is contained in:
Ryan Kurtz 2024-01-24 07:24:15 -05:00
parent 2ee2c56e38
commit db81fe8804
3 changed files with 20 additions and 8 deletions

View file

@ -15,6 +15,8 @@
*/
package ghidra.framework;
import utility.application.ApplicationUtilities;
/**
* Class to represent an application's unique identifier. An application identifier is made up
* of an application name, an application version, and an application release name.
@ -46,8 +48,8 @@ public class ApplicationIdentifier {
*/
public ApplicationIdentifier(ApplicationProperties applicationProperties)
throws IllegalArgumentException {
applicationName =
applicationProperties.getApplicationName().replaceAll("\\s", "").toLowerCase();
applicationName = ApplicationUtilities
.normalizeApplicationName(applicationProperties.getApplicationName());
if (applicationName.isEmpty()) {
throw new IllegalArgumentException("Application name is undefined.");
}

View file

@ -128,7 +128,7 @@ public class AppCleaner implements GhidraLaunchable {
*/
private Set<File> findSettingsDirs(String appName, ApplicationLayout layout) {
Set<File> discoveredDirs = new LinkedHashSet<>();
appName = appName.toLowerCase();
appName = ApplicationUtilities.normalizeApplicationName(appName);
String userNameAndAppName = SystemUtilities.getUserName() + "-" + appName;
// Legacy default settings directory
@ -191,7 +191,7 @@ public class AppCleaner implements GhidraLaunchable {
}
// Newer cache directories always use a lowercase application name
appName = appName.toLowerCase();
appName = ApplicationUtilities.normalizeApplicationName(appName);
String userNameAndAppName = SystemUtilities.getUserName() + "-" + appName;
// Current cache directories
@ -233,7 +233,7 @@ public class AppCleaner implements GhidraLaunchable {
}
// Newer temp directories always use a lowercase application name
appName = appName.toLowerCase();
appName = ApplicationUtilities.normalizeApplicationName(appName);
String userNameAndAppName = SystemUtilities.getUserName() + "-" + appName;
// Current temp directories

View file

@ -167,7 +167,7 @@ public class ApplicationUtilities {
public static File getDefaultUserTempDir(String applicationName)
throws FileNotFoundException, IOException {
String appName = applicationName.toLowerCase();
String appName = normalizeApplicationName(applicationName);
// Look for Ghidra-specific system property
File tempOverrideDir = getSystemPropertyFile(PROPERTY_TEMP_DIR, false);
@ -202,7 +202,7 @@ public class ApplicationUtilities {
public static File getDefaultUserCacheDir(ApplicationProperties applicationProperties)
throws FileNotFoundException, IOException {
String appName = applicationProperties.getApplicationName().toLowerCase();
String appName = normalizeApplicationName(applicationProperties.getApplicationName());
// Look for Ghidra-specific system property
File cacheOverrideDir = getSystemPropertyFile(PROPERTY_CACHE_DIR, false);
@ -253,9 +253,9 @@ public class ApplicationUtilities {
public static File getDefaultUserSettingsDir(ApplicationProperties applicationProperties,
ResourceFile installationDirectory) throws FileNotFoundException, IOException {
String appName = applicationProperties.getApplicationName().toLowerCase();
ApplicationIdentifier applicationIdentifier =
new ApplicationIdentifier(applicationProperties);
String appName = applicationIdentifier.getApplicationName();
String versionedName = applicationIdentifier.toString();
if (SystemUtilities.isInDevelopmentMode()) {
// Add the application's installation directory name to this variable, so that each
@ -321,6 +321,16 @@ public class ApplicationUtilities {
return new File(userSettingsParentDir, userSettingsDirName);
}
/**
* Normalizes the application name by removing spaces and converting to lower case
*
* @param applicationName The application name
* @return The normalized application name
*/
public static String normalizeApplicationName(String applicationName) {
return applicationName.replaceAll("\\s", "").toLowerCase();
}
/**
* Gets Java's temporary directory in absolute form
*