Class LinkedGhidraFolder

java.lang.Object
ghidra.framework.data.LinkedGhidraFolder
All Implemented Interfaces:
DomainFolder, LinkedDomainFolder, Comparable<DomainFolder>

public class LinkedGhidraFolder extends Object
LinkedGhidraFolder provides the base LinkedDomainFolder implementation which corresponds to a project folder-link (see FolderLinkContentHandler).
  • Field Details

  • Method Details

    • equals

      public boolean equals(Object obj)
    • isExternal

      public boolean isExternal()
      Description copied from interface: LinkedDomainFolder
      Determine if this folder resides within an external project or repository. The term "external" means the actual folder does not reside within the same project as the folder-link that referenced it and which was used to produce this linked folder instance.
      Specified by:
      isExternal in interface LinkedDomainFolder
      Returns:
      true if linked-folder is external to the link file which was used to access, else false if internal to the same project.
    • getProjectURL

      public URL getProjectURL()
      Get the Ghidra URL of the project/repository folder referenced by this object
      Returns:
      Ghidra URL of the project/repository folder referenced by this object
    • isInWritableProject

      public boolean isInWritableProject()
      Description copied from interface: DomainFolder
      Returns true if this file is in a writable project.
      Specified by:
      isInWritableProject in interface DomainFolder
      Returns:
      true if writable
    • getLinkedProjectData

      public ProjectData getLinkedProjectData() throws IOException
      Description copied from interface: LinkedDomainFolder
      Get the project data that corresponds to the linked-project and contains the LinkedDomainFolder.getLinkedPathname() which corresponds to this folder.
      Specified by:
      getLinkedProjectData in interface LinkedDomainFolder
      Returns:
      linked project data
      Throws:
      IOException - if an IO error occurs
    • getLinkedPathname

      public String getLinkedPathname()
      Description copied from interface: LinkedDomainFolder
      Get the project folder/file pathname for this this linked-folder relative to the linked-folder root.
      Specified by:
      getLinkedPathname in interface LinkedDomainFolder
      Returns:
      project pathname
    • getRealFolder

      public DomainFolder getRealFolder() throws IOException
      Description copied from interface: LinkedDomainFolder
      Get the real domain folder which corresponds to this linked-folder. In the process of resolving the real folder a remote project or repository may be required.
      Specified by:
      getRealFolder in interface LinkedDomainFolder
      Returns:
      domain folder
      Throws:
      IOException - if an IO error occurs while connecting/accessing the associated project or repository.
    • getProjectLocator

      public ProjectLocator getProjectLocator()
      Description copied from interface: DomainFolder
      Returns the local storage location for the project that this DomainFolder belongs to.
      Specified by:
      getProjectLocator in interface DomainFolder
      Returns:
      the locator
    • getProjectData

      public ProjectData getProjectData()
      Description copied from interface: DomainFolder
      Returns the project data
      Specified by:
      getProjectData in interface DomainFolder
      Returns:
      the project data
    • getParent

      public DomainFolder getParent()
      Description copied from interface: DomainFolder
      Return parent folder or null if this DomainFolder is the root folder.
      Specified by:
      getParent in interface DomainFolder
      Returns:
      the parent
    • setName

      public DomainFolder setName(String newName) throws InvalidNameException, IOException
      Description copied from interface: DomainFolder
      Set the name on this domain folder.
      Specified by:
      setName in interface DomainFolder
      Parameters:
      newName - domain folder name
      Returns:
      renamed domain file (the original DomainFolder object becomes invalid since it is immutable)
      Throws:
      InvalidNameException - if newName contains illegal characters
      IOException - thrown if an IO or access error occurs.
    • toString

      public String toString()
    • getIcon

      public Icon getIcon(boolean isOpen)
      Description copied from interface: LinkedDomainFolder
      Get the appropriate icon for this folder
      Specified by:
      getIcon in interface LinkedDomainFolder
      Parameters:
      isOpen - true if open icon, false for closed
      Returns:
      folder icon
    • isLinked

      public boolean isLinked()
      Description copied from interface: DomainFolder
      Determine if this folder corresponds to a linked-folder which directly corresponds to a folder-link file. While this method is useful for identify a linked-folder root, in some cases it may be preferrable to simply check for instanceof LinkedDomainFolder which applies to the linked-folder root as well as its child sub-folders.
      Returns:
      true if folder corresponds to a linked-folder, else false.
    • isUrlLinked

      public boolean isUrlLinked()
      Determine if this linked-folder corresponds to an external URL linkage and not an internal project linkage.
      Returns:
      true if linked based on external URL
    • getName

      public String getName()
      Description copied from interface: DomainFolder
      Return this folder's name.
      Specified by:
      getName in interface DomainFolder
      Returns:
      the name
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(DomainFolder df)
      Specified by:
      compareTo in interface Comparable<DomainFolder>
    • isSame

      public boolean isSame(DomainFolder folder)
      Description copied from interface: DomainFolder
      Returns true if the given folder is the same as this folder based on path and underlying project/repository. Unlike the Object.equals(Object) check, this method handles cases where the folder provided may correspond to another project instance which is considered the same as the project that this folder is contained within.
      Specified by:
      isSame in interface DomainFolder
      Parameters:
      folder - the potential same or descendant folder to check
      Returns:
      true if the given folder is the same or a child of this folder or one of its descendants.
    • isSameOrAncestor

      public boolean isSameOrAncestor(DomainFolder folder)
      Description copied from interface: DomainFolder
      Returns true if the given folder is the same or a child of this folder or one of its descendants based on path and underlying project/repository. Unlike the Object.equals(Object) check, this method handles cases where the folder provided may correspond to another project instance which is considered the same as the project that this folder is contained within.
      Specified by:
      isSameOrAncestor in interface DomainFolder
      Parameters:
      folder - the potential same or descendant folder to check
      Returns:
      true if the given folder is the same or a child of this folder or one of its descendants.
    • getSharedProjectURL

      public URL getSharedProjectURL()
      Description copied from interface: DomainFolder
      Get a remote Ghidra URL for this domain folder if available within an associated shared project repository. URL path will end with "/". A null value will be returned if shared folder does not exist and may also be returned if shared repository is not connected or a connection error occurs.
      Specified by:
      getSharedProjectURL in interface DomainFolder
      Returns:
      remote Ghidra URL for this folder or null
    • getLocalProjectURL

      public URL getLocalProjectURL()
      Description copied from interface: DomainFolder
      Get a local Ghidra URL for this domain file if available within the associated non-transient local project. A null value will be returned if project is transient.
      Specified by:
      getLocalProjectURL in interface DomainFolder
      Returns:
      local Ghidra URL for this folder or null if transient or not applicable
    • getPathname

      public String getPathname()
      Description copied from interface: DomainFolder
      Returns the full path name to this folder
      Specified by:
      getPathname in interface DomainFolder
      Returns:
      the path name
    • getFolders

      public ghidra.framework.data.LinkedGhidraSubFolder[] getFolders()
      Description copied from interface: DomainFolder
      Get DomainFolders in this folder. This may return cached information and does not force a full refresh.
      Specified by:
      getFolders in interface DomainFolder
      Returns:
      list of sub-folders
    • getFolder

      public ghidra.framework.data.LinkedGhidraSubFolder getFolder(String name)
      Description copied from interface: DomainFolder
      Return the folder for the given name. Folder link-files are ignored.
      Specified by:
      getFolder in interface DomainFolder
      Parameters:
      name - of folder to retrieve
      Returns:
      folder or null if there is no folder by the given name.
    • getFiles

      public DomainFile[] getFiles()
      Description copied from interface: DomainFolder
      Get all domain files in this folder. This may return cached information and does not force a full refresh.
      Specified by:
      getFiles in interface DomainFolder
      Returns:
      list of domain files
    • getLinkedFileNoError

      public DomainFile getLinkedFileNoError(String name)
      Get the true file within this linked folder.

      NOTE: The returned file is the "real" file and would be the have the equivalence: folder.getLinkedFileNoError("X") == folder.getFile("X").getRealFile() .

      Parameters:
      name - file name
      Returns:
      file or null if not found or error occurs
    • getFile

      public DomainFile getFile(String name)
      Description copied from interface: DomainFolder
      Get the domain file in this folder with the given name.
      Specified by:
      getFile in interface DomainFolder
      Parameters:
      name - name of file in this folder to retrieve
      Returns:
      domain file or null if there is no domain file in this folder with the given name.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: DomainFolder
      Determine if this folder contains any sub-folders or domain files.
      Specified by:
      isEmpty in interface DomainFolder
      Returns:
      true if this folder is empty.
    • createFile

      Description copied from interface: DomainFolder
      Add a domain object to this folder.
      Specified by:
      createFile in interface DomainFolder
      Parameters:
      name - domain file name
      obj - domain object to be stored
      monitor - progress monitor
      Returns:
      domain file created as a result of adding the domain object to this folder
      Throws:
      InvalidNameException - if name is an empty string or if it contains characters other than alphanumerics.
      IOException - if IO or access error occurs
      CancelledException - if the user cancels the create.
    • createFile

      public DomainFile createFile(String name, File packFile, TaskMonitor monitor) throws InvalidNameException, IOException, CancelledException
      Description copied from interface: DomainFolder
      Add a new domain file to this folder.
      Specified by:
      createFile in interface DomainFolder
      Parameters:
      name - domain file name
      packFile - packed file containing domain file data
      monitor - progress monitor
      Returns:
      domain file created as a result of adding the domain object to this folder
      Throws:
      InvalidNameException - if name is an empty string or if it contains characters other than alphanumerics.
      IOException - if IO or access error occurs
      CancelledException - if the user cancels the create.
    • createLinkFile

      public DomainFile createLinkFile(ProjectData sourceProjectData, String pathname, boolean makeRelative, String linkFilename, LinkHandler<?> lh) throws IOException
      Description copied from interface: DomainFolder
      Create a link-file within this folder which references the specified file or folder pathname within the project specified by sourceProjectData. The link-file may correspond to various types of content (e.g., Program, Trace, Folder, etc.) based upon the specified LinkHandler instance.
      Specified by:
      createLinkFile in interface DomainFolder
      Parameters:
      sourceProjectData - referenced content project data within which specified path exists. If this differ's from this folder's project a Ghidra URL will be used, otherwise and internal link path reference will be used.
      pathname - an absolute path of project folder or file within the specified source project data (a Ghidra URL is not permitted)
      makeRelative - if true, and this file is contained within the same active ProjectData instance as newParent, an internal-project relative path link-file will be created.
      linkFilename - name of link-file to be created within this folder. NOTE: This name may be modified to ensure uniqueness within this folder.
      lh - link-file handler used to create specific link-file (see derived implementations of LinkHandler and their public static INSTANCE.
      Returns:
      newly created link-file
      Throws:
      IOException - if IO error occurs during link creation
    • createLinkFile

      public DomainFile createLinkFile(String ghidraUrl, String linkFilename, LinkHandler<?> lh) throws IOException
      Description copied from interface: DomainFolder
      Create an external link-file within this folder which references the specified ghidraUrl and whose content is defined by the specified lh instance.
      Specified by:
      createLinkFile in interface DomainFolder
      Parameters:
      ghidraUrl - a Ghidra URL which corresponds to a file or a folder based on the designated lh instance. Only rudimentary URL checks are performed.
      linkFilename - name of link-file to be created within this folder. NOTE: This name may be modified to ensure uniqueness within this folder.
      lh - link-file handler used to create specific link-file (see derived implementations of LinkHandler and their public static INSTANCE.
      Returns:
      newly created link-file
      Throws:
      IOException - if IO error occurs during link creation
    • createFolder

      public DomainFolder createFolder(String name) throws InvalidNameException, IOException
      Description copied from interface: DomainFolder
      Create a subfolder within this folder.
      Specified by:
      createFolder in interface DomainFolder
      Parameters:
      name - sub-folder name
      Returns:
      the new folder
      Throws:
      InvalidNameException - if name is an empty string of if it contains characters other than alphanumerics.
      IOException - if IO or access error occurs
    • delete

      public void delete() throws IOException
      Description copied from interface: DomainFolder
      Deletes this folder, if empty, from the local filesystem
      Specified by:
      delete in interface DomainFolder
      Throws:
      IOException - if IO or access error occurs
    • moveTo

      public DomainFolder moveTo(DomainFolder newParent) throws IOException
      Description copied from interface: DomainFolder
      Move this folder into the newParent folder. If connected to a repository this moves both private and repository folders/files. If not connected, only private folders/files are moved.
      Specified by:
      moveTo in interface DomainFolder
      Parameters:
      newParent - new parent folder within the same project
      Returns:
      the newly relocated folder (the original DomainFolder object becomes invalid since it is immutable)
      Throws:
      IOException - thrown if an IO or access error occurs.
    • copyTo

      public DomainFolder copyTo(DomainFolder newParent, TaskMonitor monitor) throws IOException, CancelledException
      Description copied from interface: DomainFolder
      Copy this folder into the newParent folder.
      Specified by:
      copyTo in interface DomainFolder
      Parameters:
      newParent - new parent folder
      monitor - the task monitor
      Returns:
      the new copied folder
      Throws:
      IOException - thrown if an IO or access error occurs.
      CancelledException - if task monitor cancelled operation.
    • copyToAsLink

      public DomainFile copyToAsLink(DomainFolder newParent, boolean relative) throws IOException
      Description copied from interface: DomainFolder
      Copy this folder into the newParent folder as a folder-link. A folder-link references another folder without actually copying all of its children. If this folder is associated with a temporary transient project (i.e., not a locally managed project) the generated link will refer to the this folder with a Ghidra URL. If this folder is contained within the same active ProjectData instance as newParent an internal link reference will be made.
      Specified by:
      copyToAsLink in interface DomainFolder
      Parameters:
      newParent - new parent folder where link-file is to be created
      relative - if true, and this folder is contained within the same active ProjectData instance as newParent, an internal-project relative path folder-link will be created.
      Returns:
      newly created domain file which is a folder-link (i.e., link-file).
      Throws:
      IOException - if an IO or access error occurs.
    • setActive

      public void setActive()
      Description copied from interface: DomainFolder
      Allows the framework to react to a request to make this folder the "active" one.
      Specified by:
      setActive in interface DomainFolder