using System; using Microsoft.SPOT; using Microsoft.SPOT.IO; using System.IO; namespace Moszi.Net.Duino.WebServer { /// <summary> /// The <see cref="FileManager"/> class is responsible of creating the profile file names based on the Netduino SD card name. /// </summary> public static class FileManager { private static bool hasFileSystemSupport; private static string rootFolderName; /// <summary> /// Sets up the file manager class. /// </summary> static FileManager() { // find all volumes VolumeInfo[] volumes = VolumeInfo.GetVolumes(); foreach (var volumeInfo in volumes) { // then search for the sd card volume if (volumeInfo.Name == Constants.SDCardName) { // check if the volume is formatted, if not then we can't use this if (!volumeInfo.IsFormatted) { break; } // build the root folder name, and set our file system support flag to true rootFolderName = Path.Combine( "\\" + volumeInfo.Name, Constants.HomeControllerFolder); // create the directory if it doesn't exist if (!Directory.Exists(rootFolderName)) { Directory.CreateDirectory(rootFolderName); } hasFileSystemSupport = true; } } } private static string RootFolderName { get { return rootFolderName; } } /// <summary> /// Returns whether there is file system support in this HomeController. /// </summary> public static bool HasFileSystemSupport { get { return hasFileSystemSupport; } } /// <summary> /// Returns the filename for the password. /// </summary> public static string PasswordFilename { get { // build and return the return Path.Combine(RootFolderName, Constants.HomeControllerPassword); } } } }
The example uses the following constants:
/// <summary> /// The name of the volume where Netduino can save information. Change this to SD if you are using /// a real NetDuino device, or change it to WINFS if you are using the emulator. /// </summary> public const string SDCardName = @"SD"; /// <summary> /// The folder where Netduino stores information. /// </summary> public const string HomeControllerFolder = "DuinoWebServer"; /// <summary> /// The password file name. /// </summary> public const string NetDuinoPassword = "password.txt";
- Asyraf likes this