public static bool HasFileSystem(IFileSystemStore store) { if (store == null || store.StreamLength == 0) { return(false); } switch (store.StorageType) { case StorageType.PhysicalDiskPartition: { PhysicalDiskPartitionAttributes attributes = (PhysicalDiskPartitionAttributes)store.Attributes; if (attributes.PartitionType == PartitionType.NTFS) { return(true); } else if (attributes.PartitionType == PartitionType.FAT16 || attributes.PartitionType == PartitionType.FAT32) { return(true); } else if (attributes.PartitionType == PartitionType.FAT32WithInt13Support) { return(true); } else { return(false); } } case StorageType.LogicalVolume: { LogicalDiskAttributes attributes = (LogicalDiskAttributes)store.Attributes; if (attributes.FileSystem == "NTFS") { return(true); } else if (attributes.FileSystem == "FAT16") { return(true); } else if (attributes.FileSystem == "FAT32") { return(true); } else { return(false); } } default: return(false); } }
public static IFileSystem TryLoad(IFileSystemStore store, string FSType = null) { if (store == null || store.StreamLength == 0) { return(null); } if (FSType == "NTFS") { return(new FileSystemNTFS(store)); } else if (FSType == "FAT16") { return(new FileSystemFAT(store, PartitionType.FAT16)); } else if (FSType == "FAT32") { return(new FileSystemFAT(store, PartitionType.FAT32)); } // TODO: Autodetect based on FS signatures if possible? switch (store.StorageType) { case StorageType.PhysicalDiskPartition: { PhysicalDiskPartitionAttributes attributes = (PhysicalDiskPartitionAttributes)store.Attributes; if (attributes.PartitionType == PartitionType.NTFS) { return(new FileSystemNTFS(store)); } else if (attributes.PartitionType == PartitionType.FAT16 || attributes.PartitionType == PartitionType.FAT32) { return(new FileSystemFAT(store, attributes.PartitionType)); } else if (attributes.PartitionType == PartitionType.FAT32WithInt13Support) { return(new FileSystemFAT(store, PartitionType.FAT32)); } else { return(null); } } case StorageType.LogicalVolume: { LogicalDiskAttributes attributes = (LogicalDiskAttributes)store.Attributes; if (attributes.FileSystem == "NTFS") { return(new FileSystemNTFS(store)); } else if (attributes.FileSystem == "FAT16") { return(new FileSystemFAT(store, PartitionType.FAT16)); } else if (attributes.FileSystem == "FAT32") { return(new FileSystemFAT(store, PartitionType.FAT32)); } else { return(null); } } default: return(null); } }