Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 2ba2f98

Browse files
committed
judge powerstatus and screen
1 parent 7e7ef1c commit 2ba2f98

File tree

15 files changed

+85
-137
lines changed

15 files changed

+85
-137
lines changed

wallpaper/Program.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ static void Main(string[] args)
2121
Language.Initialize();
2222
if (!File.Exists("mpv.exe"))
2323
{
24-
string mpvMessage = Language.GetString("mpvMessage");
25-
string error = Language.GetString("error");
26-
MessageBox.Show(mpvMessage, error, MessageBoxButtons.OK, MessageBoxIcon.Error);
24+
MessageBox.Show(Language.GetString("mpvMessage"), Language.GetString("error"),
25+
MessageBoxButtons.OK, MessageBoxIcon.Error);
2726
}
2827
else
2928
{
@@ -36,9 +35,8 @@ static void Main(string[] args)
3635
}
3736
else
3837
{
39-
string fileMessage = Language.GetString("fileMessage");
40-
string error = Language.GetString("error");
41-
MessageBox.Show(fileMessage, error, MessageBoxButtons.OK, MessageBoxIcon.Error);
38+
MessageBox.Show(Language.GetString("fileMessage"), Language.GetString("error"),
39+
MessageBoxButtons.OK, MessageBoxIcon.Error);
4240
}
4341
}
4442
catch (Exception)

wallpaper/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
3232
// 方法是按如下所示使用“*”: :
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.2.2.0")]
35-
[assembly: AssemblyFileVersion("2.2.2.0")]
34+
[assembly: AssemblyVersion("2.3.0.0")]
35+
[assembly: AssemblyFileVersion("2.3.0.0")]

wallpaper/RegistryGet.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ namespace wallpaper
55
class RegistryGet
66
{
77
static readonly string settingPath = @"Software\Wallpaper";
8-
static readonly string excludeListPath = @"Software\Wallpaper\ExcludeList";
98

109
public static string GetSetting(string name)
1110
{
1211
RegistryKey setting = Registry.CurrentUser.OpenSubKey(settingPath);
1312
return setting.GetValue(name).ToString();
1413
}
15-
16-
public static string GetExcludeList(string name)
17-
{
18-
RegistryKey excludeList = Registry.CurrentUser.OpenSubKey(excludeListPath);
19-
return excludeList.GetValue(name).ToString();
20-
}
2114
}
2215
}

wallpaper/Resources/en-US.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Message
22
error=Error
3-
mpvMessage=Can't find "Mpv" application.
3+
mpvMessage=Can't find Mpv application.
44
fileMessage=Can't find video file.

wallpaper/Resources/zh-CN.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Message
22
error=错误
3-
mpvMessage=找不到Mpv应用程序。
3+
mpvMessage=找不到 Mpv 应用程序。
44
fileMessage=找不到视频文件。

wallpaper/Wallpaper.cs

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,16 @@ namespace wallpaper
99
class Wallpaper
1010
{
1111
static Timer timer = new Timer();
12-
static bool isEnable = false;
13-
static List<string> exclude = new List<string>();
12+
static string video = string.Empty;
13+
static List<string> list = new List<string>();
1414

1515
public static void Run()
1616
{
17-
if (Convert.ToBoolean(RegistryGet.GetSetting("wallpaperExclude")))
17+
video = RegistryGet.GetSetting("videoLocation");
18+
if (Convert.ToBoolean(RegistryGet.GetSetting("wallpaperExclude")) &&
19+
!string.IsNullOrWhiteSpace(RegistryGet.GetSetting("excludeList")))
1820
{
19-
for (int i = 0; i < int.MaxValue; i++)
20-
{
21-
try
22-
{
23-
string item = RegistryGet.GetExcludeList(i.ToString());
24-
exclude.Add(item);
25-
}
26-
catch (Exception)
27-
{
28-
break;
29-
}
30-
}
21+
list = RegistryGet.GetSetting("excludeList").Split('|').ToList();
3122
}
3223
timer.Interval = 1000;
3324
timer.Tick += TimerTick;
@@ -36,49 +27,32 @@ public static void Run()
3627

3728
private static void TimerTick(object sender, EventArgs e)
3829
{
39-
Process[] explorer = Process.GetProcessesByName("explorer");
40-
Process[] mpv = Process.GetProcessesByName("mpv");
41-
Process[] process = Process.GetProcesses();
42-
List<string> list = new List<string>();
43-
foreach (var item in process)
30+
timer.Enabled = false;
31+
bool power = SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
32+
bool screen = Screen.AllScreens.Count() == 1;
33+
int explorer = Process.GetProcessesByName("explorer").Length;
34+
int mpv = Process.GetProcessesByName("mpv").Length;
35+
int exclude = Process.GetProcesses().Select(item => item.ProcessName).Intersect(list).Count();
36+
if (power && screen && explorer != 0 && mpv == 0 && exclude == 0)
4437
{
45-
list.Add(item.ProcessName);
46-
}
47-
int excludeNum = list.Intersect(exclude).Count();
48-
if (explorer.Length > 0 && mpv.Length < 1 && excludeNum < 1)
49-
{
50-
timer.Enabled = false;
5138
System.Threading.Thread.Sleep(1000);
5239
IntPtr hwndShell = WindowsApi.GetShellWindow();
5340
WindowsApi.SendMessageTimeout(hwndShell, 0x52c, IntPtr.Zero, IntPtr.Zero, 0, 1000, IntPtr.Zero);
41+
System.Threading.Thread.Sleep(1000);
5442
IntPtr hwndWorkerW = WindowsApi.GetWindow(hwndShell, 3);
55-
string file = "\"" + RegistryGet.GetSetting("videoLocation") + "\"";
56-
string args = " --hwdec=auto --ao=null --loop-file=yes";
5743
Process newMpv = new Process();
5844
newMpv.StartInfo.FileName = "mpv.exe";
59-
newMpv.StartInfo.Arguments = file + args + " --wid=" + hwndWorkerW;
45+
newMpv.StartInfo.Arguments = $"\"{video}\" --wid={hwndWorkerW} --loop-file=yes --hwdec=auto --ao=null";
6046
newMpv.Start();
61-
isEnable = true;
62-
timer.Enabled = true;
6347
}
64-
else if (excludeNum > 0)
48+
else if ((!power || !screen || exclude > 0) && mpv != 0)
6549
{
66-
timer.Enabled = false;
67-
if (isEnable)
68-
{
69-
Stop();
70-
isEnable = false;
71-
}
72-
timer.Enabled = true;
50+
IntPtr hwndShell = WindowsApi.GetShellWindow();
51+
IntPtr hwndWorkerW = WindowsApi.GetWindow(hwndShell, 3);
52+
IntPtr hwndMpv = WindowsApi.GetWindow(hwndWorkerW, 5);
53+
WindowsApi.SendMessage(hwndMpv, 0x0010, 0, 0);
7354
}
74-
}
75-
76-
public static void Stop()
77-
{
78-
IntPtr hwndShell = WindowsApi.GetShellWindow();
79-
IntPtr hwndWorkerW = WindowsApi.GetWindow(hwndShell, 3);
80-
IntPtr hwndMpv = WindowsApi.GetWindow(hwndWorkerW, 5);
81-
WindowsApi.SendMessage(hwndMpv, 0x0010, 0, 0);
55+
timer.Enabled = true;
8256
}
8357
}
8458
}

wallpapersetting/Language.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static string GetString(string value)
5454
}
5555
}
5656

57-
public static void GetText(System.Windows.Forms.Control control)
57+
public static void GetText(Control control)
5858
{
5959
try
6060
{

wallpapersetting/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
3333
// 方法是按如下所示使用“*”: :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.1.0.0")]
36+
[assembly: AssemblyFileVersion("1.1.0.0")]

wallpapersetting/RegistryEdit.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace wallpapersetting
66
class RegistryEdit
77
{
88
static readonly string settingPath = @"Software\Wallpaper";
9-
static readonly string excludeListPath = @"Software\Wallpaper\ExcludeList";
109
static readonly string autorunPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
1110
static readonly string desktopPath = @"DesktopBackground\Shell\Wallpaper";
1211
static readonly string shellPath = @"DesktopBackground\Shell\Wallpaper\Shell";
@@ -47,25 +46,6 @@ public static void RemoveSetting()
4746
setting.Close();
4847
}
4948

50-
public static string GetExcludeList(string name)
51-
{
52-
RegistryKey excludeList = Registry.CurrentUser.OpenSubKey(excludeListPath);
53-
return excludeList.GetValue(name).ToString();
54-
}
55-
56-
public static void SetExcludeList(string name, string value)
57-
{
58-
RegistryKey excludeList = Registry.CurrentUser.CreateSubKey(excludeListPath);
59-
excludeList.SetValue(name, value);
60-
}
61-
62-
public static void RemoveExcludeList()
63-
{
64-
RegistryKey excludeList = Registry.CurrentUser;
65-
excludeList.DeleteSubKeyTree(excludeListPath, false);
66-
excludeList.Close();
67-
}
68-
6949
public static void SetAutorun()
7050
{
7151
RegistryKey autorun = Registry.CurrentUser.OpenSubKey(autorunPath, true);

wallpapersetting/Resources/en-US.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ settingCancel=Cancel
66
# Video
77
videoLabel=Video
88
videoBrowser=Browser
9+
videoFilter=Video File|*.mp4
910

1011
# Wallpaper
1112
wallpaperLabel=General
@@ -21,6 +22,7 @@ exitClear=Cleanup
2122
excludeLabel=Exclude
2223
excludeAdd=Add
2324
excludeDelete=Delete
25+
excludeFilter=Application|*.exe
2426

2527
# Message
2628
information=Information

0 commit comments

Comments
 (0)