Skip to content

Commit 62cd17f

Browse files
author
KaiXin
committed
去除C的依赖项
1 parent 297e722 commit 62cd17f

6 files changed

Lines changed: 26 additions & 32 deletions

File tree

EyeGuard/BLL/Bll.cs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
using Microsoft.Win32;
1+
using EyeGuard.BLL;
2+
using Microsoft.Win32;
3+
using NAudio.CoreAudioApi;
24
using System;
35
using System.Collections.Generic;
46
using System.Diagnostics;
57
using System.Drawing;
68
using System.IO;
9+
using System.Linq;
10+
using System.Media;
711
using System.Runtime.InteropServices;
812
using System.Text;
13+
using System.Threading;
14+
using WpfScreenHelper;
915

1016
namespace EyeGuard
1117
{
@@ -66,7 +72,7 @@ public static string GetFormattingTime(string value)
6672
int TotalSeconds = Convert.ToInt32(value);
6773

6874
int branch = TotalSeconds / 60;
69-
int second= TotalSeconds % 60;
75+
int second = TotalSeconds % 60;
7076
return GetFormattingTime(branch) + ":" + GetFormattingTime(second);
7177
}
7278

@@ -81,7 +87,7 @@ public static double ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
8187
{
8288
TimeSpan ts1 = new TimeSpan(dateBegin.Ticks);
8389
TimeSpan ts2 = new TimeSpan(dateEnd.Ticks);
84-
TimeSpan ts3 = ts2- ts1;
90+
TimeSpan ts3 = ts2 - ts1;
8591
//得到相差的分钟数
8692
return ts3.TotalMinutes;
8793
}
@@ -159,7 +165,7 @@ public struct RECT
159165
//桌面窗口句柄
160166
private IntPtr desktopHandle;
161167
//Shell窗口句柄
162-
private IntPtr shellHandle;
168+
private IntPtr shellHandle;
163169
#endregion
164170

165171

@@ -233,12 +239,6 @@ public static void BootUp(bool Whether = true)
233239
}
234240
#endregion
235241

236-
[DllImport("PublicTools.dll", EntryPoint = "_GetStateOfTheSound@0")]
237-
private static extern int GetStateOfTheSound();
238-
239-
//_GetInfoOnTheScreen@4
240-
[DllImport("PublicTools.dll", EntryPoint = "GetInfoOnTheScreen")]
241-
private static extern IntPtr GetInfoOnTheScreen();
242242

243243
/// <summary>
244244
/// 全部屏幕信息
@@ -251,22 +251,16 @@ public static void BootUp(bool Whether = true)
251251
/// </summary>
252252
public static void GetInfoOnTheScreens()
253253
{
254-
string value = Marshal.PtrToStringAnsi(GetInfoOnTheScreen());
255-
string[] Displays = value.Split(',');
256-
257-
for (int i = 0; i < Displays.Length; i++)
254+
for (int i = 0; i < Screen.AllScreens.Count(); i++)
258255
{
259-
string[] _value = Displays[i].Split("X");
260-
if (_value.Length == 2)
261-
{
262-
InfoOnTheScreen infoOnThe = new InfoOnTheScreen();
263-
infoOnThe.Width = Convert.ToInt32(_value[0]);
264-
infoOnThe.Height = Convert.ToInt32(_value[1]);
265-
infoOnThe.Order = i;
266-
InfoOnTheScreens.Add(infoOnThe);
267-
}
256+
var _value = Screen.AllScreens.ToList()[i];
257+
InfoOnTheScreen infoOnThe = new InfoOnTheScreen();
258+
infoOnThe.Width = Convert.ToInt32(_value.Bounds.Width);
259+
infoOnThe.Height = Convert.ToInt32(_value.Bounds.Height);
260+
infoOnThe.Order = i;
261+
InfoOnTheScreens.Add(infoOnThe);
268262
}
269-
263+
270264
}
271265

272266
/// <summary>
@@ -275,11 +269,12 @@ public static void GetInfoOnTheScreens()
275269
/// <returns></returns>
276270
public static bool IsAudioPlaying()
277271
{
278-
if (GetStateOfTheSound() == 1)
272+
using (var enumerator = new MMDeviceEnumerator())
279273
{
280-
return true;
274+
var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
275+
bool state= defaultDevice.AudioMeterInformation.MasterPeakValue > 0;
276+
return state;
281277
}
282-
return false;
283278
}
284279
}
285280

EyeGuard/Dal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Dal
2020
/// <summary>
2121
/// 版本号
2222
/// </summary>
23-
public static string Edition = "3.10";
23+
public static string Edition = "3.20";
2424

2525

2626
/// <summary>

EyeGuard/EyeGuard.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="HandyControl" Version="3.4.0" />
13+
<PackageReference Include="NAudio" Version="2.1.0" />
14+
<PackageReference Include="WpfScreenHelper" Version="2.1.0" />
1315
</ItemGroup>
1416

1517
<ItemGroup>
16-
<None Update="PublicTools.dll">
17-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18-
</None>
1918
<None Update="PublicTools.lib">
2019
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2120
</None>

EyeGuard/EyeGuard.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<_LastSelectedProfileId>E:\开源项目\EyeGuard\core\EyeGuard\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
4+
<_LastSelectedProfileId>E:\开源项目\眼睛卫士\EyeGuard\EyeGuard\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
55
</PropertyGroup>
66
<ItemGroup>
77
<ApplicationDefinition Update="App.xaml">

EyeGuard/PublicTools.dll

-77.5 KB
Binary file not shown.

EyeGuard/PublicTools.lib

-1.99 KB
Binary file not shown.

0 commit comments

Comments
 (0)