增加诊断信息对话框

This commit is contained in:
ww-rm
2025-03-04 11:18:21 +08:00
parent dbdabda2a7
commit 0141f69c2a
6 changed files with 3508 additions and 23 deletions

View File

@@ -0,0 +1,117 @@
namespace SpineViewer.Dialogs
{
partial class DiagnosticsDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DiagnosticsDialog));
panel1 = new Panel();
tableLayoutPanel1 = new TableLayoutPanel();
button_Copy = new Button();
propertyGrid = new PropertyGrid();
panel1.SuspendLayout();
tableLayoutPanel1.SuspendLayout();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(tableLayoutPanel1);
panel1.Dock = DockStyle.Fill;
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Padding = new Padding(50, 15, 50, 10);
panel1.Size = new Size(901, 452);
panel1.TabIndex = 1;
//
// tableLayoutPanel1
//
tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.ColumnCount = 1;
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutPanel1.Controls.Add(button_Copy, 0, 1);
tableLayoutPanel1.Controls.Add(propertyGrid, 0, 0);
tableLayoutPanel1.Dock = DockStyle.Fill;
tableLayoutPanel1.Location = new Point(50, 15);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
tableLayoutPanel1.RowStyles.Add(new RowStyle());
tableLayoutPanel1.Size = new Size(801, 427);
tableLayoutPanel1.TabIndex = 0;
//
// button_Copy
//
button_Copy.Anchor = AnchorStyles.None;
button_Copy.AutoSize = true;
button_Copy.Location = new Point(326, 390);
button_Copy.Margin = new Padding(3, 10, 3, 3);
button_Copy.Name = "button_Copy";
button_Copy.Padding = new Padding(10, 0, 10, 0);
button_Copy.Size = new Size(148, 34);
button_Copy.TabIndex = 12;
button_Copy.Text = "复制到剪贴板";
button_Copy.UseVisualStyleBackColor = true;
button_Copy.Click += button_Copy_Click;
//
// propertyGrid
//
propertyGrid.Dock = DockStyle.Fill;
propertyGrid.HelpVisible = false;
propertyGrid.Location = new Point(3, 3);
propertyGrid.Name = "propertyGrid";
propertyGrid.Size = new Size(795, 374);
propertyGrid.TabIndex = 13;
propertyGrid.ToolbarVisible = false;
//
// DiagnosticsDialog
//
AutoScaleDimensions = new SizeF(11F, 24F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(901, 452);
Controls.Add(panel1);
Icon = (Icon)resources.GetObject("$this.Icon");
MaximizeBox = false;
MinimizeBox = false;
Name = "DiagnosticsDialog";
ShowInTaskbar = false;
StartPosition = FormStartPosition.CenterScreen;
Text = "诊断信息";
panel1.ResumeLayout(false);
panel1.PerformLayout();
tableLayoutPanel1.ResumeLayout(false);
tableLayoutPanel1.PerformLayout();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private TableLayoutPanel tableLayoutPanel1;
private Button button_Copy;
private PropertyGrid propertyGrid;
}
}

View File

@@ -0,0 +1,91 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Reflection;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpineViewer.Dialogs
{
public partial class DiagnosticsDialog : Form
{
public DiagnosticsDialog()
{
InitializeComponent();
propertyGrid.SelectedObject = new DiagnosticsInformation();
}
private class DiagnosticsInformation
{
[Category("Versions")]
public string WindowsVersion
{
get
{
var registryKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion";
var productName = Registry.GetValue(registryKeyPath, "ProductName", "Unknown") as string;
var editionId = Registry.GetValue(registryKeyPath, "EditionID", "Unknown") as string;
var osVersion = Environment.OSVersion.ToString();
return $"{productName}, {editionId}, {osVersion}";
}
}
[Category("Versions")]
public string Version
{
get => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
}
[Category("Versions")]
public string DotNetVersion
{
get => Environment.Version.ToString();
}
[Category("Versions")]
public string SFMLVersion
{
get => typeof(SFML.ObjectBase).Assembly.GetName().Version.ToString();
}
[Category("Hardwares")]
public string CPU
{
get => Registry.GetValue(@"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString", "Unknown").ToString();
}
[Category("Hardwares")]
public string Memory
{
get => $"{new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024f / 1024f / 1024f:F1} GB";
}
[Category("Hardwares")]
public string GPU
{
get
{
var searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_VideoController");
return string.Join("; ", searcher.Get().Cast<ManagementObject>().Select(mo => mo["Name"].ToString()));
}
}
}
private void button_Copy_Click(object sender, EventArgs e)
{
var selectedObject = propertyGrid.SelectedObject as DiagnosticsInformation;
var properties = selectedObject.GetType().GetProperties();
var result = string.Join(Environment.NewLine, properties.Select(p => $"{p.Name}\t{p.GetValue(selectedObject)?.ToString()}"));
Clipboard.SetText(result);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -57,6 +57,8 @@
spinePreviewer = new SpineViewer.Controls.SpinePreviewer();
panel_MainForm = new Panel();
toolTip = new ToolTip(components);
toolStripSeparator3 = new ToolStripSeparator();
toolStripMenuItem_Diagnostics = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitContainer_MainForm).BeginInit();
splitContainer_MainForm.Panel1.SuspendLayout();
@@ -103,40 +105,40 @@
//
toolStripMenuItem_Open.Name = "toolStripMenuItem_Open";
toolStripMenuItem_Open.ShortcutKeys = Keys.Control | Keys.O;
toolStripMenuItem_Open.Size = new Size(254, 34);
toolStripMenuItem_Open.Size = new Size(270, 34);
toolStripMenuItem_Open.Text = "打开(&O)...";
toolStripMenuItem_Open.Click += toolStripMenuItem_Open_Click;
//
// toolStripMenuItem_BatchOpen
//
toolStripMenuItem_BatchOpen.Name = "toolStripMenuItem_BatchOpen";
toolStripMenuItem_BatchOpen.Size = new Size(254, 34);
toolStripMenuItem_BatchOpen.Size = new Size(270, 34);
toolStripMenuItem_BatchOpen.Text = "批量打开(&B)...";
toolStripMenuItem_BatchOpen.Click += toolStripMenuItem_BatchOpen_Click;
//
// toolStripSeparator1
//
toolStripSeparator1.Name = "toolStripSeparator1";
toolStripSeparator1.Size = new Size(251, 6);
toolStripSeparator1.Size = new Size(267, 6);
//
// toolStripMenuItem_Export
//
toolStripMenuItem_Export.Name = "toolStripMenuItem_Export";
toolStripMenuItem_Export.ShortcutKeys = Keys.Control | Keys.S;
toolStripMenuItem_Export.Size = new Size(254, 34);
toolStripMenuItem_Export.Size = new Size(270, 34);
toolStripMenuItem_Export.Text = "导出(&E)...";
toolStripMenuItem_Export.Click += toolStripMenuItem_Export_Click;
//
// toolStripSeparator2
//
toolStripSeparator2.Name = "toolStripSeparator2";
toolStripSeparator2.Size = new Size(251, 6);
toolStripSeparator2.Size = new Size(267, 6);
//
// toolStripMenuItem_Exit
//
toolStripMenuItem_Exit.Name = "toolStripMenuItem_Exit";
toolStripMenuItem_Exit.ShortcutKeys = Keys.Alt | Keys.F4;
toolStripMenuItem_Exit.Size = new Size(254, 34);
toolStripMenuItem_Exit.Size = new Size(270, 34);
toolStripMenuItem_Exit.Text = "退出(&X)";
toolStripMenuItem_Exit.Click += toolStripMenuItem_Exit_Click;
//
@@ -150,13 +152,13 @@
// toolStripMenuItem_ResetAnimation
//
toolStripMenuItem_ResetAnimation.Name = "toolStripMenuItem_ResetAnimation";
toolStripMenuItem_ResetAnimation.Size = new Size(242, 34);
toolStripMenuItem_ResetAnimation.Size = new Size(270, 34);
toolStripMenuItem_ResetAnimation.Text = "重置动画时间(&R)";
toolStripMenuItem_ResetAnimation.Click += toolStripMenuItem_ResetAnimation_Click;
//
// toolStripMenuItem_Help
//
toolStripMenuItem_Help.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItem_About });
toolStripMenuItem_Help.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItem_Diagnostics, toolStripSeparator3, toolStripMenuItem_About });
toolStripMenuItem_Help.Name = "toolStripMenuItem_Help";
toolStripMenuItem_Help.Size = new Size(88, 28);
toolStripMenuItem_Help.Text = "帮助(&H)";
@@ -378,6 +380,18 @@
//
toolTip.ShowAlways = true;
//
// toolStripSeparator3
//
toolStripSeparator3.Name = "toolStripSeparator3";
toolStripSeparator3.Size = new Size(267, 6);
//
// toolStripMenuItem_Diagnostics
//
toolStripMenuItem_Diagnostics.Name = "toolStripMenuItem_Diagnostics";
toolStripMenuItem_Diagnostics.Size = new Size(270, 34);
toolStripMenuItem_Diagnostics.Text = "诊断信息(&D)";
toolStripMenuItem_Diagnostics.Click += toolStripMenuItem_Diagnostics_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(11F, 24F);
@@ -449,5 +463,7 @@
private Controls.SpinePreviewer spinePreviewer;
private ToolStripMenuItem toolStripMenuItem_Function;
private ToolStripMenuItem toolStripMenuItem_ResetAnimation;
private ToolStripMenuItem toolStripMenuItem_Diagnostics;
private ToolStripSeparator toolStripSeparator3;
}
}

View File

@@ -163,24 +163,17 @@ namespace SpineViewer
(new Dialogs.AboutDialog()).ShowDialog();
}
private void splitContainer_SplitterMoved(object sender, SplitterEventArgs e)
private void toolStripMenuItem_Diagnostics_Click(object sender, EventArgs e)
{
ActiveControl = null;
(new Dialogs.DiagnosticsDialog()).ShowDialog();
}
private void splitContainer_MouseUp(object sender, MouseEventArgs e)
{
ActiveControl = null;
}
private void splitContainer_SplitterMoved(object sender, SplitterEventArgs e) { ActiveControl = null; }
private void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
{
(sender as PropertyGrid)?.Refresh();
}
private void splitContainer_MouseUp(object sender, MouseEventArgs e) { ActiveControl = null; }
private void spinePreviewer_MouseUp(object sender, MouseEventArgs e)
{
propertyGrid_Spine.Refresh();
}
private void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { (sender as PropertyGrid)?.Refresh(); }
private void spinePreviewer_MouseUp(object sender, MouseEventArgs e) { propertyGrid_Spine.Refresh(); }
}
}

View File

@@ -19,7 +19,8 @@
<ItemGroup>
<PackageReference Include="NLog.Windows.Forms" Version="5.2.3" />
<PackageReference Include="SFML.Net" Version="2.6.0" />
<PackageReference Include="SFML.Net" Version="2.6.1" />
<PackageReference Include="System.Management" Version="9.0.2" />
</ItemGroup>
<ItemGroup>