Class Preferences

java.lang.Object
ghidra.framework.preferences.Preferences

public class Preferences extends Object
Uses Properties to manage user preferences as name/value pairs. All methods are static.
  • Field Details

    • APPLICATION_PREFERENCES_FILENAME

      public static final String APPLICATION_PREFERENCES_FILENAME
      The APPLICATION_PREFERENCES_FILENAME is the default name for the user preferences file.
      See Also:
    • LAST_OPENED_ARCHIVE_DIRECTORY

      public static final String LAST_OPENED_ARCHIVE_DIRECTORY
      Preference name for the last opened archive directory.
      See Also:
    • PROJECT_DIRECTORY

      public static final String PROJECT_DIRECTORY
      Preference name for the project directory.
      See Also:
    • LAST_TOOL_IMPORT_DIRECTORY

      public static final String LAST_TOOL_IMPORT_DIRECTORY
      Preference name for import directory that was last accessed for tools.
      See Also:
    • LAST_TOOL_EXPORT_DIRECTORY

      public static final String LAST_TOOL_EXPORT_DIRECTORY
      Preference name for export directory that was last accessed for tools.
      See Also:
    • LAST_NEW_PROJECT_DIRECTORY

      public static final String LAST_NEW_PROJECT_DIRECTORY
      Preference name for directory last selected for creating a new project.
      See Also:
    • LAST_PATH_DIRECTORY

      public static final String LAST_PATH_DIRECTORY
      Preference name for the last chosen directory for path related items.
      See Also:
    • LAST_IMPORT_FILE

      public static final String LAST_IMPORT_FILE
      Preference name for the import directory that was last accessed for domain files.
      See Also:
    • LAST_EXPORT_DIRECTORY

      public static final String LAST_EXPORT_DIRECTORY
      Preference name for the export directory that was last accessed.
      See Also:
  • Method Details

    • clear

      public static void clear()
      Clears all properties in this Preferences object.

      Warning: Save any changes pending before calling this method, as this call will erase any changes not written do disk via store()

    • removeProperty

      public static String removeProperty(String name)
      Removes the given preference from this preferences object.
      Parameters:
      name - the name of the preference key to remove.
      Returns:
      the value that was stored with the given key.
    • getProperty

      public static String getProperty(String name)
      Get the property with the given name.

      Note: all getProperty(...) methods will check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

      Parameters:
      name - the property name
      Returns:
      the current property value; null if not set
    • getProperty

      public static String getProperty(String name, String defaultValue)
      Get the property with the given name; if there is no property, return the defaultValue.

      Note: all getProperty(...) methods will check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

      Parameters:
      name - the property name
      defaultValue - the default value
      Returns:
      the property value; default value if not set
      See Also:
    • getProperty

      public static String getProperty(String name, String defaultValue, boolean useHistoricalValue)
      Get the property with the given name; if there is no property, return the defaultValue.

      This version of getProperty will, when useHistoricalValue is true, look for the given preference value in the last used installation of the application.

      Note: all getProperty(...) methods will check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

      Parameters:
      name - The name of the property for which to get a value
      defaultValue - The value to use if there is no value yet set for the given name
      useHistoricalValue - True signals to check the last used application installation for a value for the given name if that value has not yet been set.
      Returns:
      the property with the given name; if there is no property, return the defaultValue.
      See Also:
    • setProperty

      public static void setProperty(String name, String value)
      Set the property value. If a null value is passed, then the property is removed from this collection of preferences.
      Parameters:
      name - property name
      value - value for property
    • getPropertyNames

      public static List<String> getPropertyNames()
      Get an array of known property names.
      Returns:
      if there are no properties, return a zero-length array
    • getFilename

      public static String getFilename()
      Get the filename that will be used in the store() method.
      Returns:
      the filename
    • setFilename

      public static void setFilename(String name)
      Set the filename so that when the store() method is called, the preferences are written to this file.
      Parameters:
      name - the filename
    • store

      public static boolean store()
      Store the preferences in a file for the current filename.
      Returns:
      true if the file was written
      Throws:
      RuntimeException - if the preferences filename was not set
    • getPluginPaths

      public static String[] getPluginPaths()
      Return the paths in the UserPluginPath property. Return zero length array if this property is not set.
      Returns:
      the paths
    • setPluginPaths

      public static void setPluginPaths(String[] paths)
      Set the paths to be used as the UserPluginPath property.
      Parameters:
      paths - the paths