Table of Contents

Class DefaultFileSystem

Namespace
Homa.Sdk.Foundation
Assembly
Homa.Sdk.Foundation.dll

Default implementation of a File System operations for use in Homa SDK

public class DefaultFileSystem : IFileSystem
Inheritance
DefaultFileSystem
Implements
Inherited Members

Constructors

DefaultFileSystem()

Default implementation of a File System operations for use in Homa SDK

public DefaultFileSystem()

DefaultFileSystem(ILogger)

Default implementation of a File System operations for use in Homa SDK

public DefaultFileSystem(ILogger logger)

Parameters

logger ILogger

Logger instance used in the operations.

Methods

DeleteFile(string, TargetDirectory)

Deletes a file.

public bool DeleteFile(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

Returns

bool

true if file was deleted.

EnumerateFileInfos(string, TargetDirectory, FileSearchOptions)

Returns file infos of files that match the provided pattern.

public IEnumerable<FileInfo> EnumerateFileInfos(string relativePath, TargetDirectory targetDirectory, FileSearchOptions options)

Parameters

relativePath string

Path fragment relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

options FileSearchOptions

Search options

Returns

IEnumerable<FileInfo>

File infos of 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.

public IEnumerable<string> EnumerateFiles(string relativePath, TargetDirectory targetDirectory, FileSearchOptions options)

Parameters

relativePath string

Path fragment relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

options FileSearchOptions

Search options

Returns

IEnumerable<string>

Full paths to all the files that match the pattern in the search options.

FileExists(string, TargetDirectory)

Checks whether a file exists.

public bool FileExists(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

Returns

bool

GetFileInfo(string, TargetDirectory)

Returns the file info of a file.

public FileInfo GetFileInfo(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

File path fragment relative to the target directory.

targetDirectory TargetDirectory

Abstraction 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.

public IFileReaderStream OpenReadingStream(string absoluteFilePath)

Parameters

absoluteFilePath string

Absolute 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.

public IFileWriterStream OpenWritingStream(string absoluteFilePath, FileMode fileMode, FileShare fileShare)

Parameters

absoluteFilePath string

Absolute path to a file.

fileMode FileMode

File mode in which to open the file.

fileShare FileShare

Share settings to other processes

Returns

IFileWriterStream

Handle to the opened stream.

Remarks

Does not support StreamingAssets on Android.

Exceptions

FileOperationException

An error occured during the read operation.

ReadTextFile(string, TargetDirectory)

Reads a text file from disk.

public string ReadTextFile(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction 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, TargetDirectory)

Reads a text file from disk.

public Task<string> ReadTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction 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, TargetDirectory)

Read text file line by line.

public string[] ReadTextFileLines(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction 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.

public bool TryReadTextFile(string relativeFilePath, TargetDirectory targetDirectory, out string contents)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

contents string

File 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, TargetDirectory)

Attempts to read a text file from disk. In case of failure will not throw any exceptions.

public Task<string> TryReadTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction 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, 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.

public bool TryWriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

contents string

Content to save.

useTwoStepSave bool

When true, the file will be saved using two steps to prevent corruption.

Returns

bool

true, if the operation was successful.

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.

public Task<bool> TryWriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

contents string

Content to save.

useTwoStepSave bool

When 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, bool)

Write a text file to a disk.

public void WriteTextFile(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

contents string

Content to save.

useTwoStepSave bool

When 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, bool)

Writes a text file to a disk.

public Task WriteTextFileAsync(string relativeFilePath, TargetDirectory targetDirectory, string contents, bool useTwoStepSave)

Parameters

relativeFilePath string

Filename or path fragment and filename relative to the target directory.

targetDirectory TargetDirectory

Abstraction over Unity directories for target platform.

contents string

Content to save.

useTwoStepSave bool

When true, the file will be saved using two steps to prevent corruption.

Returns

Task

Task representing the asynchronous operation.