protected void FillPreviousData()
 {
     Debug.Assert(dataPosition > 0);
     Debug.Assert(dataIndex == -1);
     CancellationToken.ThrowIfCancellationRequested();
     dataLength    = (int)HexPosition.Min(dataPosition, Data.Length).ToUInt64();
     dataPosition -= dataLength;
     dataIndex     = dataLength - 1;
     Buffer.ReadBytes(dataPosition, Data, 0, dataLength);
 }
Beispiel #2
0
		protected void UpdateValue() {
			if (disable_UpdateValue)
				return;
			if (DataFieldVM.HasError)
				return;
			var newData = GetDataAsByteArray();
			Debug2.Assert(!(newData is null) && newData.LongLength == Span.Length);

			var origData = buffer.ReadBytes(Span.Start, newData.LongLength);
			if (Equals(newData, origData))
				return;

			buffer.Replace(Span.Start, newData);
			OnUpdateValue();
		}
        public void Execute(IProgress progress)
        {
            progress.SetDescription(filename);
            var file = File.Create(filename);

            try {
                var  buf             = new byte[BUF_SIZE];
                var  pos             = span.Start;
                long currentProgress = 0;
                while (pos < span.End)
                {
                    progress.ThrowIfCancellationRequested();
                    progress.SetTotalProgress(currentProgress);
                    currentProgress++;
                    ulong left = (span.End - pos).ToUInt64();
                    if (left == 0)
                    {
                        left = ulong.MaxValue;
                    }
                    int size = left > (ulong)buf.Length ? buf.Length : (int)left;
                    buffer.ReadBytes(pos, buf, 0, size);
                    file.Write(buf, 0, size);
                    pos += (ulong)size;
                }
                progress.SetTotalProgress(currentProgress);
            }
            catch {
                file.Dispose();
                try { File.Delete(filename); }
                catch { }
                throw;
            }
            finally {
                file.Dispose();
            }
        }