-
Couldn't load subscription status.
- Fork 0
Create Open the embedded file system.
The access to the embedded file system provided by DidiSoft EmbeddedFS is performed via the constructors of the EmDriveInfo class. This article illustrates how to create or open an embedded file system.
Table of contents
An embedded file system contained in the RAM memory will live until the calling application runs. If we want to persist it we can do so with the EmDriveInfo.SaveTo methods.
using EmbeddedFS; ... EmDriveInfo drive = new EmDriveInfo(); // load from a previously persisted location drive.LoadFrom(@"c:\Data\embedded.fs"); // persist the data if needed drive.SaveTo(@"c:\Data\embedded.fs"); |
using EmbeddedFS; ... EmDriveInfo drive = new EmDriveInfo(); // load from a previously persisted location drive.LoadFrom(@"c:\Data\embedded.fs"); // persist the data if needed drive.SaveTo(@"c:\Data\embedded.fs");
EmDriveInfo drive = new EmDriveInfo(@"c:\Temp\drive2.efs"); |
EmDriveInfo drive = new EmDriveInfo(@"c:\Temp\drive2.efs");
A password-protected embedded file system file is AES-256 encrypted with a key derived from the password.
EmDriveInfo drive = new EmDriveInfo(@"c:\Temp\drive2.efs", "my password"); |
EmDriveInfo drive = new EmDriveInfo(@"c:\Temp\drive2.efs", "my password");
Here is how to check if an embedded file system file is password protected
bool hasPassword = EmDriveInfo.IsPasswordProtected(@"c:\Temp\drive2.efs"); // check if a password mathes the password of an embedded file system bool passwordMatches = EmDriveInfo.CheckPassword(@"c:\Temp\drive2.efs", "pass 123"); |
bool hasPassword = EmDriveInfo.IsPasswordProtected(@"c:\Temp\drive2.efs"); // check if a password mathes the password of an embedded file system bool passwordMatches = EmDriveInfo.CheckPassword(@"c:\Temp\drive2.efs", "pass 123");
The password of an embedded file system file can also be changed
// set a password for an unprotected file system EmDriveInfo.SetPassword(@"c:\Temp\drivewithpass.efs", "my password"); // change the password of a file system already protected with a password EmDriveInfo.ChangePassword(@"c:\Temp\drivewithpass.efs", "old password", "new password"); |
// set a password for an unprotected file system EmDriveInfo.SetPassword(@"c:\Temp\drivewithpass.efs", "my password"); // change the password of a file system already protected with a password EmDriveInfo.ChangePassword(@"c:\Temp\drivewithpass.efs", "old password", "new password");
The password change methods and the EmDriveInfo constructor that opens the file system from a file will throw EmbeddedFS.Exceptions.PassworrdException when the provided opening password doesn’t match. In that case, it is a good practice to enclose our code with try/catch:
// set a password for an unprotected file system try { // change the password of a file system already protected with a password EmDriveInfo.ChangePassword(@"c:\Temp\drivewithpass.efs", "old password", "new password"); } catch (EmbeddedFS.Exceptions.PasswordException) { Console.WriteLine("The provided password doesn't match") } |
// set a password for an unprotected file system try { // change the password of a file system already protected with a password EmDriveInfo.ChangePassword(@"c:\Temp\drivewithpass.efs", "old password", "new password"); } catch (EmbeddedFS.Exceptions.PasswordException) { Console.WriteLine("The provided password doesn't match") }
An embedded file system instance contains a set of self-explanatory properties similar to those available in System.IO.DriveInfo. Probably the most used one is RootDirectory.
Console.WriteLine(drive2.AvailableFreeSpace); Console.WriteLine(drive2.DriveFormat); Console.WriteLine(drive2.FullName); Console.WriteLine(drive2.InMemory); Console.WriteLine(drive2.RootDirectory); Console.WriteLine(drive2.TotalFreeSpace); Console.WriteLine(drive2.TotalSize); Console.WriteLine(drive2.VolumeLabel); |
Console.WriteLine(drive2.AvailableFreeSpace); Console.WriteLine(drive2.DriveFormat); Console.WriteLine(drive2.FullName); Console.WriteLine(drive2.InMemory); Console.WriteLine(drive2.RootDirectory); Console.WriteLine(drive2.TotalFreeSpace); Console.WriteLine(drive2.TotalSize); Console.WriteLine(drive2.VolumeLabel);
A newly created embedded file system always contains a Root Directory.
Console.WriteLine(drive2.AvailableFreeSpace); EmDirectoryInfo rootDir = drive2.RootDirectory; |
Console.WriteLine(drive2.AvailableFreeSpace); EmDirectoryInfo rootDir = drive2.RootDirectory;
This page is a starting point for using the embedded file system API offered by EmbeddedFS.dll.
Probably from here, you can visit the chapters for working with files and folders.