Skip to content

Commit

Permalink
#31 Working ont the HexEditor. UpdateViewers() methods for added the …
Browse files Browse the repository at this point in the history
…abbility to insert anywhere... courage is on the way !!
  • Loading branch information
abbaye committed Feb 28, 2021
1 parent e66bfc1 commit dd68fd9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ private void OpenButton_Click(object sender, RoutedEventArgs e) =>
private void AddByteButton_Click(object sender, RoutedEventArgs e) =>
HexEditor.With(c =>
{
c.InsertByte(224, 15);
c.InsertByte(245, 16);
c.InsertByte(226, 17);
c.InsertByte(255, 15);
c.InsertByte(255, 16);
c.InsertByte(255, 17);
c.InsertByte(255, 18);
c.InsertByte(255, 19);
c.InsertByte(255, 20);
c.InsertByte(255, 21);

//Actually the visual not show the result. I'm working on this :)
c.RefreshView();
Expand Down
73 changes: 46 additions & 27 deletions Sources/WPFHexaEditor/HexEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,10 +2938,23 @@ private void UpdateViewers(bool controlResize)
#region Read the data from the provider and warns if necessary to load the bytes that have been deleted
_provider.Position = startPosition;
var readSize = 0;
if (HideByteDeleted)
if (HideByteDeleted || CanInsertAnywhere)
for (int i = 0; i < _viewBuffer.Length; i++)
{
if (!_provider.CheckIfIsByteModified(_provider.Position, ByteAction.Deleted).success)
//BYTE INSERT ANYWHERE IS IN DEVELOPMENT!! ///////////
//DOES NOT WORK CLEANLY! BE PATIENT
if (_provider.CheckIfIsByteModified(_provider.Position, ByteAction.Added).success)
{
if (_provider.Eof) continue;

var (success, val) = _provider.CheckIfIsByteModified(_provider.Position, ByteAction.Added);

_viewBuffer[readSize] = val.Byte.Value;
_viewBufferBytePosition[readSize] = val.BytePositionInStream;
readSize++;
}
/////////////////////////////////////////////////////
else if (!_provider.CheckIfIsByteModified(_provider.Position, ByteAction.Deleted).success)
{
if (_provider.Eof) continue;

Expand All @@ -2968,11 +2981,11 @@ private void UpdateViewers(bool controlResize)

#region HexByte panel refresh

TraverseHexBytes(ctrl =>
TraverseHexBytes(c =>
{
ctrl.Action = ByteAction.Nothing;
ctrl.ReadOnlyMode = ReadOnlyMode;
ctrl.InternalChange = true;
c.Action = ByteAction.Nothing;
c.ReadOnlyMode = ReadOnlyMode;
c.InternalChange = true;

var nextPos = startPosition + index;

Expand All @@ -2981,24 +2994,30 @@ private void UpdateViewers(bool controlResize)
while (_provider.CheckIfIsByteModified(nextPos, ByteAction.Deleted).success)
nextPos++;

//Insert byte
//if (CanInsertAnywhere)
//{
// var (success, val) = _provider.CheckIfIsByteModified(nextPos, ByteAction.Added);
//}

if (index < readSize && _priLevel == curLevel)
{
ctrl.Byte = ByteSize switch
c.Byte = ByteSize switch
{
ByteSizeType.Bit8 => new Byte_8bit(_viewBuffer[index]),
ByteSizeType.Bit16 => new Byte_16bit(new byte[] { _viewBuffer[index], _viewBuffer[index + 1] }),
ByteSizeType.Bit32 => new Byte_32bit(new byte[] { _viewBuffer[index], _viewBuffer[index + 1], _viewBuffer[index + 2], _viewBuffer[index + 3] }),
_ => throw new NotImplementedException()
};
ctrl.BytePositionInStream = !HideByteDeleted ? nextPos : _viewBufferBytePosition[index];
c.BytePositionInStream = !HideByteDeleted ? nextPos : _viewBufferBytePosition[index];

if (AllowVisualByteAddress && nextPos > VisualByteAdressStop)
ctrl.Clear();
c.Clear();
}
else
ctrl.Clear();
c.Clear();

ctrl.InternalChange = false;
c.InternalChange = false;
index += ByteSizeRatio;
});

Expand All @@ -3009,13 +3028,13 @@ private void UpdateViewers(bool controlResize)
#region StringByte / Barchart panel refresh

var skipNextIsMTE = false;
TraverseStringBytes(ctrl =>
TraverseStringBytes(c =>
{
ctrl.Action = ByteAction.Nothing;
ctrl.ReadOnlyMode = ReadOnlyMode;
ctrl.InternalChange = true;
ctrl.TblCharacterTable = _tblCharacterTable;
ctrl.TypeOfCharacterTable = TypeOfCharacterTable;
c.Action = ByteAction.Nothing;
c.ReadOnlyMode = ReadOnlyMode;
c.InternalChange = true;
c.TblCharacterTable = _tblCharacterTable;
c.TypeOfCharacterTable = TypeOfCharacterTable;

var nextPos = startPosition + index;

Expand All @@ -3028,37 +3047,37 @@ private void UpdateViewers(bool controlResize)
{
if (!skipNextIsMTE)
{
ctrl.BytePositionInStream = !HideByteDeleted ? nextPos : _viewBufferBytePosition[index];
c.BytePositionInStream = !HideByteDeleted ? nextPos : _viewBufferBytePosition[index];

#region Load ByteNext for TBL MTE matching
if (_tblCharacterTable is not null)
{
var (singleByte, succes) = _provider.GetByte(ctrl.BytePositionInStream + 1);
ctrl.ByteNext = succes ? singleByte : null;
var (singleByte, succes) = _provider.GetByte(c.BytePositionInStream + 1);
c.ByteNext = succes ? singleByte : null;
}
#endregion

//update byte
ctrl.Byte = new Byte_8bit(_viewBuffer[index]);
c.Byte = new Byte_8bit(_viewBuffer[index]);

//Bar chart value
ctrl.PercentValue = _viewBuffer[index] * 100 / 256;
c.PercentValue = _viewBuffer[index] * 100 / 256;

skipNextIsMTE = ctrl.IsMTE;
skipNextIsMTE = c.IsMTE;

if (AllowVisualByteAddress && nextPos > VisualByteAdressStop)
ctrl.Clear();
c.Clear();
}
else
{
skipNextIsMTE = false;
ctrl.Clear();
c.Clear();
}
}
else
ctrl.Clear();
c.Clear();

ctrl.InternalChange = false;
c.InternalChange = false;
index++;
});

Expand Down

0 comments on commit dd68fd9

Please sign in to comment.