Пример #1
0
        /// <summary>
        /// Create a new JVC disk associated with the given stream.
        /// </summary>
        /// <param name="image">Stream for storing the disk image.</param>
        /// <param name="heads">Number of disk heads.</param>
        /// <param name="tracks">Number of tracks per head.</param>
        /// <param name="sectors">Number of sectors per track.</param>
        /// <param name="sectorsize">Sector size in bytes</param>
        /// <returns>A disk object</returns>
        public static JvcDisk Create(Stream image, int heads, int tracks, int sectors, int sectorsize)
        {
            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 (!image.CanWrite)
            {
                throw new NotSupportedException("Disk image stream does not support writing");
            }

            var disk = new JvcDisk(image, heads, tracks, sectors, sectorsize);

            var header    = new JvcHeader(heads, tracks, sectors, sectorsize, false);
            var headerRaw = header.Encode();

            disk.diskHeaderSize   = headerRaw.Length;
            disk.sectorHeaderSize = 0;
            disk.IsWriteable      = true;
            disk.IsModified       = true;

            disk.DiskData = new byte[heads * tracks * sectors * sectorsize + disk.diskHeaderSize];
            Array.Copy(headerRaw, disk.DiskData, headerRaw.Length);

            return(disk);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Reads a JVC disk image from a given stream.
        /// </summary>
        /// <param name="image">Stream containing the disk image.</param>
        /// <param name="isWriteable">Allow write operations to this disk.</param>
        /// <returns>A disk object.</returns>
        public static JvcDisk 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");
            }

            var imageData = IOUtils.ReadStreamFully(image);
            var header    = JvcHeader.Parse(imageData);

            var disk = new JvcDisk(image, header.Heads, header.Tracks, header.Sectors, header.SectorSize);

            disk.DiskData         = imageData;
            disk.diskHeaderSize   = header.HeaderSize;
            disk.sectorHeaderSize = header.SectorAttribute ? 1 : 0;
            disk.IsWriteable      = (isWriteable && image.CanSeek && image.CanWrite);

            return(disk);
        }
Пример #4
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);
        }