Example #1
0
 /// <inheritdoc/>
 public void SeekSector(int sector)
 {
     CheckDisposed();
     disk.SeekAbs((long)sector * BYTES_PER_SECTOR);
 }
        public void Apply(DiskDevice dev, ProgressDelegate progress)
        {
            byte[] tmp = null;
            long total = 0, done = 0;
            foreach (var chg in _WriteOps)
                total += chg.SizeInBytes;

            foreach (var chg in _WriteOps)
            {
                if (tmp == null || tmp.Length < chg.SizeInBytes)
                    tmp = new byte[chg.SizeInBytes];

                if (chg.Zero)
                {
                    for (int i = 0; i < chg.SizeInBytes; i++)
                        tmp[i] = 0;
                }
                else
                {
                    _File.Seek((long)chg.OffsetInFile, SeekOrigin.Begin);
                    if (_File.Read(tmp, 0, chg.SizeInBytes) != chg.SizeInBytes)
                        throw new Exception("Failed to read change file at offset " + chg.OffsetInFile);
                }

                dev.SeekAbs((long)chg.OffsetInDevice);
                if (dev.Write(tmp, chg.SizeInBytes) != chg.SizeInBytes)
                    throw new Exception("Failed to write change at offset " + chg.OffsetInDevice);

                done += chg.SizeInBytes;
                if (progress != null)
                    progress(done, total);
            }
        }