Class FileManagerSecure
Inheritance
Inherited Members
Namespace: MVR.FileManagementSecure
Assembly: cs.temp.dll.dll
Syntax
public class FileManagerSecure
Methods
CopyFile(String, String)
Copy a file. Note file copy is passed to user confirm/deny system for security reasons, so the file may not be immediately copied. It is recommended to use new CopyFile method that takes callback parameters so your code can properly react to user action.
Declaration
public static void CopyFile(string oldPath, string newPath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | oldPath | Path to copy file from |
| System.String | newPath | Path to copy file to |
CopyFile(String, String, UserActionCallback, UserActionCallback, ExceptionCallback)
Copy a file. The file is only copied after passing through user confirm/deny system, so use the callback functions if you need to take action after the file is copied (or denied by user).
Declaration
public static void CopyFile(string oldPath, string newPath, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | oldPath | Path to copy file from |
| System.String | newPath | Path to copy file to |
| UserActionCallback | confirmCallback | Function to call if user confirms action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during copy |
CreateDirectory(String)
Creates a directory. Note directory creation is passed to user confirm/deny system for security reasons, so the directory may not be immediately created. It is recommended to use new CreateDirectory method that takes callback parameters so your code can properly react to user action.
Declaration
public static void CreateDirectory(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | Directory to create |
CreateDirectory(String, UserActionCallback, UserActionCallback, ExceptionCallback)
Creates a directory. Directory is only created after passing through user confirm/deny system, so use the callback functions if you need to take action after the directory is created (or denied by user).
Declaration
public static void CreateDirectory(string path, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | Directory to create |
| UserActionCallback | confirmCallback | Function to call if user confirmes action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during directory creation |
DeleteFile(String)
Deletes a file. Note file deletion is passed to user confirm/deny system for security reasons, so the file may not be immediately deleted. It is recommended to use new DeleteFile method that takes callback parameters so your code can properly react to user action.
Declaration
public static void DeleteFile(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to delete |
DeleteFile(String, UserActionCallback, UserActionCallback, ExceptionCallback)
Deletes a file. The file is only deleted after passing through user confirm/deny system, so use the callback functions if you need to take action after the file is deleted (or denied by user).
Declaration
public static void DeleteFile(string path, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to delete |
| UserActionCallback | confirmCallback | Function to call if user confirms action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during delete |
DirectoryExists(String, Boolean)
Checks if directory exists. Path can also be package directory UID or package directory path
Declaration
public static bool DirectoryExists(string path, bool onlySystemDirectories = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to check |
| System.Boolean | onlySystemDirectories | Skips check of package directory UIDs and paths if true |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if directory exists, false if it doesn't exist |
FileExists(String, Boolean)
Checks if file exists. Path can also be package file UID or package file path.
Declaration
public static bool FileExists(string path, bool onlySystemFiles = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to check |
| System.Boolean | onlySystemFiles | Skips check of package files UIDs and paths if true |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if file exists, false if it doesn't exist |
GetDirectories(String, String)
Returns an array of sub directories in the passed directory. Input directory can also be package directory UID or package directory path
Declaration
public static string[] GetDirectories(string dir, string pattern = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | dir | The directory to look in |
| System.String | pattern | Pattern of directory to match, glob style. Example: Image |
Returns
| Type | Description |
|---|---|
| System.String[] | An array of strings which are the sub directories of the directory that match pattern |
GetDirectoryName(String, Boolean)
Gets directory name from path. Also works with package file UIDs to convert to path.
Declaration
public static string GetDirectoryName(string path, bool returnSlashPath = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path or package file UID |
| System.Boolean | returnSlashPath | If true, returns name in slash style. If false, returns in backslash style. |
Returns
| Type | Description |
|---|---|
| System.String | Directory name for the path |
GetFileName(String)
Gets file name from path. Works exactly like Path.GetFileName
Declaration
public static string GetFileName(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to get file name from |
Returns
| Type | Description |
|---|---|
| System.String | The file name |
GetFiles(String, String)
Returns an array of sub directories in the passed directory. Input directory can also be package directory UID or package directory path
Declaration
public static string[] GetFiles(string dir, string pattern = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | dir | The directory to look in |
| System.String | pattern | Pattern of file to match, glob style. Example: *.jpg |
Returns
| Type | Description |
|---|---|
| System.String[] | An array of string which are the files in the directory that match pattern |
GetFullPath(String)
Works like the Path.GetFullPath function
Declaration
public static string GetFullPath(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to get the full path from |
Returns
| Type | Description |
|---|---|
| System.String | Path converted to full path |
GetShortCutsForDirectory(String, Boolean, Boolean, Boolean, Boolean)
Gets list of shortcuts to use in file browsers.
Declaration
public static List<ShortCut> GetShortCutsForDirectory(string dir, bool allowNavigationAboveRegularDirectories = false, bool useFullPaths = false, bool generateAllFlattenedShortcut = false, bool includeRegularDirsInFlattenedShortcut = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | dir | The directory to get the shortcuts for |
| System.Boolean | allowNavigationAboveRegularDirectories | If set true, navigation upward from shortcut for regular directories is allowed |
| System.Boolean | useFullPaths | If set true, full paths are used for regular directories, allowing navigation above the install directory. Only works if one of the allowNavigationAboveRegularDirectories is set true as well. |
| System.Boolean | generateAllFlattenedShortcut | If set true, an additional shortcut is created for browsing all content in flattened manner that matches what dir is set to |
| System.Boolean | includeRegularDirsInFlattenedShortcut | If set true, regular directories are included in the flattened shortcut. Note this may be inadvisable if there are a lot of local disk files as it will make browser slow or unresponsive |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<ShortCut> | List of shortcuts that can be passed to file browse functions |
IsDirectoryInPackage(String)
Check if passed directory path or uid is in an existing package.
Declaration
public static bool IsDirectoryInPackage(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to check |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the path or uid is in package. False if not. |
IsFileInPackage(String)
Check is passed file path or uid is in an existing package.
Declaration
public static bool IsFileInPackage(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to check |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the path or uid is in package. False if not. |
MoveFile(String, String, UserActionCallback, UserActionCallback, ExceptionCallback, Boolean)
Move a file. The file is only moved after passing through user confirm/deny system, so use the callback functions if you need to take action after the file is moved (or denied by user).
Declaration
public static void MoveFile(string oldPath, string newPath, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback, bool overwrite = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | oldPath | Path to move file from |
| System.String | newPath | Path to move file to |
| UserActionCallback | confirmCallback | Function to call if user confirms action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during move |
| System.Boolean | overwrite | If true, overwrite move to file if it already exists |
MoveFile(String, String, Boolean)
Move a file. Note file move is passed to user confirm/deny system for security reasons, so the file may not be immediately copied. It is recommended to use new moveFile method that takes callback parameters so your code can properly react to user action.
Declaration
public static void MoveFile(string oldPath, string newPath, bool overwrite = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | oldPath | Path to move file from |
| System.String | newPath | Path to move file to |
| System.Boolean | overwrite | If true, overwrite move to file if it already exists |
NormalizePath(String)
Normalizes a path to return path relative to the install dir if possible. If path is outside of install directory, returns full path
Declaration
public static string NormalizePath(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path to normalize |
Returns
| Type | Description |
|---|---|
| System.String | Normalized path |
ReadAllBytes(String)
Reads all contents of file as byte array
Declaration
public static byte[] ReadAllBytes(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to read from |
Returns
| Type | Description |
|---|---|
| System.Byte[] | byte array of contents of file |
ReadAllText(String)
Reads all contents of file as string
Declaration
public static string ReadAllText(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to read from |
Returns
| Type | Description |
|---|---|
| System.String | string of contents of file |
WriteAllBytes(String, Byte[])
Writes byte array to file. Note file creation is passed to user confirm/deny system for security reasons, so the file may not be immediately created. It is recommended to use new WriteAllBytes method that takes callback parameters so your code can properly react to user action.
Declaration
public static void WriteAllBytes(string path, byte[] bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to write to |
| System.Byte[] | bytes | The array of bytes to write |
WriteAllBytes(String, Byte[], UserActionCallback, UserActionCallback, ExceptionCallback)
Writes byte array to file. File is only written to after passing through user confirm/deny system, so use the callback functions if you need to take action after the file is written (or denied by user).
Declaration
public static void WriteAllBytes(string path, byte[] bytes, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to write to |
| System.Byte[] | bytes | The array of bytes to write |
| UserActionCallback | confirmCallback | Function to call if user confirms action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during file write |
WriteAllText(String, String)
Writes string to file. Note file creation is passed to user confirm/deny system for security reasons, so the file may not be immediately created. It is recommended to use new WriteAllText method that takes callback parameters so your code can properly react to user action.
Declaration
public static void WriteAllText(string path, string text)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to write to |
| System.String | text | string to write |
WriteAllText(String, String, UserActionCallback, UserActionCallback, ExceptionCallback)
Writes string to file. File is only written to after passing through user confirm/deny system, so use the callback functions if you need to take action after the file is written (or denied by user).
Declaration
public static void WriteAllText(string path, string text, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | File path to write to |
| System.String | text | string to write |
| UserActionCallback | confirmCallback | Function to call if user confirms action |
| UserActionCallback | denyCallback | Function to call if user denies action |
| ExceptionCallback | exceptionCallback | Function to call if exception occurs during file write |