/// <summary> /// Update the UI from a given entry /// </summary> private void UpdateEntryUI(WerFaultEntry Entry) { txtDumpCount.Text = Entry.DumpCount.ToString(); txtImageName.Text = Entry.ImageName; txtDumpFolder.Text = Entry.DumpFolder; cbDumpType.SelectedIndex = Math.Max(0, Math.Min(2, Entry.DumpType)); // Update the custom dump flags foreach (var ctrl in flowLayoutPanelOptions.Controls) { var chk = ctrl as CheckBox; var opt = chk.Tag as CustomFlagsDef; chk.Checked = (Entry.CustomDumpFlags & (uint)opt.Flag) != 0; } if (Entry.CustomDumpFlags == 0) { (flowLayoutPanelOptions.Controls[0] as CheckBox).Checked = true; } }
/// <summary> /// Load a WerFault entry by name /// </summary> private WerFaultEntry LoadWerFaultEntry(string ImageName) { try { using (var reg = Registry.LocalMachine.OpenSubKey(Path.Combine(REGPATH_WER, ImageName))) { var Entry = new WerFaultEntry() { ImageName = ImageName, DumpType = (int)reg.GetValue(REGVAL_DUMPTYPE, 0), CustomDumpFlags = (uint)(int)reg.GetValue(REGVAL_CUSTOMDUMPFLAGS, 0), DumpCount = (int)reg.GetValue(REGVAL_DUMPCOUNT, 0), DumpFolder = (string)reg.GetValue(REGVAL_DUMPFOLDER, "") }; return(Entry); } } catch { return(null); } }
private void btnUpdateImage_Click(object sender, EventArgs e) { var Entry = new WerFaultEntry() { ImageName = Path.GetFileName(txtImageName.Text), DumpFolder = txtDumpFolder.Text, DumpType = cbDumpType.SelectedIndex }; if (string.IsNullOrEmpty(Entry.ImageName)) { MessageBox.Show("Please select an image name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtImageName.Focus(); return; } if (!Directory.Exists(Entry.DumpFolder)) { MessageBox.Show("Dump folder " + Entry.DumpFolder + " does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDumpFolder.Focus(); return; } if (!int.TryParse(txtDumpCount.Text, out Entry.DumpCount)) { MessageBox.Show("Dump count invalid. Specify a number > 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDumpCount.Focus(); return; } foreach (var ctrl in flowLayoutPanelOptions.Controls) { var chk = ctrl as CheckBox; var opt = chk.Tag as CustomFlagsDef; if (chk.Checked) { Entry.CustomDumpFlags |= (uint)opt.Flag; } } try { bool bNew; var regPath = Path.Combine(REGPATH_WER, Entry.ImageName); var reg = Registry.LocalMachine.OpenSubKey(regPath); if (reg == null) { bNew = true; } else { reg.Close(); bNew = false; } using (reg = Registry.LocalMachine.CreateSubKey(regPath)) { reg.SetValue(REGVAL_DUMPFOLDER, Entry.DumpFolder, RegistryValueKind.String); reg.SetValue(REGVAL_DUMPTYPE, Entry.DumpType, RegistryValueKind.DWord); reg.SetValue(REGVAL_CUSTOMDUMPFLAGS, Entry.CustomDumpFlags, RegistryValueKind.DWord); reg.SetValue(REGVAL_DUMPCOUNT, Entry.DumpCount, RegistryValueKind.DWord); } if (bNew) { lbConfiguredImages.Items.Add(Entry.ImageName); lbConfiguredImages.SelectedIndex = lbConfiguredImages.Items.Count - 1; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }