internal static IDelegateCommand CreateSetAsEndCommand(IHexDataContext hexDataContext) { var setAsEndCommand = CommandFactory.CreateDelegateCommand(() => { if (hexDataContext.Stream == null) { return; } //Check if FocusPosition is valid; if (hexDataContext.FocusPosition == -1) { return; } if (hexDataContext.FocusPosition >= (hexDataContext.Stream.Length)) { return; } if (hexDataContext.SelectionStart != -1 && hexDataContext.SelectionLength != 0 && hexDataContext.SelectionStart < hexDataContext.FocusPosition) { hexDataContext.SelectionLength = hexDataContext.FocusPosition - hexDataContext.SelectionStart + 1; } else { hexDataContext.SelectionStart = hexDataContext.FocusPosition; hexDataContext.SelectionLength = 1; } }); return(setAsEndCommand); }
public void Handle(IHexDataContext hexContext) { //订阅位置变更事件; hexContext.FocusPositionChanged += (sender, e) => HandleOnFocusChanged(hexContext); //失去焦点时,移除状态栏项; //hexContext.LostFocus += (sender, e) => HandleOnLostFocus(hexContext); }
private static ICommandItem GetCopyAsProCommandItem(IHexDataContext hexDataContext, IBufferToCodeFormatter formatter) { var comm = CommandFactory.CreateDelegateCommand(() => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) { return; } if (hexDataContext.SelectionLength - hexDataContext.SelectionStart > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); return; } try { var buffer = GetSelectionData(hexDataContext); ClipBoardService.SetText(formatter.FormatAsCode(buffer)); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); } }); var cmi = CommandItemFactory.CreateNew(comm); cmi.Name = LanguageService.FindResourceString(formatter.CodeLanguageName); return(cmi); }
internal static IDelegateCommand CopyASCIIToCBoardCommand(IHexDataContext hexDataContext) { var copyASCIIToCBoardCommand = CommandFactory.CreateDelegateCommand( () => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) //若需剪切数据大于4GB { return; } if (hexDataContext.SelectionLength > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); } try { var buffer = hexDataContext.GetSelectionData(); ClipBoardService.SetDataObject(Encoding.ASCII.GetString(buffer, 0, buffer.Length)); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); MsgBoxService.Current?.Show($"{ex.Message}"); } }); return(copyASCIIToCBoardCommand); }
/// <summary> /// 通知当前的字符值; /// </summary> /// <param name="hexContext"></param> private static void ShowChar(IHexDataContext hexContext) { var curCharValueItem = StatusBarService.Current.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_CurCharValue, _curCharValueChildLength, 8); if (curCharValueItem == null) { return; } try { var stream = hexContext.Stream; if (stream == null) { LoggerService.WriteCallerLine($"{nameof(stream)} can't be null."); return; } stream.Position = hexContext.FocusPosition; StatusBarService.Report( $"{LanguageService.FindResourceString(Constants.StatusBarItemText_CurCharValue)} {stream.ReadByte()}", Constants.StatusBarItemGUID_CurCharValue); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); } }
public void Handle(IHexDataContext hexDataContext) { if (hexDataContext == null) { return; } var device = hexDataContext.GetInstance <IFile>(Contracts.FileExplorer.Constants.HexDataContextTag_File) as IDevice; if (device == null) { return; } if (device.PartitionEntries == null) { return; } int i = 0; foreach (var ti in device.PartitionEntries.OrderBy(p => p.StartLBA)) { hexDataContext.CustomBackgroundBlocks?.Add( BrushBlockFactory.CreateNewBackgroundBlock( ti.StartLBA, ti.Size, i++ % 2 == 0 ? BrushBlockFactory.FirstBrush : BrushBlockFactory.SecondBrush ) ); } hexDataContext.UpdateCustomBackgroundBlocks(); }
private static void HandleOnLostFocus(IHexDataContext hexContext) { var positionItem = StatusBarService.Current.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_Position, _positionChildLength, 4); //RemoveItem(positionItem); var curCharValueItem = StatusBarService.Current.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_CurCharValue, _curCharValueChildLength, 8); //RemoveItem(curCharValueItem); }
/// <summary> /// 保存修改的内容命令,暂未使用; /// </summary> /// <param name="hexDataContext"></param> /// <returns></returns> private static IDelegateCommand CreateSubmitChangesCommand(IHexDataContext hexDataContext) { var submitChangesCommand = CommandFactory.CreateDelegateCommand(() => { //SubmitChangesRequired?.Invoke(this, new EventArgs()); }); return(submitChangesCommand); }
private static IEnumerable <ICommandItem> GetCopyAsProCommandItems(IHexDataContext hexDataContext) { var formatters = ServiceProvider.GetAllInstances <IBufferToCodeFormatter>().OrderBy(p => p.Sort); foreach (var formatter in formatters) { yield return(GetCopyAsProCommandItem(hexDataContext, formatter)); } }
private static ICommandItem CreateEncodingCommand(IHexDataContext hexContext, IBytesToCharEncoding encoding) { var cmi = CommandItemFactory.CreateNew(new DelegateCommand(() => { hexContext.BytesToCharEncoding = encoding; })); cmi.Name = encoding.EncodingName; return(cmi); }
/// <summary> /// 检查是否存在可用的选中状态; /// </summary> /// <param name="hexDataContext"></param> /// <returns></returns> private static bool SelectionAvailable(IHexDataContext hexDataContext) { if (hexDataContext == null) { return(false); } return(hexDataContext.SelectionStart >= 0 && hexDataContext.SelectionLength > 0); }
private void AddKeyBindingsToHexDataContext(IHexDataContext hexDataContext) { if (hexDataContext == null) { throw new ArgumentNullException(nameof(hexDataContext)); } hexDataContext.AddKeyBinding(HexDataContextCommandFactory.CreateCopyToClipBoardCommand(hexDataContext), Key.C, ModifierKeys.Control); hexDataContext.AddKeyBinding(HexDataContextCommandFactory.CreateCopyToCopyHexToCBoardCommand(hexDataContext), Key.C, ModifierKeys.Control | ModifierKeys.Shift); }
private static void HandleOnFocusChanged(IHexDataContext hexContext) { if (hexContext == null) { return; } NotifyPosition(hexContext); ShowChar(hexContext); }
//加载Hex时若为DosDevice,进行高亮块; private void OnHexEditorLoaded(IHexDataContext hex) { //int i = 0; //if(hex.Data is DosDevice device) { // foreach (var ti in device.TableItems.OrderBy(p => p.Offset)) { // hex.CustomBackgroundBlocks?.Add((ti.Offset, ti.Length, i++ % 2 == 0 ? Brushes.Blue : Brushes.Red)); // } //} }
public void Handle(IHexDataContext hexDataContext) { if (hexDataContext == null) { return; } var part = hexDataContext.GetInstance <IFile>(Contracts.FileExplorer.Constants.HexDataContextTag_File) as IPartition; if (part == null) { return; } if (part.TypeGuid != Constants.PartitionType_FAT32) { return; } var fatPartInfo = part.GetInstance <FATPartInfo>(Constants.PartitionStokenTag_FATPartInfo); if (fatPartInfo == null) { LoggerService.WriteCallerLine($"{nameof(fatPartInfo)} can't be null."); return; } IEnumerable <(ICustomMemberDescriptor descriptor, long offset, string languagePrefix)> GetDescriptorTuples() { yield return(fatPartInfo.FatDBR, fatPartInfo.FatDBR?.Offset ?? 0, Constants.FATFieldPrefix_DBR); yield return(fatPartInfo.FatDBR_BackUp, fatPartInfo.FatDBR_BackUp?.Offset ?? 0, Constants.FATFieldPrefix_DBR); yield return(fatPartInfo.FatInfo, fatPartInfo.FatInfo?.Offset ?? 0, Constants.FATFieldPrefix_Info); yield return(fatPartInfo.FatInfo_BackUp, fatPartInfo.FatInfo_BackUp?.Offset ?? 0, Constants.FATFieldPrefix_Info); }; var infoIndex = 0; foreach (var tuple in GetDescriptorTuples().OrderBy(p => p.offset)) { if (tuple.descriptor == null) { continue; } hexDataContext.LoadCustomTypeDescriptor( tuple.descriptor, tuple.offset, infoIndex % 2 == 0?BrushBlockFactory.FirstBrush:BrushBlockFactory.SecondBrush, BrushBlockFactory.HighLightBrush ); infoIndex++; } }
public void Handle(IHexDataContext hexDataContext) { if (hexDataContext == null) { return; } if (!(hexDataContext.GetInstance <IFile>(Contracts.FileExplorer.Constants.HexDataContextTag_File) is IPartition part)) { return; } if (part.TypeGuid != Constants.PartitionType_Ext) { return; } var extPartInfo = part.GetInstance <ExtPartInfo>(Constants.PartitionStokenTag_ExtPartInfo); if (extPartInfo == null) { LoggerService.WriteCallerLine($"{nameof(extPartInfo)} can't be null."); return; } if (extPartInfo.SuperBlock != null) { var stSuperBlock = extPartInfo.SuperBlock.StructInstance; hexDataContext.LoadCustomTypeDescriptor(extPartInfo.SuperBlock, Constants.ExtSuperBlockStartIndex, BrushBlockFactory.FirstBrush, BrushBlockFactory.HighLightBrush); var descStart = (stSuperBlock.s_first_data_block + 1) * stSuperBlock.BlockSize; var descIndex = 0; if (extPartInfo.Ext4GroupDescs == null) { LoggerService.WriteCallerLine($"{nameof(extPartInfo.Ext4GroupDescs)} can't be null."); return; } foreach (var desc in extPartInfo.Ext4GroupDescs) { hexDataContext.LoadCustomTypeDescriptor( desc, descStart + descIndex * stSuperBlock.s_desc_size, descIndex % 2 == 0?BrushBlockFactory.FirstBrush:BrushBlockFactory.SecondBrush, BrushBlockFactory.HighLightBrush ); descIndex++; } //extPartInfo.StExt4GroupDescs } Handle(hexDataContext, extPartInfo); }
public void LoadHexDataContext(IHexDataContext hexDataContext) { if (hexDataContext == null) { throw new ArgumentNullException(nameof(hexDataContext)); } CommonEventHelper.PublishEventToHandlers(hexDataContext, _hexDataContextLoadedEventHandlers); CommonEventHelper.GetEvent <HexDataContextLoadedEvent>().Publish(hexDataContext); }
/// <summary> /// 拷贝至新文件; /// </summary> /// <param name="hexDataContext"></param> /// <returns></returns> public static ICommandItem CreateCopyToNewFileCommandItem(IHexDataContext hexDataContext) { if (hexDataContext == null) { throw new ArgumentNullException(nameof(hexDataContext)); } var cmi = CommandItemFactory.CreateNew(CreateCopyToNewFileCommand(hexDataContext)); cmi.Name = LanguageService.FindResourceString(Constants.ContextCommandName_CopyToNewFile); return(cmi); }
private static byte[] GetSelectionData(this IHexDataContext hexDataContext) { if (hexDataContext.SelectionLength > MaxCopyToClipBoardSize) { throw new InsufficientMemoryException(); } hexDataContext.Stream.Position = hexDataContext.SelectionStart; var buffer = new byte[hexDataContext.SelectionLength]; hexDataContext.Stream.Read(buffer, 0, (int)hexDataContext.SelectionLength); return(buffer); }
private static void AddContextCommandsToHexDataContext(IHexDataContext hexDataContext) { if (hexDataContext == null) { throw new ArgumentNullException(nameof(hexDataContext)); } hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateSetAsStartCommandItem(hexDataContext)); hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateSetAsEndCommandItem(hexDataContext)); hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateCopyToNewFileCommandItem(hexDataContext)); hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateCopyToClipBoardCommandItem(hexDataContext)); hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateCopyToCopyHexToCBoardCommandItem(hexDataContext)); hexDataContext.AddContextCommand(HexDataContextCommandFactory.CreateCopyAsProCodeCommandItem(hexDataContext)); }
public void Handle(IHexDataContext hexDataContext, ExtPartInfo extPartInfo) { //var propertyGridDataContext = hexDataContext.GetInstance<IPropertyGridDataContext>(); //if(propertyGridDataContext == null) { // propertyGridDataContext = PropertyGridDataContextFactory.CreateNew(); // hexDataContext.StackGrid.AddChild(propertyGridDataContext, new Contracts.Controls.GridChildLength(new System.Windows.GridLength(1, System.Windows.GridUnitType.Star))); // hexDataContext.SetInstance(propertyGridDataContext, HexDataContextTag_PropertyGridDataContext); //} //if(propertyGridDataContext == null) { // return; //} //propertyGridDataContext.AddCustomMemberDescriptor(extPartInfo.SuperBlock,LanguageService.FindResourceString(Constants.ExtSuperBlockGroupName)); }
public void Handle(IHexDataContext hexContext) { ThreadInvoker.BackInvoke(() => { var cmi = CommandItemFactory.CreateNew(null); cmi.Name = LanguageService.FindResourceString(Constants.ContextCommandName_EncodingSelect); foreach (var encoding in _bytesToCharEncodings) { cmi.AddChild(CreateEncodingCommand(hexContext, encoding)); } ThreadInvoker.UIInvoke(() => { hexContext.AddContextCommand(cmi); if (_bytesToCharEncodings.Length != 0) { hexContext.BytesToCharEncoding = _bytesToCharEncodings[0]; } }); }); }
/// <summary> /// 复制为代码; /// </summary> /// <param name="hexDataContext"></param> /// <returns></returns> public static ICommandItem CreateCopyAsProCodeCommandItem(IHexDataContext hexDataContext) { if (hexDataContext == null) { throw new ArgumentNullException(nameof(hexDataContext)); } var cmi = CommandItemFactory.CreateNew(CreateSetAsEndCommand(hexDataContext)); cmi.Name = LanguageService.FindResourceString(Constants.ContextCommandName_CopyAsProgramCode); var children = GetCopyAsProCommandItems(hexDataContext); foreach (var child in children) { cmi.AddChild(child); } return(cmi); }
/// <summary> /// 通知位置; /// </summary> /// <param name="hexContext"></param> private static void NotifyPosition(IHexDataContext hexContext) { var positionItem = StatusBarService.Current.GetOrCreateStatusBarTextItem(Constants.StatusBarItemGUID_Position, _positionChildLength, 4); if (positionItem == null) { return; } try { StatusBarService.Report( $"{LanguageService.FindResourceString(Constants.StatusBarItemText_Position)} {hexContext.FocusPosition}", Constants.StatusBarItemGUID_Position ); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); } }
public void Handle(IHexDataContext hexDataContext) { if (hexDataContext == null) { return; } if (!(hexDataContext.GetInstance <IFile>(Contracts.FileExplorer.Constants.HexDataContextTag_File) is IDevice device)) { return; } if (device.TypeGuid != Constants.DeviceType_DOS) { return; } var dosDeviceInfo = device.GetInstance <DOSDeviceInfo>(Constants.DeviceStokenTag_DOSDeviceInfo); if (dosDeviceInfo == null) { LoggerService.WriteCallerLine($"{nameof(dosDeviceInfo)} can't be null."); return; } var pTableIndex = 0; foreach (var p in dosDeviceInfo.DosPartInfos.OrderBy(p => p.DosPTable.StDosPTable.nOffset)) { if (p.InfoDisk != null) { hexDataContext.LoadCustomTypeDescriptor( p.InfoDisk, (long)p.DosPTable.StDosPTable.nOffset, pTableIndex % 2 == 0 ? BrushBlockFactory.FirstBrush : BrushBlockFactory.SecondBrush, BrushBlockFactory.HighLightBrush ); } pTableIndex++; } }
internal static IDelegateCommand CreateCopyToClipBoardCommand(IHexDataContext hexDataContext) { var copyToClipBoardCommand = CommandFactory.CreateDelegateCommand( () => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) { return; } //若需剪切数据大于4GB,提示警告; if (hexDataContext.SelectionLength - hexDataContext.SelectionStart > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); return; } hexDataContext.Stream.Position = hexDataContext.SelectionStart; InterceptStream sourceStream = null; StreamReader sr = null; try { sourceStream = InterceptStream.CreateFromStream( hexDataContext.Stream, hexDataContext.SelectionStart, hexDataContext.SelectionLength); sr = new StreamReader(sourceStream); ClipBoardService.SetDataObject(sr.ReadToEnd()); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); MsgBoxService.Current?.Show($"{ex.Message}"); } finally { sourceStream?.Dispose(); sr?.Dispose(); } }); return(copyToClipBoardCommand); }
/// <summary> /// 高亮结构体背景与ToolTip,PropertyGrid; /// </summary> /// <param name="hexDataContext"></param> /// <param name="offset">绝对偏移量</param> /// <param name="originBrush">默认颜色</param> /// <param name="fieldPrefix">字段高亮前缀值(语言相关)</param> /// <param name="highlightBrush">高亮颜色</param> /// <param name="languageKeyPrefix">语言前缀类型</param> public static void LoadCustomTypeDescriptor( this IHexDataContext hexDataContext, ICustomMemberDescriptor customMemberDescriptor, long offset, Brush originBrush, Brush highlightBrush ) { var memberInfos = customMemberDescriptor.GetMemberInfos(); var fieldOffset = 0; var toolTipAndBrushBlockTuples = new List <(IToolTipDataItem dataItem, IBrushBlock brushBlock, IMemberInfo memberInfo)?>(); foreach (var memberInfo in memberInfos) { var dataItem = ToolTipItemFactory.CreateIToolTipDataItem(); var brushBlock = BrushBlockFactory.CreateNewBackgroundBlock(); dataItem.KeyName = memberInfo.DisplayName + $"({memberInfo.MemberSize})"; dataItem.Value = memberInfo.Value?.ToString(); brushBlock.Background = originBrush; brushBlock.StartOffset = offset + fieldOffset; brushBlock.Length = memberInfo.MemberSize; toolTipAndBrushBlockTuples.Add((dataItem, brushBlock, memberInfo)); fieldOffset += memberInfo.MemberSize; } toolTipAndBrushBlockTuples.ForEach(p => { hexDataContext.CustomBackgroundBlocks.Add(p.Value.brushBlock); hexDataContext.CustomDataToolTipItems.Add((offset, fieldOffset, p.Value.dataItem)); }); //ToolTip悬停高亮; hexDataContext.SelectedToolTipItemChanged += delegate { if (hexDataContext.SelectedToolTipItem == null) { return; } toolTipAndBrushBlockTuples.ForEach(p => { p.Value.brushBlock.Background = originBrush; }); var slTuple = toolTipAndBrushBlockTuples.FirstOrDefault(p => p.Value.dataItem == hexDataContext.SelectedToolTipItem); if (slTuple == null) { return; } slTuple.Value.brushBlock.Background = highlightBrush; hexDataContext.UpdateCustomBackgroundBlocks(); }; //PropertyGrid部分; var(instance, isNew) = hexDataContext.GetOrCreateInstanceInform(Constants.HexDataContextTag_PropertyListDataContext, PropertyGridDataContextFactory.CreateNew); var propertyListDataContext = instance; if (propertyListDataContext == null) { return; } //若为首次创建,则加入视图; if (isNew) { hexDataContext.StackGrid.AddChild(propertyListDataContext, new Contracts.Controls.GridChildLength(new System.Windows.GridLength(1, System.Windows.GridUnitType.Star)), 1); } propertyListDataContext.AddCustomMemberDescriptor(customMemberDescriptor); //PropertyGrid选中属性高亮; propertyListDataContext.SelectedMemberInfoChanged += delegate { if (propertyListDataContext.SelectedMemberInfo == null) { return; } toolTipAndBrushBlockTuples.ForEach(p => { p.Value.brushBlock.Background = originBrush; }); var slTuple = toolTipAndBrushBlockTuples.FirstOrDefault(p => p.Value.memberInfo == propertyListDataContext.SelectedMemberInfo); if (slTuple == null) { return; } slTuple.Value.brushBlock.Background = highlightBrush; if (hexDataContext.BytePerLine != 0) { hexDataContext.Position = slTuple.Value.brushBlock.StartOffset / hexDataContext.BytePerLine * hexDataContext.BytePerLine; } hexDataContext.UpdateCustomBackgroundBlocks(); }; }
internal static IDelegateCommand CreateCopyToNewFileCommand(IHexDataContext hexDataContext) { var copyToNewFileCommand = CommandFactory.CreateDelegateCommand( () => { if (hexDataContext.SelectionLength == -1 || hexDataContext.SelectionStart == -1) { return; } var dialogService = ServiceProvider.Current.GetInstance <IDialogService>(); if (dialogService == null) { LoggerService.WriteCallerLine($"{nameof(dialogService)} can't be null."); return; } var path = dialogService.GetSaveFilePath(); if (path == null) { return; } var dialog = dialogService.CreateLoadingDialog(); dialog.WindowTitle = LanguageService.FindResourceString(Constants.WindowTitle_DataCopying); dialog.DoWork += (sender, e) => { FileStream fs = null; InterceptStream sourceStream = null; try { fs = File.Create(path); byte[] buffer = new byte[10485760]; int read; long readSize = 0; hexDataContext.Stream.Position = hexDataContext.SelectionStart; sourceStream = InterceptStream.CreateFromStream( hexDataContext.Stream, hexDataContext.SelectionStart, hexDataContext.SelectionLength); while ((read = sourceStream.Read(buffer, 0, buffer.Length)) != 0 && !dialog.CancellationPending) { fs.Write(buffer, 0, read); readSize += read; dialog.ReportProgress((int)(readSize * 100 / sourceStream.Length)); } } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); } finally { fs?.Dispose(); sourceStream?.Dispose(); } }; dialog.RunWorkerCompleted += (sender, e) => { if (e.Cancelled) { return; } LocalExplorerService.OpenFolderAndSelectFile(path); MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.WindowTitle_DataCopyDone)); }; dialog.ShowDialog(); }, () => SelectionAvailable(hexDataContext)); hexDataContext.SelectionStateChanged += delegate { copyToNewFileCommand.RaiseCanExecuteChanged(); }; return(copyToNewFileCommand); }
public void FindNextBytes(IHexDataContext hex, byte[] findBytes, FindMethod method) => FindNextBytes(hex, findBytes, method, false, -1, -1);
public void FindNextBytes(IHexDataContext hex, byte[] findBytes, FindMethod findMethod, bool isBlockSearch, int blockSize, int blockOffset) { if (findBytes == null || findBytes.Length == 0) { LoggerService.Current?.WriteCallerLine($"{nameof(findBytes)} can't be null or empty."); return; } if (isBlockSearch && (blockSize <= 0 || blockOffset < 0)) { throw new ArgumentException($"Invalid Argument(s):{nameof(blockSize)} or {nameof(blockOffset)}"); } long pos = (hex.FocusPosition == -1 ? 0 : hex.FocusPosition) + 1; var dialog = DialogService.Current.CreateLoadingDialog(); dialog.WindowTitle = findMethod == FindMethod.Text ? ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("SearchingForText") : ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("SearchingForHex"); dialog.DoWork += (sender, e) => { if (isBlockSearch) { pos = hex.Stream.SearchBlock(pos, blockSize, blockOffset, findBytes, index => { dialog.ReportProgress((int)(index * 100 / hex.Stream.Length)); }, () => dialog.CancellationPending); } else { pos = hex.Stream.Search(pos, findBytes, index => { dialog.ReportProgress((int)(index * 100 / hex.Stream.Length)); }, () => dialog.CancellationPending); } }; dialog.RunWorkerCompleted += (sender, e) => { if (e.Cancelled) { return; } if (pos == -1) { MsgBoxService.Show(LanguageService.FindResourceString("CannotFindTheContent")); return; } if (hex.BytePerLine <= 0) { LoggerService.WriteCallerLine($"{nameof(hex.BytePerLine)} can't be less than zero."); MsgBoxService.Show("Un expected error"); return; } hex.Position = pos / hex.BytePerLine * hex.BytePerLine; hex.FocusPosition = pos; }; dialog.ShowDialog(); }