コード例 #1
0
        public static string GetDiskInformation(Disk disk)
        {
            StringBuilder builder = new StringBuilder();

            if (disk is PhysicalDisk)
            {
                PhysicalDisk physicalDisk = (PhysicalDisk)disk;
                builder.AppendLine(physicalDisk.Description);
                builder.AppendLine("S/N: " + physicalDisk.SerialNumber);
                builder.AppendLine();
            }
            builder.AppendFormat("Size: {0} bytes\n", disk.Size.ToString("###,###,###,###,##0"));
            builder.AppendFormat("Bytes per sector (logical): {0}\n", disk.BytesPerSector);
            if (disk is PhysicalDisk)
            {
                PhysicalDisk physicalDisk = (PhysicalDisk)disk;
                builder.AppendFormat("Geometry: Cylinders: {0}, Heads: {1}, Sectors Per Track: {2}\n", physicalDisk.Cylinders, physicalDisk.TracksPerCylinder, physicalDisk.SectorsPerTrack);
            }
            else if (disk is DiskImage)
            {
                DiskImage diskImage = (DiskImage)disk;
                builder.AppendFormat("Disk image path: {0}\n", diskImage.Path);
            }
            builder.AppendLine();

            MasterBootRecord mbr = MasterBootRecord.ReadFromDisk(disk);

            if (mbr != null)
            {
                builder.AppendFormat("Partitioning scheme: {0}\n", (mbr.IsGPTBasedDisk ? "GPT" : "MBR"));
            }
            DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk);

            builder.AppendFormat("Disk type: {0}\n", ((dynamicDisk != null) ? "Dynamic Disk" : "Basic Disk"));
            if (dynamicDisk != null)
            {
                VolumeManagerDatabase database = VolumeManagerDatabase.ReadFromDisk(dynamicDisk);
                if (database != null)
                {
                    DiskRecord diskRecord = database.FindDiskByDiskGuid(dynamicDisk.PrivateHeader.DiskGuid);
                    if (diskRecord != null)
                    {
                        builder.AppendLine("Disk ID: " + diskRecord.DiskId);
                    }
                }
                builder.AppendLine("Disk GUID: " + dynamicDisk.PrivateHeader.DiskGuid);
                builder.AppendLine("Disk Group GUID: " + dynamicDisk.PrivateHeader.DiskGroupGuidString);
                builder.AppendLine();
                builder.AppendLine("Public region start sector: " + dynamicDisk.PrivateHeader.PublicRegionStartLBA);
                builder.AppendLine("Public region size (sectors): " + dynamicDisk.PrivateHeader.PublicRegionSizeLBA);
                builder.AppendLine();
                builder.AppendLine("Private region start sector: " + dynamicDisk.PrivateHeader.PrivateRegionStartLBA);
                builder.AppendLine("Private region size (sectors): " + dynamicDisk.PrivateHeader.PrivateRegionSizeLBA);
            }
            return(builder.ToString());
        }
コード例 #2
0
 public DiskLoadManager(DiskImage diskImage)
 {
     base.AddSerializer(new UdiSerializer(diskImage));
     base.AddSerializer(new FdiSerializer(diskImage));
     base.AddSerializer(new Td0Serializer(diskImage));
     base.AddSerializer(new TrdSerializer(diskImage));
     base.AddSerializer(new SclSerializer(diskImage));
     base.AddSerializer(new HobetaSerializer(diskImage));
     diskImage.SaveDisk += this.saveDisk;
 }
コード例 #3
0
ファイル: AddTargetForm.cs プロジェクト: ab932/iSCSIConsole
        private void btnAddDiskImage_Click(object sender, EventArgs e)
        {
            SelectDiskImageForm selectDiskImage = new SelectDiskImageForm();
            DialogResult        result          = selectDiskImage.ShowDialog();

            if (result == DialogResult.OK)
            {
                DiskImage diskImage = selectDiskImage.DiskImage;
                AddDisk(diskImage);
            }
        }
コード例 #4
0
 private void LoadDisk(DiskImage image, bool readOnly)
 {
     if (!string.IsNullOrEmpty(image.FileName))
     {
         OpenFileName(image.FileName, readOnly);
     }
     else
     {
         image.SetPhysics(80, 2);
         image.FormatTrdos();
     }
 }
コード例 #5
0
        private static byte GetSectorSize(int sectorSize, DiskImage diskImage)
        {
            for (byte i = 0; i < diskImage.SectorSizes.Length; i++)
            {
                if (diskImage.SectorSizes[i] >= sectorSize)
                {
                    return(i);
                }
            }

            throw new InvalidOperationException("Unknown sector size");
        }
コード例 #6
0
        public void Write(DiskImage diskImage)
        {
            xml.WriteStartElement("Image");
            xml.WriteAttributeString("creator", diskImage.Creator);
            xml.WriteAttributeString("fileName", Path.GetFileName(diskImage.FileName));

            var context = CreateContext(diskImage);

            WriteDefaults(context);
            Write(diskImage.Disk, context);

            xml.WriteEndElement();
        }
コード例 #7
0
        private static Sector ReadSector(Stream rs, DiskImage image)
        {
            var sector = new PD765Sector();

            sector.TrackId    = rs.ReadByte();
            sector.SideId     = rs.ReadByte();
            sector.Id         = rs.ReadByte();
            sector.Size       = CalculateSectorSize(image, rs.ReadByte());
            sector.Flag1      = (byte)rs.ReadByte();
            sector.Flag2      = (byte)rs.ReadByte();
            sector.DataLength = rs.ReadWord();
            return(sector);
        }
コード例 #8
0
        /// <summary>
        /// Read a sector from the disk
        /// </summary>
        /// <param name="lsn">Logical sector number to read</param>
        /// <returns>Array of bytes containing sector data</returns>
        private byte[] ReadLSN(int lsn)
        {
            if (lsn == 0)
            {
                return(DiskImage.ReadSector(0, 0, 1));
            }

            int track  = lsn / (LogicalSectors * LogicalHeads);
            int head   = (lsn / LogicalSectors) % LogicalHeads;
            int sector = (lsn % LogicalSectors) + 1;

            return(DiskImage.ReadSector(track, head, sector));
        }
コード例 #9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string path = txtFilePath.Text;

            if (path == String.Empty)
            {
                MessageBox.Show("Please choose file location.", "Error");
                return;
            }
            DiskImage diskImage;

            try
            {
                diskImage = DiskImage.GetDiskImage(path);
            }
            catch (IOException ex)
            {
                MessageBox.Show("Can't open disk image: " + ex.Message, "Error");
                return;
            }
            catch (InvalidDataException ex)
            {
                MessageBox.Show("Invalid disk image: " + ex.Message, "Error");
                return;
            }
            catch (NotImplementedException)
            {
                MessageBox.Show("Unsupported Disk Image Format", "Error");
                return;
            }

            diskImage.IsReadOnly = chkReadOnly.Checked;
            bool isLocked = false;

            try
            {
                isLocked = diskImage.ExclusiveLock();
            }
            catch (IOException)
            {
            }
            if (!isLocked)
            {
                MessageBox.Show("Cannot lock the disk image for exclusive access.", "Error");
                return;
            }
            m_diskImage       = diskImage;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #10
0
ファイル: BaseDiskFormat.cs プロジェクト: wzydhek/EmuDisk
        public void WriteLSN(int lsn, byte[] data)
        {
            if (lsn == 0)
            {
                DiskImage.WriteSector(0, 0, 1, data);
            }
            else
            {
                int track  = lsn / (LogicalSectors * LogicalHeads);
                int head   = (lsn / LogicalSectors) % LogicalHeads;
                int sector = (lsn % LogicalSectors) + 1;

                DiskImage.WriteSector(track, head, sector, data);
            }
        }
コード例 #11
0
        public DiskLoadManager(DiskImage diskImage)
        {
            AddSerializer(new UdiSerializer(diskImage));
            AddSerializer(new FdiSerializer(diskImage));
            AddSerializer(new Td0Serializer(diskImage));
            AddSerializer(new TrdSerializer(diskImage));
            AddSerializer(new ImgSerializer(diskImage));
            AddSerializer(new ProSerializer(diskImage));
            AddSerializer(new QdiSerializer(diskImage));
            AddSerializer(new SclSerializer(diskImage));
            AddSerializer(new HobetaSerializer(diskImage));

            diskImage.LoadDisk += LoadDisk;
            diskImage.SaveDisk += SaveDisk;
        }
コード例 #12
0
        public void OpenANonExistFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");

            IImageFile file = disk.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNull(file);

            System.IO.File.Delete(filename);
        }
コード例 #13
0
        private static void WriteTrack(Stream s, Track track, DiskImage diskImage)
        {
            var sectorDataPosition = s.Position + 0x100;

            s.WriteText(trackSignature);
            s.Ignore(3);

            s.WriteByte((byte)track.Number);
            s.WriteByte((byte)track.Side);

            if (track is FormattedTrack)
            {
                WriteFormattedTrack(s, (FormattedTrack)track, sectorDataPosition, diskImage);
            }
        }
コード例 #14
0
        public static void Write(DiskImage diskImage, Stream rs)
        {
            var signature = diskImage is StandardDskDiskImage
                            ? StandardDskDiskImage.Signature
                            : ExtendedDskDiskImage.Signature;

            rs.Position = 0;
            rs.WriteText(signature);

            rs.Position = 0x22;
            rs.WriteText(diskImage.Creator + '\0');

            rs.Position = 0x30;
            rs.WriteByte((byte)diskImage.Disk.TrackCount);
            rs.WriteByte((byte)diskImage.Disk.Sides.Count);

            var allTracks = diskImage.Disk.Sides.SelectMany(s => s.Tracks);

            if (diskImage is StandardDskDiskImage)
            {
                var maxTrackSize = allTracks.OfType <FormattedTrack>().Max(t => t.Size);
                rs.WriteWord((ushort)maxTrackSize);
            }

            if (diskImage is ExtendedDskDiskImage)
            {
                rs.Position += 2;
                foreach (var track in allTracks.OrderBy(t => t.Number).ThenBy(t => t.Side))
                {
                    if (track is FormattedTrack)
                    {
                        var trackSize = ((FormattedTrack)track).Size;
                        rs.WriteByte((byte)(trackSize / 256));
                    }
                    else
                    {
                        rs.WriteByte(0);
                    }
                }
            }

            rs.Position = 0x100;

            foreach (var track in allTracks)
            {
                WriteTrack(rs, track, diskImage);
            }
        }
コード例 #15
0
        //TODO: align copy plan with file map in disk image
        private static List <FileExtent> CreateCopyPlan(DiskImage image, IPartitioningInfo partInfo)
        {
            //TODO: figure out if it possible to quickly zero the whole disk so we can skip writing zero blocks.
            //Using allocation bitmap from the disk image will speed thing up if the disk is sparse.
            //However not writing zeros can cause data corruption.
            var diskImageBitmap = new BitArray((int)(image.Length / SECTOR_SIZE), true);

            if (partInfo != null)
            {
                var partBitmap = GetAllocationBitmap(image.Length, partInfo.Partitions);
                diskImageBitmap = diskImageBitmap.And(partBitmap);
            }

            var  ret      = new List <FileExtent>();
            long startLba = -1;
            long currentLba;

            for (currentLba = 0; currentLba < diskImageBitmap.Length; currentLba++)
            {
                if (startLba != -1 && (currentLba - startLba) >= MAX_CHUNK_LBAS)
                {
                    ret.Add(new FileExtent(startLba * SECTOR_SIZE, (currentLba - startLba) * SECTOR_SIZE));
                    startLba = -1;
                }

                if (diskImageBitmap[checked ((int)currentLba)])
                {
                    if (startLba == -1)
                    {
                        startLba = currentLba;
                    }
                }
                else if (startLba != -1)
                {
                    ret.Add(new FileExtent(startLba * SECTOR_SIZE, (currentLba - startLba) * SECTOR_SIZE));
                    startLba = -1;
                }
            }

            if (startLba != -1)
            {
                long offset = startLba * SECTOR_SIZE;
                ret.Add(new FileExtent(offset, image.Length - offset));
            }

            return(ret);
        }
コード例 #16
0
        private static Track ReadTrack(Stream rs, DiskImage image, uint trackSize)
        {
            if (rs.Position == rs.Length)
            {
                return(new UnformattedTrack());
            }

            var sectorData = rs.Position + 0x100;

            var trackSig = rs.ReadText(trackSignature.Length);

            if (!trackSig.Equals(trackSignature))
            {
                throw new InvalidDataException(String.Format("Missing track info at offset {0}", rs.Position));
            }

            rs.Ignore(3);

            var track = new PD765FormattedTrack();

            track.Number = (uint)rs.ReadByte();
            track.Side   = (byte)rs.ReadByte();
            track.Size   = trackSize;

            track.DataRate      = (byte)rs.ReadByte();
            track.RecordingMode = (byte)rs.ReadByte();
            track.SectorSize    = CalculateSectorSize(image, rs.ReadByte());
            track.SectorCount   = (byte)rs.ReadByte();

            track.Gap    = (byte)rs.ReadByte();
            track.Filler = (byte)rs.ReadByte();

            for (var i = 0; i < track.SectorCount; i++)
            {
                track.Sectors.Add(ReadSector(rs, image));
            }

            rs.Seek(sectorData, SeekOrigin.Begin);

            foreach (var sector in track.Sectors)
            {
                sector.Data = rs.ReadBlock(sector.Size);
            }

            return(track);
        }
コード例 #17
0
        static bool getParitionInfo(DiskImage image, out IPartitioningInfo info)
        {
            GptPartitioningInfo gpt;

            if (GptPartitioningInfo.TryGetGptInfo(image, out gpt))
            {
                info = gpt;
                return(true);
            }
            MbrPartitioningInfo mbr;

            if (MbrPartitioningInfo.TryGetMbrInfo(image, out mbr))
            {
                info = mbr;
                return(true);
            }
            info = null;
            return(false);
        }
コード例 #18
0
        public Wd1793(int driveCount)
        {
            if (driveCount < 1 || driveCount > 4)
            {
                throw new ArgumentException("driveCount");
            }
            drive = 0;
            fdd   = new DiskImage[driveCount];
            for (int i = 0; i < fdd.Length; i++)
            {
                DiskImage di = new DiskImage();
                di.Init(Z80FQ / FDD_RPS);
                //di.Format();  // take ~1 second (long delay on show options)
                fdd[i] = di;
            }
            fdd[drive].t = fdd[drive].CurrentTrack;

            //fdd[i].set_appendboot(NULL);

            wd93_nodelay = false;
        }
コード例 #19
0
ファイル: TrueCryptResize.cs プロジェクト: radtek/TrueResize
        public static void FillAllocatedSpaceWithData(DiskImage disk, long startSector, long sectorCount, ref long bytesWritten)
        {
            const int DirectTransferSizeLBA = 2048; // 1 MB (assuming 512-byte sectors)

            byte[] data        = new byte[DirectTransferSizeLBA * disk.BytesPerSector];
            Random random      = new Random();
            long   sectorIndex = startSector;

            while (sectorIndex < startSector + sectorCount)
            {
                long sectorsToWrite = startSector + sectorCount - sectorIndex;
                if (sectorsToWrite < DirectTransferSizeLBA)
                {
                    data = new byte[sectorsToWrite * disk.BytesPerSector];
                }
                random.NextBytes(data);
                disk.WriteSectors(sectorIndex, data);
                sectorIndex  += DirectTransferSizeLBA;
                bytesWritten += data.Length;
            }
        }
コード例 #20
0
        public void CreateWriteLoadReadMultiTrackFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = new byte[2000];
            for (int i = 0; i < 2000; ++i)
            {
                data[i] = (byte)(i % 256);
            }
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Close();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[3000];
            Assert.AreEqual(2000, file1.Read(data1, 3000));
            byte[] trucatedData = new byte[2000];
            Array.Copy(data1, trucatedData, 2000);
            for (int i = 0; i < 2000; ++i)
            {
                Assert.AreEqual(i % 256, trucatedData[i]);
            }
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
コード例 #21
0
        private WriteContext CreateContext(DiskImage image)
        {
            var tracks = image.Disk.Sides
                         .SelectMany(s => s.Tracks)
                         .OfType <FormattedTrack>()
                         .ToList();

            var sectors = tracks
                          .SelectMany(f => f.Sectors)
                          .ToList();

            return(new WriteContext {
                DefaultTrack = new FormattedTrack {
                    Gap = tracks.MostCommon(t => t.Gap),
                    Filler = tracks.MostCommon(t => t.Filler),
                    Size = tracks.MostCommon(t => t.Size)
                },
                DefaultSector = new Sector {
                    Size = sectors.MostCommon(s => s.Size)
                }
            });
        }
コード例 #22
0
 private void applyDrive(DiskImage diskImage, CheckBox chkPresent, TextBox txtPath, CheckBox chkProtect)
 {
     if (diskImage == null)
     {
         return;
     }
     var fileName = txtPath.Text;
     if (fileName != string.Empty)
     {
         if (!File.Exists(Path.GetFullPath(fileName)) &&
             chkPresent.Checked)
         {
             throw new FileNotFoundException(
                 string.Format(
                     "File not found: \"{0}\"",
                     fileName));
         }
         fileName = Path.GetFullPath(fileName);
     }
     diskImage.Present = chkPresent.Checked;
     diskImage.FileName = fileName;
     diskImage.IsWP = chkProtect.Checked;
 }
コード例 #23
0
ファイル: AddTargetForm.cs プロジェクト: ab932/iSCSIConsole
 private void btnCreateDiskImage_Click(object sender, EventArgs e)
 {
     if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
     {
         CreateRAMDiskForm createRAMDisk = new CreateRAMDiskForm();
         DialogResult      result        = createRAMDisk.ShowDialog();
         if (result == DialogResult.OK)
         {
             RAMDisk ramDisk = createRAMDisk.RAMDisk;
             AddDisk(ramDisk);
         }
     }
     else
     {
         CreateDiskImageForm createDiskImage = new CreateDiskImageForm();
         DialogResult        result          = createDiskImage.ShowDialog();
         if (result == DialogResult.OK)
         {
             DiskImage diskImage = createDiskImage.DiskImage;
             AddDisk(diskImage);
         }
     }
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: krzychuwr1/expert-goggles
        static void Main(string[] args)
        {
            var file         = new FileInfo("..//..//resources/USB-disk-image-FAT.E01");
            var diskImage    = new DiskImage(file);
            int volumeAdress = 2;

            using (VolumeSystem volumeSystem = diskImage.OpenVolumeSystem())
            {
                Volume volume = volumeSystem.Volumes.SingleOrDefault(v => v.Address == volumeAdress);

                //Assert.NotNull(volume);

                using (FileSystem fileSystem = volume.OpenFileSystem())
                {
                    //count += CountFiles(fileSystem.OpenRootDirectory());
                    fileSystem.WalkDirectories(
                        FindFiles_DirectoryWalkCallback,
                        DirWalkFlags.Recurse | DirWalkFlags.Unallocated);
                }
                Console.ReadKey();
                //Assert.AreEqual(37, FilePaths.Count()); //I think it should be 63 || Bala: Autopsy shows me that there are only 30 files
            }
        }
コード例 #25
0
        private static void WriteFormattedTrack(Stream s, FormattedTrack track, long sectorDataPosition, DiskImage diskImage)
        {
            if (track is PD765FormattedTrack)
            {
                var pdTrack = (PD765FormattedTrack)track;
                s.WriteByte(pdTrack.DataRate);
                s.WriteByte(pdTrack.RecordingMode);
                s.WriteByte(GetSectorSize(pdTrack.SectorSize, diskImage));
            }
            else
            {
                s.WriteByte(0);
                s.WriteByte(0);
                s.WriteByte(0);
            }

            s.WriteByte((byte)track.Sectors.Count);
            s.WriteByte(track.Gap);
            s.WriteByte(track.Filler);

            foreach (var sector in track.Sectors)
            {
                WriteSectorHeader(s, sector);
            }

            s.Position = sectorDataPosition;

            foreach (var sector in track.Sectors)
            {
                s.Write(sector.Data, 0, sector.Data.Length);
            }
        }
コード例 #26
0
 public QdiSerializer(DiskImage diskImage)
     : base(diskImage)
 {
 }
コード例 #27
0
        public static void Write(DiskImage diskImage, string fileName)
        {
            var output = File.OpenWrite(fileName);

            Write(diskImage, output);
        }
コード例 #28
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string path = txtFilePath.Text;
            long   size = (long)numericDiskSize.Value * 1024 * 1024;

            if (path == String.Empty)
            {
                MessageBox.Show("Please choose file location", "Error");
                return;
            }
            m_isWorking = true;
            new Thread(delegate()
            {
                DiskImage diskImage;
                try
                {
                    diskImage = VirtualHardDisk.CreateFixedDisk(path, size);
                }
                catch (IOException ex)
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        MessageBox.Show("Failed to create the disk: " + ex.Message, "Error");
                        txtFilePath.Enabled     = true;
                        btnBrowse.Enabled       = true;
                        numericDiskSize.Enabled = true;
                        btnOK.Enabled           = true;
                        btnCancel.Enabled       = true;
                    });
                    m_isWorking = false;
                    return;
                }
                bool isLocked = diskImage.ExclusiveLock();
                if (!isLocked)
                {
                    this.Invoke((MethodInvoker) delegate()
                    {
                        MessageBox.Show("Cannot lock the disk image for exclusive access", "Error");
                        txtFilePath.Enabled     = true;
                        btnBrowse.Enabled       = true;
                        numericDiskSize.Enabled = true;
                        btnOK.Enabled           = true;
                        btnCancel.Enabled       = true;
                    });
                    m_isWorking = false;
                    return;
                }
                m_diskImage = diskImage;
                m_isWorking = false;
                this.Invoke((MethodInvoker) delegate()
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                });
            }).Start();
            txtFilePath.Enabled     = false;
            btnBrowse.Enabled       = false;
            numericDiskSize.Enabled = false;
            btnOK.Enabled           = false;
            btnCancel.Enabled       = false;
        }
コード例 #29
0
        public static void SelectCommand(string[] args)
        {
            if (args.Length == 1)
            {
                HelpSelect();
                return;
            }

            switch (args[1].ToLower())
            {
            case "disk":
            {
                if (args.Length == 3)
                {
                    int diskIndex = Conversion.ToInt32(args[2], -1);
                    if (diskIndex >= 0)
                    {
                        PhysicalDisk disk = null;
                        try
                        {
                            disk = new PhysicalDisk(diskIndex);
                        }
                        catch
                        {
                            Console.WriteLine();
                            Console.WriteLine("Error: Invalid disk number");
                        }

                        if (disk != null)
                        {
                            m_selectedDisk = disk;
                        }
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: Invalid number of arguments");
                }
                break;
            }

            case "vdisk":
            {
                if (args.Length == 3)
                {
                    KeyValuePairList <string, string> parameters = ParseParameters(args, 2);
                    if (parameters.ContainsKey("file"))
                    {
                        string path = parameters.ValueOf("file");
                        if (new FileInfo(path).Exists)
                        {
                            try
                            {
                                m_selectedDisk = DiskImage.GetDiskImage(path);
                            }
                            catch (InvalidDataException)
                            {
                                Console.WriteLine("Invalid virtual disk format");
                            }
                            catch (NotImplementedException)
                            {
                                Console.WriteLine("Unsupported virtual disk format");
                            }
                            catch (IOException ex)
                            {
                                Console.WriteLine("Cannot read file: " + ex.Message);
                            }
                        }
                        else
                        {
                            Console.WriteLine("File not found: \"{0}\"", path);
                        }
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Invalid argument");
                    }
                }
                else
                {
                    Console.WriteLine("Error: Invalid number of arguments");
                }
                break;
            }

            case "partition":
            {
                if (m_selectedDisk != null)
                {
                    if (args.Length == 3)
                    {
                        int partitionIndex          = Conversion.ToInt32(args[2], -1);
                        List <Partition> partitions = BasicDiskHelper.GetPartitions(m_selectedDisk);
                        if (partitionIndex >= 0 && partitionIndex < partitions.Count)
                        {
                            m_selectedVolume = partitions[partitionIndex];
                        }
                        else
                        {
                            Console.WriteLine("Error: Invalid partition number");
                        }
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Partition number was not specified");
                    }
                }
                else
                {
                    Console.WriteLine("No disk has been selected");
                }
                break;
            }

            case "volume":
            {
                if (args.Length == 3)
                {
                    List <Volume> volumes;
                    try
                    {
                        volumes = WindowsVolumeHelper.GetVolumes();
                    }
                    catch
                    {
                        volumes = new List <Volume>();
                    }

                    int volumeIndex = Conversion.ToInt32(args[2], -1);
                    if (volumeIndex >= 0 && volumeIndex < volumes.Count)
                    {
                        m_selectedVolume = volumes[volumeIndex];
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Invalid volume number");
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: Volume number was not specified");
                }
                break;
            }

            default:
                HelpSelect();
                break;
            }
        }
コード例 #30
0
        IDiskImagePolicy.CreateDMG(
            DiskImage sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString sourceFolderPath,
            Bam.Core.TokenizedString outputPath)
        {
            var volumeName            = sender.CreateTokenizedString("$(OutputName)").Parse();
            var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension
            var diskImagePathName     = outputPath.ToString();

            var commandLine = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            // create the disk image
            {
                var settings = sender.Settings as IDiskImageSettings;

                var args = new Bam.Core.StringArray();
                args.Add("create");
                args.AddRange(commandLine);
                args.Add("-srcfolder");
                args.Add(System.String.Format("\"{0}\"", sourceFolderPath.ToString()));
                args.Add("-size");
                args.Add(settings.ImageSize);
                args.Add("-fs");
                args.Add("HFS+");
                args.Add("-volname");
                args.Add(System.String.Format("\"{0}\"", volumeName));
                args.Add(tempDiskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            // mount disk image
            {
                var args = new Bam.Core.StringArray();
                args.Add("attach");
                args.AddRange(commandLine);
                args.Add(tempDiskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            // TODO
            /// do a copy

            // unmount disk image
            {
                var args = new Bam.Core.StringArray();
                args.Add("detach");
                args.AddRange(commandLine);
                args.Add(System.String.Format("\"/Volumes/{0}\"", volumeName));
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            var dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dmgDir);

            // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg
            {
                var args = new Bam.Core.StringArray();
                args.Add("convert");
                args.AddRange(commandLine);
                args.Add(tempDiskImagePathName);
                args.Add("-format");
                args.Add("UDZO");
                args.Add("-o");
                args.Add(diskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }
        }
コード例 #31
0
        IDiskImagePolicy.CreateDMG(
            DiskImage sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString sourceFolderPath,
            Bam.Core.TokenizedString outputPath)
        {
            var volumeName = sender.CreateTokenizedString("$(OutputName)").Parse();
            var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension
            var diskImagePathName = outputPath.ToString();

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            // create the disk image
            {
                var settings = sender.Settings as IDiskImageSettings;

                var args = new Bam.Core.StringArray();
                args.Add("create");
                args.AddRange(commandLine);
                args.Add("-srcfolder");
                args.Add(System.String.Format("\"{0}\"", sourceFolderPath.ToString()));
                args.Add("-size");
                args.Add(settings.ImageSize);
                args.Add("-fs");
                args.Add("HFS+");
                args.Add("-volname");
                args.Add(System.String.Format("\"{0}\"", volumeName));
                args.Add(tempDiskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            // mount disk image
            {
                var args = new Bam.Core.StringArray();
                args.Add("attach");
                args.AddRange(commandLine);
                args.Add(tempDiskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            // TODO
            /// do a copy

            // unmount disk image
            {
                var args = new Bam.Core.StringArray();
                args.Add("detach");
                args.AddRange(commandLine);
                args.Add(System.String.Format("\"/Volumes/{0}\"", volumeName));
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }

            var dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName);
            if (!System.IO.Directory.Exists(dmgDir))
            {
                System.IO.Directory.CreateDirectory(dmgDir);
            }

            // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg
            {
                var args = new Bam.Core.StringArray();
                args.Add("convert");
                args.AddRange(commandLine);
                args.Add(tempDiskImagePathName);
                args.Add("-format");
                args.Add("UDZO");
                args.Add("-o");
                args.Add(diskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }
        }