public virtual void Clear()
 {
     _SubItems.Clear();
     _dateTime    = new DateTime();
     _Parent      = null;
     obj          = null;
     _name        = string.Empty;
     _path        = string.Empty;
     _location    = 0;
     _size        = 0;
     _isDirectory = false;
 }
        private string GetPath()
        {
            List <string> lst = new List <string>();
            ImageRecord   cur = this;

            while (cur.Parent != null)
            {
                lst.Add(cur.Parent.Name);
                cur = cur.Parent;
            }
            StringBuilder sb = new StringBuilder();

            for (int i = lst.Count - 1; i > -1; i--)
            {
                sb.Append(lst[i]);
                sb.Append(System.IO.Path.DirectorySeparatorChar);
            }
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extracts files from the image to the given directory.
        /// </summary>
        /// <param name="path">The directory to extract the files to.</param>
        /// <param name="root">The root directory of the image.</param>
        public void ExtractFiles(string path, ImageRecord root)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            if (this.ImageFile == null)
            {
                throw new InvalidOperationException("No image file specified.");
            }

            using (var fileStream = this.ImageFile.OpenRead())
            {
                this.InitializeStream(fileStream);

                this.Extract(path, root);
            }
        }
 internal static long GetSize(ImageRecord record, long retval)
 {
     foreach (ImageRecord r in record.Subitems) {
         retval += r.Size;
     }
     return retval;
 }
 public virtual void Clear()
 {
     _SubItems.Clear();
     _dateTime = new DateTime();
     _Parent = null;
     obj = null;
     _name = string.Empty;
     _path = string.Empty;
     _location = 0;
     _size = 0;
     _isDirectory = false;
 }
        /// <summary>
        /// Extracts an individual record from the image to the given directory.
        /// </summary>
        /// <param name="path">The directory to extract the record to.</param>
        /// <param name="record">The record to extract.</param>
        private void Extract(string path, ImageRecord record)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            // Only extract UDF records.
            if (!record.IsUdf)
            {
                return;
            }

            string target = Path.Combine(path, record.Name);
            if (record.IsDirectory || String.IsNullOrEmpty(record.Name))
            {
                Directory.CreateDirectory(target);

                // No sub items for this directory, continue.
                if (record.Subitems == null || record.Subitems.Count <= 0)
                {
                    return;
                }

                for (int i = 0; i < record.Subitems.Count; i++)
                {
                    if (this.WorkerThread.CancellationPending)
                    {
                        break; // Canceled, exit loop
                    }

                    this.Extract(target, record.Subitems[i]);
                }
            }
            else
            {
                UdfRecord item = (UdfRecord)record;
                if (item.IsRecAndAlloc() && item.CheckChunkSizes() && this.CheckItemExtents(item.VolumeIndex, item))
                {
                    if (item.IsInline)
                    {
                        if (item.InlineData != null)
                        {
                            if (item.InlineData.Length == 0)
                            {
                                return;
                            }

                            File.WriteAllBytes(target, item.InlineData);
                        }
                    }
                    else
                    {
                        Partition part = this.Partitions[item.PartitionIndex];
                        this.currentBlockSize = this.LogicalVolumes[item.VolumeIndex].BlockSize;
                        long logBlockNumber = item.Key;
                        if (item.Extents.Count > 0)
                        {
                            logBlockNumber = item.Extents[0].Position;
                        }

                        long start = ((long)part.Position << SectorSizeLog) + (logBlockNumber * this.currentBlockSize);
                        this.Extract(target, start, item.Size);
                    }
                }
            }
        }
        /// <summary>
        /// Extracts files from the image to the given directory.
        /// </summary>
        /// <param name="path">The directory to extract the files to.</param>
        /// <param name="root">The root directory of the image.</param>
        public void ExtractFiles(string path, ImageRecord root)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            if (this.ImageFile == null)
            {
                throw new InvalidOperationException("No image file specified.");
            }

            using (var fileStream = this.ImageFile.OpenRead())
            {
                this.InitializeStream(fileStream);

                this.Extract(path, root);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Extracts an individual record from the image to the given directory.
        /// </summary>
        /// <param name="path">The directory to extract the record to.</param>
        /// <param name="record">The record to extract.</param>
        private void Extract(string path, ImageRecord record)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            // Only extract UDF records.
            if (!record.IsUdf)
            {
                return;
            }

            string target = Path.Combine(path, record.Name);

            if (record.IsDirectory || String.IsNullOrEmpty(record.Name))
            {
                Directory.CreateDirectory(target);

                // No sub items for this directory, continue.
                if (record.Subitems == null || record.Subitems.Count <= 0)
                {
                    return;
                }

                for (int i = 0; i < record.Subitems.Count; i++)
                {
                    if (this.WorkerThread.CancellationPending)
                    {
                        break; // Canceled, exit loop
                    }

                    this.Extract(target, record.Subitems[i]);
                }
            }
            else
            {
                UdfRecord item = (UdfRecord)record;
                if (item.IsRecAndAlloc() && item.CheckChunkSizes() && this.CheckItemExtents(item.VolumeIndex, item))
                {
                    if (item.IsInline)
                    {
                        if (item.InlineData != null)
                        {
                            if (item.InlineData.Length == 0)
                            {
                                return;
                            }

                            File.WriteAllBytes(target, item.InlineData);
                        }
                    }
                    else
                    {
                        Partition part = this.Partitions[item.PartitionIndex];
                        this.currentBlockSize = this.LogicalVolumes[item.VolumeIndex].BlockSize;
                        long logBlockNumber = item.Key;
                        if (item.Extents.Count > 0)
                        {
                            logBlockNumber = item.Extents[0].Position;
                        }

                        long start = ((long)part.Position << SectorSizeLog) + (logBlockNumber * this.currentBlockSize);
                        this.Extract(target, start, item.Size);
                    }
                }
            }
        }