Browse Source

commit: add amd gpu usage support; add command-line `--no-perf' to disable performance counts

HOME 3 years ago
parent
commit
9ac04f5ae4
5 changed files with 107 additions and 17 deletions
  1. 4 0
      BsWidget/BsWidget.csproj
  2. 22 16
      BsWidget/MainForm.cs
  3. 5 0
      BsWidget/Program.cs
  4. 75 0
      BsWidget/app.manifest
  5. 1 1
      BsYurHttpStatus/manifest.json

+ 4 - 0
BsWidget/BsWidget.csproj

@@ -40,6 +40,9 @@
   <PropertyGroup>
     <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
   </PropertyGroup>
+  <PropertyGroup>
+    <ApplicationManifest>app.manifest</ApplicationManifest>
+  </PropertyGroup>
   <ItemGroup>
     <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>C:\NuGetLocalRepo\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -92,6 +95,7 @@
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
     </EmbeddedResource>
+    <None Include="app.manifest" />
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>

+ 22 - 16
BsWidget/MainForm.cs

@@ -88,23 +88,29 @@ namespace BsWidget
             _yurClient = new BsYurHttpStatusClient();
             _yurClient.Event += Yur_Event;
 
-            _computer = new Computer();
-            _computer.CPUEnabled = true;
-            _computer.GPUEnabled = true;
-            _computer.FanControllerEnabled = false;
-            _computer.HDDEnabled = false;
-            _computer.MainboardEnabled = false;
-            _computer.RAMEnabled = false;
-            _computer.Open();
+            if (Program.NoPerf)
+            {
+            }
+            else
+            {
+                _computer = new Computer();
+                _computer.CPUEnabled = true;
+                _computer.GPUEnabled = true;
+                _computer.FanControllerEnabled = false;
+                _computer.HDDEnabled = false;
+                _computer.MainboardEnabled = false;
+                _computer.RAMEnabled = false;
+                _computer.Open();
+
+                _pcTimer = new Timer { Interval = 750 };
+                _pcTimer.Tick += PcTimer_Tick;
+            }
 
             _queue = new BlockingCollection<UpdateFlags>();
             CutHistory = new List<HistoryModel>();
 
             _updateTimer = new Timer { Interval = 25 };
             _updateTimer.Tick += UpdateTimer_Tick;
-
-            _pcTimer = new Timer { Interval = 750 };
-            _pcTimer.Tick += PcTimer_Tick;
         }
 
         protected override void OnLoad(EventArgs e)
@@ -115,9 +121,9 @@ namespace BsWidget
             TopMost = false;
             WindowState = FormWindowState.Normal;
             _updateTimer.Start();
-            _pcTimer.Start();
             _client.Start();
             _yurClient.Start();
+            _pcTimer?.Start();
         }
 
         protected override void OnMouseDoubleClick(MouseEventArgs e)
@@ -151,7 +157,7 @@ namespace BsWidget
         {
             _client.Stop();
             _yurClient.Stop();
-            _computer.Close();
+            _computer?.Close();
             base.OnFormClosed(e);
         }
 
@@ -253,7 +259,7 @@ namespace BsWidget
         {
             try
             {
-                foreach (var hardware in _computer.Hardware.Where(p => p.HardwareType == HardwareType.CPU || p.HardwareType == HardwareType.GpuNvidia))
+                foreach (var hardware in _computer.Hardware.Where(p => p.HardwareType == HardwareType.CPU || p.HardwareType == HardwareType.GpuNvidia || p.HardwareType == HardwareType.GpuAti))
                 {
                     hardware.Update();
                 }
@@ -294,7 +300,7 @@ namespace BsWidget
 
             try
             {
-                GpuUsage = _computer.Hardware.Where(p => p.HardwareType == HardwareType.GpuNvidia).SelectMany(p => p.Sensors)
+                GpuUsage = _computer.Hardware.Where(p => p.HardwareType == HardwareType.GpuNvidia || p.HardwareType == HardwareType.GpuAti).SelectMany(p => p.Sensors)
                     .Where(p => p.SensorType == SensorType.Load && p.Name == "GPU Core").Select(p => p.Value).Max();
             }
             catch
@@ -535,7 +541,7 @@ namespace BsWidget
                 }
             }
 
-            if (flags.HasFlag(UpdateFlags.CpuAndGpu) || flags.HasFlag(UpdateFlags.RefreshAll))
+            if (Program.NoPerf == false && (flags.HasFlag(UpdateFlags.CpuAndGpu) || flags.HasFlag(UpdateFlags.RefreshAll)))
             {
                 var width = 800;
                 var height = 50;

+ 5 - 0
BsWidget/Program.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using System.Net;
 using System.Windows.Forms;
 
@@ -8,6 +9,8 @@ namespace BsWidget
     {
         internal static string Host = "127.0.0.1";
 
+        internal static bool NoPerf = false;
+
         /// <summary>
         /// 应用程序的主入口点。
         /// </summary>
@@ -22,6 +25,8 @@ namespace BsWidget
                 }
             }
 
+            if (args.Any(p => p.ToLower() == "--no-perf")) NoPerf = true;
+
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new MainForm());

+ 75 - 0
BsWidget/app.manifest

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+    <security>
+      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
+        <!-- UAC 清单选项
+             如果想要更改 Windows 用户帐户控制级别,请使用
+             以下节点之一替换 requestedExecutionLevel 节点。n
+        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
+        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
+        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
+
+            指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
+            如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
+            元素。
+        -->
+        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
+           Windows 版本的列表。取消评论适当的元素,
+           Windows 将自动选择最兼容的环境。 -->
+
+      <!-- Windows Vista -->
+      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
+
+      <!-- Windows 7 -->
+      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
+
+      <!-- Windows 8 -->
+      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
+
+      <!-- Windows 8.1 -->
+      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
+
+      <!-- Windows 10 -->
+      <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
+
+    </application>
+  </compatibility>
+
+  <!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
+       自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
+       选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
+       在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
+  <!--
+  <application xmlns="urn:schemas-microsoft-com:asm.v3">
+    <windowsSettings>
+      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
+    </windowsSettings>
+  </application>
+  -->
+
+  <!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
+  <!--
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity
+          type="win32"
+          name="Microsoft.Windows.Common-Controls"
+          version="6.0.0.0"
+          processorArchitecture="*"
+          publicKeyToken="6595b64144ccf1df"
+          language="*"
+        />
+    </dependentAssembly>
+  </dependency>
+  -->
+
+</assembly>

+ 1 - 1
BsYurHttpStatus/manifest.json

@@ -2,7 +2,7 @@
   "$schema": "https://raw.githubusercontent.com/bsmg/BSIPA-MetadataFileSchema/master/Schema.json",
   "author": "Coder",
   "description": "A plugin for provide YUR status via HTTP in Beat Saber.",
-  "gameVersion": "1.13.0",
+  "gameVersion": "1.13.5",
   "id": "BsYurHttpStatus",
   "name": "BsYurHttpStatus",
   "version": "1.0.0",