예제 #1
0
        /// <summary>
        /// Creates a new virtual disk image file and returns a Disk object associated with it.  The file name extension determines the
        /// type of Disk object actually returned.
        /// </summary>
        /// <param name="filename">File name of virtual disk image.</param>
        /// <param name="heads">Number of disk heads.</param>
        /// <param name="tracks">Number of disk tracks per head.</param>
        /// <param name="sectors">Number of disk sectors per track and per head.</param>
        /// <param name="sectorsize">The size of each sector measured in bytes.</param>
        /// <returns>A Disk object associated with the given file.</returns>
        public static IDisk CreateDisk(string filename, int heads, int tracks, int sectors, int sectorsize)
        {
            filename = filename.ToLowerInvariant();
            if (filename.EndsWith(".vdk"))
            {
                return(VdkDisk.Create(new FileStream(filename, FileMode.Create), heads, tracks, sectors));
            }
            if (filename.EndsWith(".dsk"))
            {
                return(JvcDisk.Create(new FileStream(filename, FileMode.Create), heads, tracks, sectors, sectorsize));
            }
            if (filename.EndsWith(".hfe"))
            {
                return(HfeDisk.Create(new FileStream(filename, FileMode.Create), heads, tracks, sectors, sectorsize));
            }
            if (filename.EndsWith(".dmk"))
            {
                return(DmkDisk.Create(new FileStream(filename, FileMode.Create), heads, tracks, sectors, sectorsize));
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Returns a Disk object associated with an existing virtual disk image file.  The name (extension) of the file name determines the
        /// type of Disk object actually returned.
        /// </summary>
        /// <param name="filename">File name of virtual disk image.</param>
        /// <param name="iswriteable">Returns a writeable Disk object if this is <value>true</value>.</param>
        /// <returns>A Disk object associated with the given file.</returns>
        public static IDisk OpenDisk(string filename, bool iswriteable)
        {
            filename = filename.ToLowerInvariant();
            var access = iswriteable ? FileAccess.ReadWrite : FileAccess.Read;

            if (filename.EndsWith(".vdk"))
            {
                return(VdkDisk.Open(new FileStream(filename, FileMode.Open, access), iswriteable));
            }
            if (filename.EndsWith(".dsk"))
            {
                return(JvcDisk.Open(new FileStream(filename, FileMode.Open, access), iswriteable));
            }
            if (filename.EndsWith(".hfe"))
            {
                return(HfeDisk.Open(new FileStream(filename, FileMode.Open, access), iswriteable));
            }
            if (filename.EndsWith(".dmk"))
            {
                return(DmkDisk.Open(new FileStream(filename, FileMode.Open, access), iswriteable));
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Reads a DMK disk image from a given stream.
        /// </summary>
        /// <param name="image">Stream containing the HFE disk image.</param>
        /// <param name="isWriteable">Allow write operations to this disk.</param>
        /// <returns>A disk object.</returns>
        public static DmkDisk Open(Stream image, bool isWriteable)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (!image.CanRead)
            {
                throw new NotSupportedException("Disk image stream does not support reading");
            }
            if (!image.CanSeek)
            {
                throw new NotSupportedException("Disk image stream does not support seeking");
            }
            if (isWriteable && !image.CanWrite)
            {
                throw new NotSupportedException("Disk image stream does not support writing");
            }

            var header = new DmkDiskHeader(image);

            if (header.IsSingleDensity)
            {
                throw new NotSupportedException("Single density disks not supported");
            }

            var disk = new DmkDisk();

            disk.diskImageStream = image;
            disk.IsWriteable     = isWriteable && header.IsWriteable;
            disk.Heads           = header.Heads;
            disk.Tracks          = header.Tracks;
            disk.TrackLength     = header.EncodedTrackLength;

            return(disk);
        }
예제 #4
0
        /// <summary>
        /// Reads a DMK disk image from a given stream.
        /// </summary>
        /// <param name="image">Stream containing the HFE disk image.</param>
        /// <param name="isWriteable">Allow write operations to this disk.</param>
        /// <returns>A disk object.</returns>
        public static DmkDisk Open(Stream image, bool isWriteable)
        {
            if (image == null) throw new ArgumentNullException("image");
            if (!image.CanRead) throw new NotSupportedException("Disk image stream does not support reading");
            if (!image.CanSeek) throw new NotSupportedException("Disk image stream does not support seeking");
            if (isWriteable && !image.CanWrite)
                throw new NotSupportedException("Disk image stream does not support writing");

            var header = new DmkDiskHeader(image);
            if (header.IsSingleDensity) throw new NotSupportedException("Single density disks not supported");

            var disk = new DmkDisk();
            disk.diskImageStream = image;
            disk.IsWriteable = isWriteable && header.IsWriteable;
            disk.Heads = header.Heads;
            disk.Tracks = header.Tracks;
            disk.TrackLength = header.EncodedTrackLength;

            return disk;
        }