Package ghidra.framework.data
Class ProjectFileManager
- java.lang.Object
-
- ghidra.framework.data.ProjectFileManager
-
- All Implemented Interfaces:
ProjectData
- Direct Known Subclasses:
TransientProjectData
public class ProjectFileManager extends java.lang.Object implements ProjectData
Helper class to manage files within a project.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
INDEXED_DATA_FOLDER_NAME
static java.lang.String
MANGLED_DATA_FOLDER_NAME
Name of folder that stores user's datastatic java.lang.String
USER_FOLDER_NAME
static java.lang.String
VERSIONED_FOLDER_NAME
-
Constructor Summary
Constructors Constructor Description ProjectFileManager(ProjectLocator localStorageLocator, boolean isInWritableProject, boolean resetOwner)
Constructor for existing projects.ProjectFileManager(ProjectLocator localStorageLocator, RepositoryAdapter repository, boolean isInWritableProject)
Constructor for a new project.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDomainFolderChangeListener(DomainFolderChangeListener l)
Adds a listener that will be notified when any folder or file changes in the project.void
close()
Close the project storage associated with this project data object.void
convertProjectToShared(RepositoryAdapter newRepository, TaskMonitor monitor)
Convert a local project to a shared project.void
dispose()
Disposes this project file manager.void
findOpenFiles(java.util.List<DomainFile> list)
Finds all changed domain files and appends them to the specified list.DomainFile
getFile(java.lang.String path)
Get domain file specified by an absolute data path.DomainFile
getFileByID(java.lang.String fileID)
Get domain file specified by its unique fileID.int
getFileCount()
Get the approximate number of files contained within the project.DomainFolder
getFolder(java.lang.String path)
Get domain folder specified by an absolute data path.java.lang.Class<? extends LocalFileSystem>
getLocalStorageClass()
int
getMaxNameLength()
java.lang.String
getOwner()
Returns the owner of the project that is associated with this ProjectFileManager.FileSystem
getPrivateFileSystem()
Returns the private files system associated with this project file manager.java.io.File
getProjectDir()
Return the project directory.TaskMonitor
getProjectDisposalMonitor()
Get monitor which will be cancelled if project is closedProjectLocator
getProjectLocator()
Returns the projectLocator for the this ProjectData.RepositoryAdapter
getRepository()
Returns the repository associated with this project file manager.GhidraFolder
getRootFolder()
Returns the root folder of the project.java.net.URL
getSharedFileURL(java.lang.String path)
Get a GhidraURL for a shared domain file which is available within a remote repository.User
getUser()
Returns User object associated with remote repository or null if a remote repository is not used.static java.lang.String
getUserDataFilename(java.lang.String associatedFileID)
Returns the standard user data filename associated with the specified file ID.java.lang.String
makeValidName(java.lang.String name)
Transform the specified name into an acceptable folder or file item name.void
refresh(boolean force)
Sync the Domain folder/file structure with the underlying file structure.void
releaseDomainFiles(java.lang.Object consumer)
Releases all domain files for the specified consumer.void
removeDomainFolderChangeListener(DomainFolderChangeListener l)
Removes the listener to be notified of folder and file changes.void
removeFromIndex(java.lang.String fileID)
Remove specified fileID from index.void
testValidName(java.lang.String name, boolean isPath)
Validate a folder/item name or path.void
updateFileIndex(GhidraFileData fileData)
Update the file index for the specified file datavoid
updateRepositoryInfo(RepositoryAdapter newRepository, TaskMonitor monitor)
Update the repository for this project; the server may have changed or a different repository is being used.
-
-
-
Field Detail
-
MANGLED_DATA_FOLDER_NAME
public static final java.lang.String MANGLED_DATA_FOLDER_NAME
Name of folder that stores user's data- See Also:
- Constant Field Values
-
INDEXED_DATA_FOLDER_NAME
public static final java.lang.String INDEXED_DATA_FOLDER_NAME
- See Also:
- Constant Field Values
-
USER_FOLDER_NAME
public static final java.lang.String USER_FOLDER_NAME
- See Also:
- Constant Field Values
-
VERSIONED_FOLDER_NAME
public static final java.lang.String VERSIONED_FOLDER_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ProjectFileManager
public ProjectFileManager(ProjectLocator localStorageLocator, boolean isInWritableProject, boolean resetOwner) throws NotOwnerException, java.io.IOException
Constructor for existing projects.- Parameters:
localStorageLocator
- the location of the projectisInWritableProject
- true if project content is writable, false if project is read-onlyinProject
- true if this is the active project- Throws:
java.io.IOException
- if an i/o error occursNotOwnerException
- if inProject is true and user is not ownerjava.io.FileNotFoundException
- if project directory not found
-
ProjectFileManager
public ProjectFileManager(ProjectLocator localStorageLocator, RepositoryAdapter repository, boolean isInWritableProject) throws java.io.IOException
Constructor for a new project.- Parameters:
localStorageLocator
- the location of the projectrepository
- a repository if this is a shared project or null if it is a private projectisInWritableProject
- true if project content is writable, false if project is read-only- Throws:
java.io.IOException
- if an i/o error occurs
-
-
Method Detail
-
getMaxNameLength
public int getMaxNameLength()
- Specified by:
getMaxNameLength
in interfaceProjectData
-
testValidName
public void testValidName(java.lang.String name, boolean isPath) throws InvalidNameException
Description copied from interface:ProjectData
Validate a folder/item name or path.- Specified by:
testValidName
in interfaceProjectData
- Parameters:
name
- folder or item nameisPath
- 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 interfaceProjectData
- See Also:
ProjectData.getUser()
-
getLocalStorageClass
public java.lang.Class<? extends LocalFileSystem> getLocalStorageClass()
- Specified by:
getLocalStorageClass
in interfaceProjectData
- Returns:
- local storage implementation class
-
getOwner
public java.lang.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 interfaceProjectData
- See Also:
ProjectData.getRootFolder()
-
getFolder
public DomainFolder getFolder(java.lang.String path)
Description copied from interface:ProjectData
Get domain folder specified by an absolute data path.- Specified by:
getFolder
in interfaceProjectData
- Parameters:
path
- the absolute path of domain folder relative to the data folder.- Returns:
- domain folder or null if folder not found
- See Also:
ProjectData.getFolder(java.lang.String)
-
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 interfaceProjectData
- Returns:
- number of project files or -1 if unknown.
-
getFile
public DomainFile getFile(java.lang.String path)
Description copied from interface:ProjectData
Get domain file specified by an absolute data path.- Specified by:
getFile
in interfaceProjectData
- Parameters:
path
- the absolute path of domain file relative to the root folder.- Returns:
- domain file or null if file not found
- See Also:
ProjectData.getFile(java.lang.String)
-
getFileByID
public DomainFile getFileByID(java.lang.String fileID)
Description copied from interface:ProjectData
Get domain file specified by its unique fileID.- Specified by:
getFileByID
in interfaceProjectData
- Parameters:
fileID
- domain file ID- Returns:
- domain file or null if file not found
- See Also:
ProjectData.getFileByID(java.lang.String)
-
getSharedFileURL
public java.net.URL getSharedFileURL(java.lang.String path)
Description copied from interface:ProjectData
Get a GhidraURL for a shared domain file which is available within a remote repository.- Specified by:
getSharedFileURL
in interfaceProjectData
- 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.
- See Also:
ProjectData.getSharedFileURL(java.lang.String)
-
releaseDomainFiles
public void releaseDomainFiles(java.lang.Object consumer)
Releases all domain files for the specified consumer.- Parameters:
consumer
- the domain object consumer
-
findOpenFiles
public void findOpenFiles(java.util.List<DomainFile> list)
Finds all changed domain files and appends them to the specified list.- Specified by:
findOpenFiles
in interfaceProjectData
- 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 interfaceProjectData
- See Also:
ProjectData.getProjectLocator()
-
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 interfaceProjectData
- Parameters:
l
- the listener to be notified of folder and file changes.- See Also:
ProjectData.addDomainFolderChangeListener( ghidra.framework.model.DomainFolderChangeListener)
-
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 interfaceProjectData
- Parameters:
l
- the listener to be removed.- See Also:
ProjectData.removeDomainFolderChangeListener( ghidra.framework.model.DomainFolderChangeListener)
-
getPrivateFileSystem
public FileSystem getPrivateFileSystem()
Returns the private files system associated with this project file manager.- Returns:
- the private files system associated with this project file manager
-
getRepository
public RepositoryAdapter getRepository()
Returns the repository associated with this project file manager.- Specified by:
getRepository
in interfaceProjectData
- Returns:
- the repository associated with this project file manager
-
refresh
public void refresh(boolean force) throws java.io.IOException
Description copied from interface:ProjectData
Sync the Domain folder/file structure with the underlying file structure.- Specified by:
refresh
in interfaceProjectData
- Parameters:
force
- if true all folders will be be visited and refreshed, if false only those folders previously visited will be refreshed.- Throws:
java.io.IOException
- See Also:
ProjectData.refresh(boolean)
-
convertProjectToShared
public void convertProjectToShared(RepositoryAdapter newRepository, TaskMonitor monitor) throws java.io.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 interfaceProjectData
- Parameters:
newRepository
- the repository that the project will be associated with.monitor
- task monitor- Throws:
java.io.IOException
- thrown if files under version control are still checked out, or if there was a problem accessing the filesystemCancelledException
- if the conversion was cancelled while versioned files were being converted to private files.
-
updateRepositoryInfo
public void updateRepositoryInfo(RepositoryAdapter newRepository, TaskMonitor monitor) throws java.io.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. NOTE: The project should be closed and then reopened after this method is called.- Specified by:
updateRepositoryInfo
in interfaceProjectData
- Parameters:
newRepository
- new repository to usemonitor
- task monitor- Throws:
java.io.IOException
- thrown if files are still checked out, or if there was a problem accessing the filesystemCancelledException
- if the user canceled the update
-
getUserDataFilename
public static java.lang.String getUserDataFilename(java.lang.String associatedFileID)
Returns the standard user data filename associated with the specified file ID.- Parameters:
associatedFileID
-- Returns:
- user data filename
-
makeValidName
public java.lang.String makeValidName(java.lang.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 interfaceProjectData
- Returns:
- valid name or "unknown" if no valid characters exist within name provided
-
getProjectDir
public java.io.File getProjectDir()
Return the project directory.
-
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 interfaceProjectData
-
dispose
public void dispose()
Disposes this project file manager.
-
updateFileIndex
public void updateFileIndex(GhidraFileData fileData)
Update the file index for the specified file data- Parameters:
fileData
- file data
-
removeFromIndex
public void removeFromIndex(java.lang.String fileID)
Remove specified fileID from index.- Parameters:
fileID
-
-
getProjectDisposalMonitor
public TaskMonitor getProjectDisposalMonitor()
Get monitor which will be cancelled if project is closed- Returns:
- cancel monitor
-
-