private void Append(byte[] buffer, int count) { string text = Encoding.ASCII.GetString(buffer, 0, count); TextView.SelectionStart = TextView.TextLength; TextView.SelectionLength = 0; TextView.SelectionColor = Color.Red; TextView.AppendText(text); TextView.ScrollToCaret(); StringBuilder builder = new StringBuilder(); for (int index = 0; index < count; index++) { builder.AppendFormat("{0:X2} ", buffer[index]); } HexView.SelectionStart = HexView.TextLength; HexView.SelectionLength = 0; HexView.SelectionColor = Color.Red; HexView.AppendText(builder.ToString()); HexView.ScrollToCaret(); }
private void OnPreviewTextInput(object sender, TextCompositionEventArgs e) { // 如果处于 HEX 模式, 只允许输入十六进制字符 if (HEXView.IsChecked != true) { return; } var regex = new Regex(@"^[0-9A-Fa-f]$"); if (!regex.IsMatch(e.Text)) { e.Handled = true; return; } if (string.IsNullOrEmpty(TextView.Text)) { return; } if (TextView.Text.Replace(" ", string.Empty).Length % 2 == 0) { TextView.AppendText(" "); TextView.CaretIndex = TextView.Text.Length; } }
private void OnLoaded(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog { DefaultExt = "ggpk", FileName = SteamMode ? "_.index.bin" : "Content.ggpk", Filter = SteamMode ? "Index Bundle File|*.index.bin" : "GGPK File|*.ggpk" }; var setting = Properties.Settings.Default; if (setting.GGPKPath == "") { string path; path = Registry.CurrentUser.OpenSubKey(@"Software\GrindingGearGames\Path of Exile")?.GetValue("InstallLocation") as string; if (path != null && File.Exists(path + @"\Content.ggpk")) // Get POE path { ofd.InitialDirectory = path.TrimEnd('\\'); } else { path = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Garena\PoE")?.GetValue("Path") as string; if (path != null && File.Exists(path + @"\Content.ggpk")) // Get Garena POE path { ofd.InitialDirectory = path.TrimEnd('\\'); } } } else { ofd.InitialDirectory = setting.GGPKPath; } if (ofd.ShowDialog() == true) { setting.GGPKPath = Directory.GetParent(ofd.FileName).FullName; setting.Save(); } else { Close(); return; } var mi = new MenuItem { Header = "Export" }; // Initial ContextMenu mi.Click += OnExportClicked; TreeMenu.Items.Add(mi); mi = new MenuItem { Header = "Replace" }; mi.Click += OnReplaceClicked; TreeMenu.Items.Add(mi); mi = new MenuItem { Header = "Recovery" }; mi.Click += OnRecoveryClicked; TreeMenu.Items.Add(mi); var imageMenu = new ContextMenu(); mi = new MenuItem { Header = "SaveAsPng" }; mi.Click += OnSavePngClicked; imageMenu.Items.Add(mi); ImageView.ContextMenu = imageMenu; ggpkContainer = new GGPKContainer(ofd.FileName, BundleMode, SteamMode); // Initial GGPK var root = CreateNode(ggpkContainer.rootDirectory); Tree.Items.Add(root); // Initial TreeView root.IsExpanded = true; TextView.AppendText("\r\n\r\nDone!\r\n"); }