Class ProjectFileManager

java.lang.Object
ghidra.framework.data.ProjectFileManager
All Implemented Interfaces:
ProjectData
Direct Known Subclasses:
TransientProjectData

public class ProjectFileManager extends Object implements ProjectData
Helper class to manage files within a project.
  • Field Details

  • Constructor Details

    • ProjectFileManager

      public ProjectFileManager(ProjectLocator localStorageLocator, boolean isInWritableProject, boolean resetOwner) throws NotOwnerException, IOException
      Constructor for existing projects.
      Parameters:
      localStorageLocator - the location of the project
      isInWritableProject - true if project content is writable, false if project is read-only
      resetOwner - true to reset the project owner
      Throws:
      IOException - if an i/o error occurs
      NotOwnerException - if inProject is true and user is not owner
      FileNotFoundException - if project directory not found
    • ProjectFileManager

      public ProjectFileManager(ProjectLocator localStorageLocator, RepositoryAdapter repository, boolean isInWritableProject) throws IOException
      Constructor for a new project.
      Parameters:
      localStorageLocator - the location of the project
      repository - a repository if this is a shared project or null if it is a private project
      isInWritableProject - true if project content is writable, false if project is read-only
      Throws:
      IOException - if an i/o error occurs
  • Method Details

    • getMaxNameLength

      public int getMaxNameLength()
      Specified by:
      getMaxNameLength in interface ProjectData
      Returns:
      the maximum name length permitted for folders or items.
    • testValidName

      public void testValidName(String name, boolean isPath) throws InvalidNameException
      Description copied from interface: ProjectData
      Validate a folder/item name or path.
      Specified by:
      testValidName in interface ProjectData
      Parameters:
      name - folder or item name
      isPath - if true name represents full path
      Throws:
      InvalidNameException - if name is invalid
    • getUser

      public User getUser()
      Description copied from interface: ProjectData
      Returns User object associated with remote repository or null if a remote repository is not used.
      Specified by:
      getUser in interface ProjectData
    • getLocalStorageClass

      public Class<? extends LocalFileSystem> getLocalStorageClass()
      Specified by:
      getLocalStorageClass in interface ProjectData
      Returns:
      local storage implementation class
    • getOwner

      public String getOwner()
      Returns the owner of the project that is associated with this ProjectFileManager. A value of null indicates an old multiuser project.
      Returns:
      the owner of the project
    • getRootFolder

      public GhidraFolder getRootFolder()
      Description copied from interface: ProjectData
      Returns the root folder of the project.
      Specified by:
      getRootFolder in interface ProjectData
    • getFolder

      public GhidraFolder getFolder(String path)
      Description copied from interface: ProjectData
      Get domain folder specified by an absolute data path.
      Specified by:
      getFolder in interface ProjectData
      Parameters:
      path - the absolute path of domain folder relative to the data folder.
      Returns:
      domain folder or null if folder not found
    • getFileCount

      public int getFileCount()
      Description copied from interface: ProjectData
      Get the approximate number of files contained within the project. The number may be reduced if not connected to the shared repository. Only the newer indexed file-system supports this capability, a value of -1 will be returned for older projects utilizing the mangled file-system or if an IO Error occurs. An approximate number is provided since the two underlying file systems are consulted separately and the local private file-system does not distinguish between checked-out files and private files. This number is currently intended as a rough sizing number to disable certain features when very large projects are in use. Generally the larger of the two file counts will be returned.
      Specified by:
      getFileCount in interface ProjectData
      Returns:
      number of project files or -1 if unknown.
    • getFile

      public DomainFile getFile(String path)
      Description copied from interface: ProjectData
      Get domain file specified by an absolute data path.
      Specified by:
      getFile in interface ProjectData
      Parameters:
      path - the absolute path of domain file relative to the root folder.
      Returns:
      domain file or null if file not found
    • getFileByID

      public DomainFile getFileByID(String fileID)
      Description copied from interface: ProjectData
      Get domain file specified by its unique fileID.
      Specified by:
      getFileByID in interface ProjectData
      Parameters:
      fileID - domain file ID
      Returns:
      domain file or null if file not found
    • getSharedFileURL

      public URL getSharedFileURL(String path)
      Description copied from interface: ProjectData
      Get a URL for a shared domain file which is available within a remote repository.
      Specified by:
      getSharedFileURL in interface ProjectData
      Parameters:
      path - the absolute path of domain file relative to the root folder.
      Returns:
      URL object for accessing shared file from outside of a project, or null if file does not exist or is not shared.
    • releaseDomainFiles

      public void releaseDomainFiles(Object consumer)
    • findOpenFiles

      public void findOpenFiles(List<DomainFile> list)
      Finds all changed domain files and appends them to the specified list.
      Specified by:
      findOpenFiles in interface ProjectData
      Parameters:
      list - the list to receive the changed domain files
    • getProjectLocator

      public ProjectLocator getProjectLocator()
      Description copied from interface: ProjectData
      Returns the projectLocator for the this ProjectData.
      Specified by:
      getProjectLocator in interface ProjectData
    • addDomainFolderChangeListener

      public void addDomainFolderChangeListener(DomainFolderChangeListener l)
      Description copied from interface: ProjectData
      Adds a listener that will be notified when any folder or file changes in the project.
      Specified by:
      addDomainFolderChangeListener in interface ProjectData
      Parameters:
      l - the listener to be notified of folder and file changes.
    • removeDomainFolderChangeListener

      public void removeDomainFolderChangeListener(DomainFolderChangeListener l)
      Description copied from interface: ProjectData
      Removes the listener to be notified of folder and file changes.
      Specified by:
      removeDomainFolderChangeListener in interface ProjectData
      Parameters:
      l - the listener to be removed.
    • getPrivateFileSystem

      public FileSystem getPrivateFileSystem()
    • getRepository

      public RepositoryAdapter getRepository()
      Description copied from interface: ProjectData
      Return the repository for this project data.
      Specified by:
      getRepository in interface ProjectData
      Returns:
      null if the project is not associated with a repository
    • refresh

      public void refresh(boolean force) throws IOException
      Description copied from interface: ProjectData
      Sync the Domain folder/file structure with the underlying file structure.
      Specified by:
      refresh in interface ProjectData
      Parameters:
      force - if true all folders will be be visited and refreshed, if false only those folders previously visited will be refreshed.
      Throws:
      IOException
    • convertProjectToShared

      public void convertProjectToShared(RepositoryAdapter newRepository, TaskMonitor monitor) throws IOException, CancelledException
      Description copied from interface: ProjectData
      Convert a local project to a shared project. NOTE: The project should be closed and then reopened after this method is called.
      Specified by:
      convertProjectToShared in interface ProjectData
      Parameters:
      newRepository - the repository that the project will be associated with.
      monitor - task monitor
      Throws:
      IOException - thrown if files under version control are still checked out, or if there was a problem accessing the filesystem
      CancelledException - if the conversion was cancelled while versioned files were being converted to private files.
    • updateRepositoryInfo

      public void updateRepositoryInfo(RepositoryAdapter newRepository, boolean force, TaskMonitor monitor) throws IOException, CancelledException
      Description copied from interface: ProjectData
      Update the repository for this project; the server may have changed or a different repository is being used. Any existing checkout which is not recognized/valid by newRepository will be terminated and a local .keep file created. NOTE: The project should be closed and then reopened after this method is called.
      Specified by:
      updateRepositoryInfo in interface ProjectData
      Parameters:
      newRepository - new repository to use
      force - if true any existing local checkout which is not recognized/valid for newRepository will be forceably terminated if offline with old repository.
      monitor - task monitor
      Throws:
      IOException - thrown if files are still checked out, or if there was a problem accessing the filesystem
      CancelledException - if the user canceled the update
    • hasInvalidCheckouts

      public boolean hasInvalidCheckouts(List<DomainFile> checkoutList, RepositoryAdapter newRepository, TaskMonitor monitor) throws IOException, CancelledException
      Determine if any domain files listed does not correspond to a checkout in the specified newRespository.
      Specified by:
      hasInvalidCheckouts in interface ProjectData
      Parameters:
      checkoutList - project domain files to check
      newRepository - repository to check against before updating
      monitor - task monitor
      Returns:
      true if one or more files are not valid checkouts in newRepository
      Throws:
      IOException - if IO error occurs
      CancelledException - if task cancelled
    • findCheckedOutFiles

      public List<DomainFile> findCheckedOutFiles(TaskMonitor monitor) throws IOException, CancelledException
      Find all project files which are currently checked-out
      Specified by:
      findCheckedOutFiles in interface ProjectData
      Parameters:
      monitor - task monitor (no progress updates)
      Returns:
      list of current checkout files
      Throws:
      IOException - if IO error occurs
      CancelledException - if task cancelled
    • getUserDataFilename

      public static String getUserDataFilename(String associatedFileID)
      Returns the standard user data filename associated with the specified file ID.
      Parameters:
      associatedFileID - the file id
      Returns:
      user data filename
    • makeValidName

      public String makeValidName(String name)
      Description copied from interface: ProjectData
      Transform the specified name into an acceptable folder or file item name. Only an individual folder or file name should be specified, since any separators will be stripped-out. NOTE: Uniqueness of name within the intended target folder is not considered.
      Specified by:
      makeValidName in interface ProjectData
      Returns:
      valid name or "unknown" if no valid characters exist within name provided
    • getProjectDir

      public File getProjectDir()
    • close

      public void close()
      Description copied from interface: ProjectData
      Close the project storage associated with this project data object. NOTE: This should not be invoked if this object is utilized by a Project instance.
      Specified by:
      close in interface ProjectData
    • dispose

      public void dispose()
    • updateFileIndex

      public void updateFileIndex(GhidraFileData fileData)
      Update the file index for the specified file data
      Parameters:
      fileData - file data
    • removeFromIndex

      public void removeFromIndex(String fileID)
      Remove specified fileID from index.
      Parameters:
      fileID - the file ID
    • getProjectDisposalMonitor

      public TaskMonitor getProjectDisposalMonitor()
      Get monitor which will be cancelled if project is closed
      Returns:
      cancel monitor