/// <summary> /// Creates an instance of TinyFileStream. /// </summary> /// <param name="fileSystem">TinyFileSystem instance on which the file this stream exposes exists.</param> /// <param name="fileRef">The file to expose through the TinyFileStream.</param> /// <remarks> /// Instances of this class should never be created directly. The should be created by calls to Create or Open /// on the TinyFileSystem instance. /// </remarks> internal TinyFileStream(TinyFileSystem fileSystem, FileRef fileRef) { _fs = fileSystem; _fileRef = fileRef; _filePointer = 0; _fileRef.OpenCount++; }
public void Initialize() { var spiConfig = new SPI.Configuration(_chipSelect, false, 0, 0, false, true, 12000, _spiModule); var spi = new SPI(spiConfig); // Instantiate the block driver var driver = new FL164KIF01BlockDriver(spi, Oxygen.Hardware.UserLed, 4); // Instantiate the file system passing the block driver for the underlying storage medium _tfs = new TinyFileSystem(driver); }
/// <summary> /// Dispose the TinyFileStream. /// </summary> /// <param name="disposing">true if being disposed from a call to Dispose otherwise false if called from the finalizer.</param> protected override void Dispose(Boolean disposing) { if (_fileRef != null) { _fileRef.OpenCount--; _fileRef = null; _fs = null; } base.Dispose(disposing); }
public static void Main() { _tfs = new TinyFileSystem(new FlashMemory(Hardware.OnboardFlash)); if (_tfs.CheckIfFormatted()) { Debug.WriteLine("Filesystem OK. Mounting..."); _tfs.Mount(); Debug.WriteLine("Mounted. Now reading settings.dat file..."); if (!_tfs.Exists("settings.dat")) { return; } using (Stream fs = _tfs.Open("settings.dat", FileMode.Open)) using (var rdr = new StreamReader(fs)) { System.String line; while ((line = rdr.ReadLine()) != null) { Debug.WriteLine(line); } } TinyFileSystem.DeviceStats aa = _tfs.GetStats(); Debug.WriteLine("Stats : " + aa); } else { Debug.WriteLine("Formatting"); _tfs.Format(); Debug.WriteLine("Creating file"); using (Stream fs = _tfs.Create("settings.dat")) { using (var wr = new StreamWriter(fs)) { wr.WriteLine("<settings>"); wr.WriteLine("InitialPosX=200"); wr.WriteLine("InitialPosY=150"); wr.WriteLine("</settings>"); wr.Flush(); fs.Flush(); } } Debug.WriteLine("FileCreated"); } Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Dispose the TinyFileStream. /// </summary> /// <param name="disposing">true if being disposed from a call to Dispose otherwise false if called from the finalizer.</param> protected override void Dispose(bool disposing) { if (_fileRef != null) { _fileRef.OpenCount--; _fileRef = null; _fs = null; } base.Dispose(disposing); }