Interface IFileSystem
- Namespace
- Homa.Sdk.Foundation
- Assembly
- Homa.Sdk.Foundation.dll
File system proxy interface. Allows to abstract file operations for testing and provide custom logic for platform specific operations.
public interface IFileSystem
Properties
Default
Provides access to the default implementation of the IFileSystem interface.
public static IFileSystem Default { get; }
Property Value
Methods
DeleteFile(string)
Deletes a file.
bool DeleteFile(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
Returns
- bool
true if file was deleted.
DeleteFile(string, TargetDirectory)
Deletes a file.
bool DeleteFile(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- bool
true if file was deleted.
EnumerateFileInfos(string, FileSearchOptions)
Returns file infos of files that match the provided pattern.
IEnumerable<FileInfo> EnumerateFileInfos(string absolutePath, FileSearchOptions options)
Parameters
absolutePathstringPath to the directory to be searched.
optionsFileSearchOptionsSearch options
Returns
- IEnumerable<FileInfo>
File infos of all the files that match the pattern in the search options.
EnumerateFileInfos(string, TargetDirectory, FileSearchOptions)
Returns file infos of files that match the provided pattern.
IEnumerable<FileInfo> EnumerateFileInfos(string relativePath, TargetDirectory targetDirectory, FileSearchOptions options)
Parameters
relativePathstringPath fragment relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
optionsFileSearchOptionsSearch options
Returns
- IEnumerable<FileInfo>
File infos of all the files that match the pattern in the search options.
EnumerateFiles(string, FileSearchOptions)
Returns full paths to files that match the provided pattern.
IEnumerable<string> EnumerateFiles(string absolutePath, FileSearchOptions options)
Parameters
absolutePathstringPath to the directory to be searched.
optionsFileSearchOptionsSearch options
Returns
- IEnumerable<string>
Full paths to all the files that match the pattern in the search options.
EnumerateFiles(string, TargetDirectory, FileSearchOptions)
Returns full paths to files that match the provided pattern.
IEnumerable<string> EnumerateFiles(string relativePath, TargetDirectory targetDirectory, FileSearchOptions options)
Parameters
relativePathstringPath fragment relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
optionsFileSearchOptionsSearch options
Returns
- IEnumerable<string>
Full paths to all the files that match the pattern in the search options.
FileExists(string)
Checks whether a file exists.
bool FileExists(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
Returns
FileExists(string, TargetDirectory)
Checks whether a file exists.
bool FileExists(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
GetFileInfo(string)
Returns the file info of a file.
FileInfo GetFileInfo(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to a file.
Returns
- FileInfo
File info of the file.
Exceptions
- FileOperationException
The file does not exist.
GetFileInfo(string, TargetDirectory)
Returns the file info of a file.
FileInfo GetFileInfo(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFile path fragment relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- FileInfo
File info of the file.
Exceptions
- FileOperationException
The file does not exist.
OpenReadingStream(string)
Opens a file for reading using a stream.
IFileReaderStream OpenReadingStream(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to a file.
Returns
- IFileReaderStream
Handle to the opened stream.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
OpenWritingStream(string, FileMode, FileShare)
Opens a file for writing using a stream.
IFileWriterStream OpenWritingStream(string absoluteFilePath, FileMode fileMode, FileShare fileShare)
Parameters
absoluteFilePathstringAbsolute path to a file.
fileModeFileModeFile mode in which to open the file.
fileShareFileShareShare settings to other processes
Returns
- IFileWriterStream
Handle to the opened stream.
Exceptions
- FileOperationException
An error occured during the read operation.
ReadTextFile(string)
Reads a text file from disk.
string ReadTextFile(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
Returns
- string
File content as string.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
ReadTextFile(string, TargetDirectory)
Reads a text file from disk.
string ReadTextFile(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- string
File content as string.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
ReadTextFileAsync(string)
Reads a text file from disk.
Task<string> ReadTextFileAsync(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
Returns
- Task<string>
A task that represents the asynchronous read operation which wraps the file content as string.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
ReadTextFileAsync(string, TargetDirectory)
Reads a text file from disk.
Task<string> ReadTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- Task<string>
A task that represents the asynchronous read operation which wraps the file content as string.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
ReadTextFileLines(string)
Read text file line by line.
string[] ReadTextFileLines(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to a file.
Returns
- string[]
Array with the contents of the file separated by lines.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
ReadTextFileLines(string, TargetDirectory)
Read text file line by line.
string[] ReadTextFileLines(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- string[]
Array with the contents of the file separated by lines.
Exceptions
- FileOperationException
The file does not exist, or an error occured during the read operation.
TryReadTextFile(string, TargetDirectory, out string)
Attempts to read a text file from disk. In case of failure will not throw any exceptions.
bool TryReadTextFile(string relativeFilePath, TargetDirectory targetDirectory, out string contents)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringFile content as string or null if the file does not exist or an error occured.
Returns
- bool
true if the operation was successful.
TryReadTextFile(string, out string)
Attempts to read a text file from disk. In case of failure will not throw any exceptions.
bool TryReadTextFile(string absoluteFilePath, out string contents)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringFile content as string or null if the file does not exist or an error occured.
Returns
- bool
true if the operation was successful.
TryReadTextFileAsync(string)
Attempts to read a text file from disk. In case of failure will not throw any exceptions.
Task<string> TryReadTextFileAsync(string absoluteFilePath)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
Returns
- Task<string>
A task that represents the asynchronous read operation which wraps the file content as string or null if the file was not found or an error has occurred.
TryReadTextFileAsync(string, TargetDirectory)
Attempts to read a text file from disk. In case of failure will not throw any exceptions.
Task<string> TryReadTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
Returns
- Task<string>
A task that represents the asynchronous read operation which wraps the file content as string or null if the file was not found or an error has occurred.
TryWriteTextFile(string, TargetDirectory, string)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
bool TryWriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
Returns
- bool
true, if the operation was successful.
TryWriteTextFile(string, TargetDirectory, string, bool)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
bool TryWriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- bool
true, if the operation was successful.
TryWriteTextFile(string, string)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
bool TryWriteTextFile(string absoluteFilePath, string contents)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
Returns
- bool
true, if the operation was successful.
TryWriteTextFile(string, string, bool)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
bool TryWriteTextFile(string absoluteFilePath, string contents, bool useTwoStepSave)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- bool
true, if the operation was successful.
TryWriteTextFileAsync(string, TargetDirectory, string)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
Task<bool> TryWriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
Returns
- Task<bool>
Task representing the asynchronous operation which wraps the result of the write operation.
TryWriteTextFileAsync(string, TargetDirectory, string, bool)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
Task<bool> TryWriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- Task<bool>
Task representing the asynchronous operation which wraps the result of the write operation.
TryWriteTextFileAsync(string, string)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
Task<bool> TryWriteTextFileAsync(string absoluteFilePath, string contents)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
Returns
- Task<bool>
Task representing the asynchronous operation which wraps the result of the write operation.
TryWriteTextFileAsync(string, string, bool)
Attempts to write a text file to a disk. In case of failure will not throw any exceptions. Attempting to write into a directory that does not exist will create the directory.
Task<bool> TryWriteTextFileAsync(string absoluteFilePath, string contents, bool useTwoStepSave)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- Task<bool>
Task representing the asynchronous operation which wraps the result of the write operation.
WriteTextFile(string, TargetDirectory, string)
Write a text file to a disk.
void WriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
Exceptions
- FileOperationException
An error occured during the write operation.
WriteTextFile(string, TargetDirectory, string, bool)
Write a text file to a disk.
void WriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Exceptions
- FileOperationException
An error occured during the write operation.
WriteTextFile(string, string)
Write a text file to a disk.
void WriteTextFile(string absoluteFilePath, string contents)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
Exceptions
- FileOperationException
An error occured during the write operation.
WriteTextFile(string, string, bool)
Write a text file to a disk.
void WriteTextFile(string absoluteFilePath, string contents, bool useTwoStepSave)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Exceptions
- FileOperationException
An error occured during the write operation.
WriteTextFileAsync(string, TargetDirectory, string)
Writes a text file to a disk.
Task WriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
Returns
- Task
Task representing the asynchronous operation.
WriteTextFileAsync(string, TargetDirectory, string, bool)
Writes a text file to a disk.
Task WriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)
Parameters
relativeFilePathstringFilename or path fragment and filename relative to the target directory.
targetDirectoryTargetDirectoryAbstraction over Unity directories for target platform.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- Task
Task representing the asynchronous operation.
WriteTextFileAsync(string, string)
Writes a text file to a disk.
Task WriteTextFileAsync(string absoluteFilePath, string contents)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
Returns
- Task
Task representing the asynchronous operation.
WriteTextFileAsync(string, string, bool)
Writes a text file to a disk.
Task WriteTextFileAsync(string absoluteFilePath, string contents, bool useTwoStepSave)
Parameters
absoluteFilePathstringAbsolute path to the file or relative to the executing directory.
contentsstringContent to save.
useTwoStepSaveboolWhen true, the file will be saved using two steps to prevent corruption.
Returns
- Task
Task representing the asynchronous operation.