diff --git a/source/Windows.Storage/FileIO.cs b/source/Windows.Storage/FileIO.cs index 79a1a18..0e323d7 100644 --- a/source/Windows.Storage/FileIO.cs +++ b/source/Windows.Storage/FileIO.cs @@ -158,7 +158,7 @@ public static void WriteBuffer(IStorageFile file, IBuffer buffer) [System.Diagnostics.DebuggerStepThrough] [MethodImpl(MethodImplOptions.InternalCall)] - public extern static void ReadTextNative(IStorageFile file, ref string text); + private extern static void ReadTextNative(IStorageFile file, ref string text); #endregion } diff --git a/source/Windows.Storage/IStorageProvider.cs b/source/Windows.Storage/IStorageProvider.cs index 15db343..bccdb6c 100644 --- a/source/Windows.Storage/IStorageProvider.cs +++ b/source/Windows.Storage/IStorageProvider.cs @@ -7,6 +7,9 @@ namespace Windows.Storage { + /// + /// + /// public interface IStorageProvider { } diff --git a/source/Windows.Storage/KnownFolderId.cs b/source/Windows.Storage/KnownFolderId.cs index 02bfa0c..da89081 100644 --- a/source/Windows.Storage/KnownFolderId.cs +++ b/source/Windows.Storage/KnownFolderId.cs @@ -75,5 +75,11 @@ public enum KnownFolderId ///// Videos library folder. ///// //VideosLibrary = 13 + + /// + /// Internal devices. + /// + InternalDevices = 14 + } } diff --git a/source/Windows.Storage/KnownFolders.cs b/source/Windows.Storage/KnownFolders.cs index b3813b1..7e5ea0b 100644 --- a/source/Windows.Storage/KnownFolders.cs +++ b/source/Windows.Storage/KnownFolders.cs @@ -28,6 +28,13 @@ public static class KnownFolders /// public static StorageFolder RemovableDevices => new StorageFolder(KnownFolderId.RemovableDevices); + + /// + /// Gets the internal devices folder. + /// + public static StorageFolder InternalDevices => new StorageFolder(KnownFolderId.InternalDevices); + + //public static StorageFolder SavedPictures { get; } //public static StorageFolder VideosLibrary { get; } diff --git a/source/Windows.Storage/StorageDevices.cs b/source/Windows.Storage/StorageDevices.cs new file mode 100644 index 0000000..f967049 --- /dev/null +++ b/source/Windows.Storage/StorageDevices.cs @@ -0,0 +1,93 @@ +using System; +using System.Runtime.CompilerServices; + + +namespace Windows.Storage.Devices +{ + /// + /// Class to allow a single SDCard to be mounted on the system. + /// Only allows for 1 device to be mounted, either via MMC or SPI + /// + public static class SDCard + { + +#pragma warning disable 0649 + + // this field is set in native code + [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] + private static bool _mounted = false; + +#pragma warning restore 0649 + + /// + /// Indcates if the SDscard has been mounted + /// + public static bool IsMounted => _mounted; + + /// + /// Mount the SDcard device on the MMC interface + /// + /// If true denotes 1 bit data path will be used otherwise it will be 4 bits. + /// + /// This will try to mount the SDCard on the specified interface. + /// If the Card is not present or the card is unable to be read then an exception will be thrown. + /// + [System.Diagnostics.DebuggerStepThrough] + public static void MountMMC(bool Data1bit) + { + MountMMCNative(Data1bit); + _mounted = true; + } + + /// + /// Mount the SPI SDcard device on the specified SPI bus + /// + /// The name for the SPI device, i.e "SPI1" + /// The GPIO pin used for chip select on SDcard. + /// + /// This will try to mount the SDCard on the specified interface. + /// If the Card is not present or the card is unable to be read then an exception will be thrown. + /// + [System.Diagnostics.DebuggerStepThrough] + public static void MountSpi(string SpiController, int ChipSelect) + { + // the SpiDevice is an ASCII string with the format 'SPIn' + // need to grab 'n' from the string and convert that to the integer value from the ASCII code (do this by subtracting 48 from the char value) + int spiBus = SpiController[3] - '0'; + MountSpiNative(spiBus, ChipSelect); + + // If no exception then set mounted flag + _mounted = true; + } + + /// + /// Unmount the mounted SDcard. + /// + [System.Diagnostics.DebuggerStepThrough] + public static void Unmount() + { + UnmountNative(); + + // If no exception then set mounted flag + _mounted = false; + } + +#region Native Calls + + [System.Diagnostics.DebuggerStepThrough] + [MethodImpl(MethodImplOptions.InternalCall)] + private extern static void MountMMCNative(bool Data1bit); + + [System.Diagnostics.DebuggerStepThrough] + [MethodImpl(MethodImplOptions.InternalCall)] + private static extern void MountSpiNative(int SpiBus, int ChipSelect); + + [System.Diagnostics.DebuggerStepThrough] + [MethodImpl(MethodImplOptions.InternalCall)] + private static extern void UnmountNative(); + +#endregion + + } +} + diff --git a/source/Windows.Storage/StorageFile.cs b/source/Windows.Storage/StorageFile.cs index 590cf7b..2abdc02 100644 --- a/source/Windows.Storage/StorageFile.cs +++ b/source/Windows.Storage/StorageFile.cs @@ -3,8 +3,8 @@ // See LICENSE file in the project root for full license information. // - using System; +using System.Runtime.CompilerServices; namespace Windows.Storage { @@ -160,6 +160,27 @@ public string FileType // public static IAsyncOperation GetFileFromPathAsync(String path) // { } + /// + /// Gets a StorageFile object to represent the file at the specified path. + /// + /// The path of the file to get a StorageFile to represent. + /// Returns the file as a StorageFile. + /// + /// + /// This method is exclusive of nanoFramework and it's not available in the UWP API. + /// The equivalent method would be GetFileFromPathAsync(String). + /// + public static StorageFile GetFileFromPath(String path) + { + StorageFile file = new StorageFile(); + + CheckFileNative(path); + + file._path = path; + + return file; + } + // public IAsyncOperation GetParentAsync() // { } @@ -202,6 +223,7 @@ public string FileType // public IAsyncOperation OpenAsync(FileAccessMode accessMode) // { } + // public IAsyncOperation OpenAsync(FileAccessMode accessMode, StorageOpenOptions options) // { } @@ -228,5 +250,12 @@ public string FileType // public static IAsyncOperation ReplaceWithStreamedFileFromUriAsync(IStorageFile fileToReplace, Uri uri, IRandomAccessStreamReference thumbnail) // { } + + + [System.Diagnostics.DebuggerStepThrough] + [System.Diagnostics.DebuggerHidden] + [MethodImpl(MethodImplOptions.InternalCall)] + private static extern void CheckFileNative(string filePath); + } } diff --git a/source/Windows.Storage/StorageFolder.cs b/source/Windows.Storage/StorageFolder.cs index 681c379..544d20f 100644 --- a/source/Windows.Storage/StorageFolder.cs +++ b/source/Windows.Storage/StorageFolder.cs @@ -18,6 +18,7 @@ public sealed class StorageFolder : IStorageFolder//, IStorageFolder2, IStorageI private const string s_RemovableStorageDevicesName = "Removable Storage Devices"; private const string s_RemovableStorageDevicesDisplayType = "System Folder"; + private const string s_InternalStorageDevicesName = "Internal Storage Devices"; #endregion @@ -105,14 +106,22 @@ public sealed class StorageFolder : IStorageFolder//, IStorageFolder2, IStorageI internal StorageFolder(KnownFolderId folderId) { - // currently there is only support for removable devices - if (folderId != KnownFolderId.RemovableDevices) + // currently there is only support for removable devices + // and internal storage devices + if (folderId == KnownFolderId.RemovableDevices) + { + _name = s_RemovableStorageDevicesName; + } + else if (folderId == KnownFolderId.InternalDevices) + { + _name = s_InternalStorageDevicesName; + } + else { throw new NotSupportedException(); } _knownFolderId = folderId; - _name = s_RemovableStorageDevicesName; _path = ""; } @@ -310,13 +319,17 @@ public StorageFile[] GetFiles(CommonFileQuery query, UInt32 startIndex, UInt32 m public StorageFolder[] GetFolders() { // is this a call for a known folder ID - // RemovableDevices + // RemovableDevices & InternalDevices // nothing else is implemented, no need to check as this doesn't get pass the constructor StorageFolder(KnownFolderId folderId) if (_knownFolderId == KnownFolderId.RemovableDevices) { return GetRemovableStorageFoldersNative(); } - + else if (_knownFolderId == KnownFolderId.InternalDevices) + { + return GetInternalStorageFoldersNative(); + } + // regular get folders return GetStorageFoldersNative(); } @@ -401,6 +414,11 @@ public bool IsCommonFileQuerySupported(CommonFileQuery query) [MethodImpl(MethodImplOptions.InternalCall)] private extern StorageFolder[] GetRemovableStorageFoldersNative(); + [System.Diagnostics.DebuggerStepThrough] + [System.Diagnostics.DebuggerHidden] + [MethodImpl(MethodImplOptions.InternalCall)] + private extern StorageFolder[] GetInternalStorageFoldersNative(); + [System.Diagnostics.DebuggerStepThrough] [System.Diagnostics.DebuggerHidden] [MethodImpl(MethodImplOptions.InternalCall)] diff --git a/source/Windows.Storage/Windows.Storage.nfproj b/source/Windows.Storage/Windows.Storage.nfproj index 7af28aa..de6558d 100644 --- a/source/Windows.Storage/Windows.Storage.nfproj +++ b/source/Windows.Storage/Windows.Storage.nfproj @@ -94,6 +94,7 @@ +