private void ReadDirectory(int clusterStart, FAT16Directory dir) { int Cluster = clusterStart; while (Cluster != -1) { DiskStream.Seek(DiskBootSector.SectorOffsetForCluster(Cluster), SeekOrigin.Begin); byte[] dirCluster = new byte[DiskBootSector.GetBytesPerCluster()]; DiskStream.Read(dirCluster, 0, DiskBootSector.GetBytesPerCluster()); MemoryStream MS = new MemoryStream(dirCluster); ParseDirectoryCluster(dir, MS); Cluster = FAT_TABLE.nextClusterInChain(Cluster); } dir.ParseAllEntries(); numeroDeArchivosLabel.Text = dir.NumeroDeArchivos().ToString(); DirectorioActual = dir.GetClusterStart(); DirectorioAnterior = dir.GetParentCluster(); UpdateFileListView(dir); }
public void obtenerArchivo(BootSector BS, FileStream stream, FileAllocationTable FAT, String path) { List <byte[]> bytes = new List <byte[]>(); MemoryStream ms = new MemoryStream(); byte[] archivo = null; int Cluster = Entry.GetFirstCluster(); while (Cluster != -1) { //Leer archivo byte[] tempByte = new byte[BS.GetBytesPerSector()]; stream.Seek(BS.SectorOffsetForCluster(Cluster), SeekOrigin.Begin); stream.Read(tempByte, 0, BS.GetBytesPerSector()); bytes.Add(tempByte); //Obtener el siguiente cluster Cluster = FAT.nextClusterInChain(Cluster); } if (bytes.Count > 0) { foreach (byte[] b in bytes) { ms.Write(b, 0, b.Length); } ms.Seek(0, SeekOrigin.Begin); archivo = new byte[Entry.FileSize]; ms.Read(archivo, 0, archivo.Length); Console.WriteLine(ms.Length); } if (archivo != null) { File.WriteAllBytes(path + Entry.NombreDeDir, archivo); MessageBox.Show("Archivo(s) extraido(s) exitosamente!", "Extraccion de Archivo(s)", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Archivo devuelto en cero!", "Error al extraer archivo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }