/// <summary> /// Событие перемещения ползунка изменения позиции курсора в файле /// </summary> public void SliderFileValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (!(sender is null || e is null)) { SliderSizeManage.Tag = null; } if (g.FileManager is null) { return; } double percent = SliderSizeManage.Value / (SliderSizeManage.Maximum / 100); SlideFileInfo.Content = SliderSizeManage.Value.ToString(CultureInfo.CurrentCulture) + "/" + SliderSizeManage.Maximum.ToString(CultureInfo.CurrentCulture) + " byte(s) = " + (SliderSizeManage.Value < 1024 ? "0.0" : (Math.Round(SliderSizeManage.Value / 1048576, 2)).ToString(CultureInfo.CurrentCulture)) + "/" + (Math.Round(SliderSizeManage.Maximum / 1048576, 2)).ToString(CultureInfo.CurrentCulture) + " MB" + " [" + String.Format(CultureInfo.CurrentCulture, "{0:F6}", Math.Round(percent, 6)) + "%" + "]"; // g.FileManager.Position = (long)SliderSizeManage.Value; Dictionary <ReadingDirection, byte[]> showData = g.FileManager.ReadDataAboutPosition((long)SliderSizeManage.Value, g.CacheSize); string StartData; string EndData; switch (currentFormatResult?.ToLower(CultureInfo.CurrentCulture)) { case "hex": StartData = AdapterFileReader.BytesToHEX(showData[ReadingDirection.Left]); EndData = AdapterFileReader.BytesToHEX(showData[ReadingDirection.Rifht]); break; case "base64": StartData = Convert.ToBase64String(showData[ReadingDirection.Left]); EndData = Convert.ToBase64String(showData[ReadingDirection.Rifht]); break; default: StartData = AdapterFileReader.EncodingMode.GetString(showData[ReadingDirection.Left]); EndData = AdapterFileReader.EncodingMode.GetString(showData[ReadingDirection.Rifht]); break; } // ResultTextBox.Document.Blocks.Clear(); TextRange rangeStart = new TextRange(ResultTextBox.Document.ContentEnd, ResultTextBox.Document.ContentEnd) { Text = StartData }; rangeStart.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Indigo); TextRange rangeEnd = new TextRange(ResultTextBox.Document.ContentEnd, ResultTextBox.Document.ContentEnd) { Text = EndData }; rangeEnd.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Green); if (e == null) { return; } }
/// <summary> /// событие выбора исходного файла /// </summary> private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog { // Set filter options and filter index. Filter = "All Files (*.*)|*.*|Text Files (.txt)|*.txt", FilterIndex = 1, CheckPathExists = true, Multiselect = false }; // Call the ShowDialog method to show the dialog box. bool?userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (userClickedOK == true) { PathFile.Text = openFileDialog1.FileName; new ModifyRegistry().Write("last_read_file", PathFile.Text.Trim()); AdapterFileReader.SetEncoding(currentFormatResult); g.FileManager.OpenFile(openFileDialog1.FileName); SliderSizeManage.Maximum = g.FileManager.Length; SliderSizeManage.Value = 0; SliderFileValueChanged(null, null); } }
/// <summary> /// Событие выбора формата отображение из пункта контекстного меню /// </summary> private void SelectFormat_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; if (e != null) { currentFormatResult = Item.Tag?.ToString(); new ModifyRegistry().Write("display_format", currentFormatResult); AdapterFileReader.SetEncoding(currentFormatResult); } Item.Background = Brushes.PaleGoldenrod; Item.BorderBrush = Brushes.Red; MenuItem ParentItem = (MenuItem)Item.Parent; if (ParentItem.Parent is MenuItem) { SelectFormat_Click(ParentItem, null); } foreach (MenuItem li in ((MenuItem)Item.Parent).Items) { if (Item.Header.ToString() != li.Header.ToString()) { li.Background = Brushes.White; li.BorderBrush = null; foreach (MenuItem subLi in li.Items) { subLi.Background = Brushes.White; subLi.BorderBrush = null; } } } SliderFileValueChanged(null, null); }
/// <summary> /// запуск нарезки файла /// </summary> private void Button_Click_Start(object sender, RoutedEventArgs e) { if (DestinationFolderTextBox.Text.Trim().Length == 0 || !Directory.Exists(DestinationFolderTextBox.Text)) { System.Windows.MessageBox.Show(g.Dict["MessSpecifyDestinationFolder"].ToString(), g.Dict["MessError"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error); DestinationFolderTextBox.Focus(); return; } string DestinationFolderTextBoxText = DestinationFolderTextBox.Text; ProgressBarSplitFile.Value = 0; if (myOptions[OptionsEnum.Mode].ToLower(CultureInfo.CurrentCulture) == "size") { new SplitFileOfSizeDelegate(g.FileManager.SplitFile).BeginInvoke(DestinationFolderTextBox.Text, Convert.ToInt64(myOptions[OptionsEnum.extMode], CultureInfo.CurrentCulture), Convert.ToInt32(dimension_group.Text, CultureInfo.CurrentCulture), delegate { g.OpenFolder(DestinationFolderTextBoxText); }, null); } else { g.FileManager.Scanner.ClearMatchUnits(); if (((UcSplit)this.Tag).currentFormatResult.ToLower(CultureInfo.CurrentCulture) == "hex") { g.FileManager.Scanner.AddMatchUnit(new MatchUnitBytes(AdapterFileReader.HexToByte(myOptions[OptionsEnum.extMode]))); } else { g.FileManager.Scanner.AddMatchUnit(new MatchUnitText(myOptions[OptionsEnum.extMode], true)); } g.FileManager.ProgressValueChange += FileManager_ProgressValueChange; new SplitFileOfDataDelegate(g.FileManager.SplitFile).BeginInvoke(DestinationFolderTextBox.Text, Convert.ToInt32(dimension_group.Text, CultureInfo.CurrentCulture), delegate { g.OpenFolder(DestinationFolderTextBoxText); }, null); } }
private void Button_Click_StartSplit(object sender, RoutedEventArgs e) { if (!File.Exists(PathFile.Text.Trim())) { MessageBox.Show(g.Dict["txtFileNotExist"].ToString(), g.Dict["MessError"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error); return; } if (isModeOfSize.IsChecked.Value && (SliderSizeManage.Value <= 0 || SliderSizeManage.Value == SliderSizeManage.Maximum)) { MessageBox.Show(g.Dict["txtSelectCorrectFileSize"].ToString(), g.Dict["MessError"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error); return; } if (isModeOfText.IsChecked.Value && CutTextBox.Text.Length == 0) { MessageBox.Show(g.Dict["txtEnterTextCutFile"].ToString(), g.Dict["MessError"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error); return; } if (isModeOfText.IsChecked.Value) { SliderSizeManage.Value = 0; } if (isModeOfText.IsChecked.Value && currentFormatResult.ToLower(CultureInfo.CurrentCulture) == "hex" && !new System.Text.RegularExpressions.Regex(@"^(\w\w-)+\w\w$").IsMatch(CutTextBox.Text)) { MessageBoxResult result = MessageBox.Show(string.Format(CultureInfo.CurrentCulture, this.Resources.MergedDictionaries[0]["txtErrHEXTextCutFile"].ToString().Replace("\\n", Environment.NewLine), CutTextBox.Text, AdapterFileReader.StringToHEX(CutTextBox.Text)), "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { return; } CutTextBox.Text = AdapterFileReader.StringToHEX(CutTextBox.Text); } Dictionary <OptionsEnum, string> options = new Dictionary <OptionsEnum, string>() { { OptionsEnum.File, PathFile.Text }, { OptionsEnum.Mode, (isModeOfSize.IsChecked.Value ? "Size" : "Text") }, { OptionsEnum.extMode, (isModeOfSize.IsChecked.Value ? SliderSizeManage.Value.ToString(CultureInfo.CurrentCulture) : CutTextBox.Text) } }; FinalSplitWin doSplitForm = new FinalSplitWin(options) { // Owner = Window.GetWindow(this), Tag = this }; doSplitForm.ShowDialog(); }
/// <summary> /// Событие [найти следующее вхождение в файле] /// </summary> private void MenuItemFindPointCutText_Click(object sender, RoutedEventArgs e) { g.FileManager.Scanner.ClearMatchUnits(); if (currentFormatResult.ToLower(CultureInfo.CurrentCulture) == "hex") { g.FileManager.Scanner.AddMatchUnit(new MatchUnitBytes(AdapterFileReader.HexToByte(CutTextBox.Text))); } else { g.FileManager.Scanner.AddMatchUnit(new MatchUnitText(CutTextBox.Text, false)); //searchData = AdapterFileReader.StringToSearchBytes(CutTextBox.Text); } long index_detect_find_data; if (SliderSizeManage.Tag is null) { index_detect_find_data = g.FileManager.FindPositionData((long)SliderSizeManage.Value); } else { index_detect_find_data = (long)SliderSizeManage.Tag; index_detect_find_data = g.FileManager.FindPositionData(index_detect_find_data + 1); } if (index_detect_find_data < 0 || index_detect_find_data + g.FileManager.Scanner.MinDataLengthBytes >= g.FileManager.Length) { MessageBox.Show("End of file", "End of file", MessageBoxButton.OK, MessageBoxImage.Asterisk); } else { SliderSizeManage.Value = index_detect_find_data; if (index_detect_find_data > -1) { SliderSizeManage.Tag = index_detect_find_data; } } }