internal DiskImageFile(FileLocator locator, string path, FileAccess access)
        {
            FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None;

            _fileStream = locator.Open(path, FileMode.Open, access, share);
            _ownsStream = Ownership.Dispose;

            _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
            _fileName    = locator.GetFileFromPath(path);

            Initialize();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the DiskImageFile class.
        /// </summary>
        /// <param name="fileLocator">An object to open the file and any extents.</param>
        /// <param name="file">The file name.</param>
        /// <param name="access">The type of access desired.</param>
        internal DiskImageFile(FileLocator fileLocator, string file, FileAccess access)
        {
            _access = access;

            FileAccess fileAccess = FileAccess.Read;
            FileShare  fileShare  = FileShare.Read;

            if (_access != FileAccess.Read)
            {
                fileAccess = FileAccess.ReadWrite;
                fileShare  = FileShare.None;
            }

            Stream fileStream = null;

            try
            {
                fileStream = fileLocator.Open(file, FileMode.Open, fileAccess, fileShare);
                LoadDescriptor(fileStream);

                // For monolithic disks, keep hold of the stream - we won't try to use the file name
                // from the embedded descriptor because the file may have been renamed, making the
                // descriptor out of date.
                if (_descriptor.CreateType == DiskCreateType.StreamOptimized ||
                    _descriptor.CreateType == DiskCreateType.MonolithicSparse)
                {
                    _monolithicStream     = fileStream;
                    _ownsMonolithicStream = Ownership.Dispose;
                    fileStream            = null;
                }
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }

            _fileLocator = fileLocator.GetRelativeLocator(fileLocator.GetDirectoryFromPath(file));
        }
Exemplo n.º 3
0
        internal DiskImageFile(FileLocator locator, string path, FileAccess access)
        {
            FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None;

            _fileStream = locator.Open(path, FileMode.Open, access, share);
            _ownsStream = Ownership.Dispose;

            try
            {
                _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
                _fileName    = locator.GetFileFromPath(path);

                ReadFooter(true);

                ReadHeaders();
            }
            catch
            {
                _fileStream.Dispose();
                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the DiskImageFile class.
        /// </summary>
        /// <param name="fileLocator">An object to open the file and any extents</param>
        /// <param name="file">The file name</param>
        /// <param name="access">The type of access desired</param>
        internal DiskImageFile(FileLocator fileLocator, string file, FileAccess access)
        {
            _access = access;

            FileAccess fileAccess = FileAccess.Read;
            FileShare fileShare = FileShare.Read;
            if (_access != FileAccess.Read)
            {
                fileAccess = FileAccess.ReadWrite;
                fileShare = FileShare.None;
            }

            Stream fileStream = null;
            try
            {
                fileStream = fileLocator.Open(file, FileMode.Open, fileAccess, fileShare);
                LoadDescriptor(fileStream);

                // For monolithic disks, keep hold of the stream - we won't try to use the file name
                // from the embedded descriptor because the file may have been renamed, making the 
                // descriptor out of date.
                if (_descriptor.CreateType == DiskCreateType.StreamOptimized || _descriptor.CreateType == DiskCreateType.MonolithicSparse)
                {
                    _monolithicStream = fileStream;
                    _ownsMonolithicStream = Ownership.Dispose;
                    fileStream = null;
                }
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }

            _fileLocator = fileLocator.GetRelativeLocator(fileLocator.GetDirectoryFromPath(file));
        }
Exemplo n.º 5
0
 internal DiskImageFile(FileLocator locator, string path, Stream stream, Ownership ownsStream)
     : this(stream, ownsStream)
 {
     _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
     _fileName    = locator.GetFileFromPath(path);
 }
Exemplo n.º 6
0
        internal DiskImageFile(FileLocator locator, string path, FileAccess access)
        {
            FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None;
            _fileStream = locator.Open(path, FileMode.Open, access, share);
            _ownsStream = Ownership.Dispose;

            try
            {
                _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
                _fileName = locator.GetFileFromPath(path);

                ReadFooter(true);

                ReadHeaders();
            }
            catch
            {
                _fileStream.Dispose();
                throw;
            }
        }
Exemplo n.º 7
0
 internal DiskImageFile(FileLocator locator, string path, Stream stream, Ownership ownsStream)
     : this(stream, ownsStream)
 {
     _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
     _fileName = locator.GetFileFromPath(path);
 }
        internal DiskImageFile(FileLocator locator, string path, FileAccess access)
        {
            FileShare share = access == FileAccess.Read ? FileShare.Read : FileShare.None;
            _fileStream = locator.Open(path, FileMode.Open, access, share);
            _ownsStream = Ownership.Dispose;

            _fileLocator = locator.GetRelativeLocator(locator.GetDirectoryFromPath(path));
            _fileName = locator.GetFileFromPath(path);

            Initialize();
        }