-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Wallpaper Engine Support and Fix Startup
Add: 1. Wallpaper Engine Support 2. User information collection 3. Improve related pages Fix: 1. Startup 2. System version control
- Loading branch information
1 parent
1431a86
commit 7cb9792
Showing
22 changed files
with
442 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,44 @@ | ||
using Microsoft.Win32; | ||
using System; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace DarkMode_2.Models; | ||
|
||
public class CommandLine | ||
{ | ||
public static bool CallCommandLine(string hand, string command, string type) | ||
private string commandOutput = ""; | ||
|
||
public string CommandOutput | ||
{ | ||
get { return commandOutput; } | ||
} | ||
|
||
public int ExitCode { get; private set; } | ||
|
||
public CommandLine(string command) | ||
{ | ||
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\DarkMode2", true); | ||
if (getNowWallpaperPath(hand) == key.GetValue(type).ToString()) | ||
var processInfo = new ProcessStartInfo("cmd.exe", $"/c \"{command}\"") | ||
{ | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true | ||
}; | ||
|
||
using (var process = new Process()) | ||
{ | ||
string zhilin = "\"" + hand + "\"" + " -control openWallpaper -file " + "\"" + command + "\""; | ||
Process process = new Process() | ||
{ | ||
StartInfo = | ||
{ | ||
FileName = "cmd.exe", | ||
UseShellExecute = false, | ||
RedirectStandardInput = true, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
process.StartInfo = processInfo; | ||
process.OutputDataReceived += Process_OutputDataReceived; | ||
process.Start(); | ||
process.StandardInput.WriteLine(zhilin); | ||
string res = process.StandardOutput.ReadToEnd(); | ||
process.StandardInput.WriteLine("exit"); | ||
process.StandardInput.AutoFlush = true; | ||
process.BeginOutputReadLine(); | ||
process.WaitForExit(); | ||
return true; | ||
ExitCode = process.ExitCode; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
public static string getNowWallpaperPath(string hand) | ||
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) | ||
{ | ||
//string zhilin = "\"" + hand + "\"" + " -control getWallpaper"; | ||
////执行cmd命令 | ||
//Process CmdProcess = new Process(); | ||
//CmdProcess.StartInfo.FileName = "cmd.exe"; | ||
//CmdProcess.StartInfo.CreateNoWindow = true; // 不创建新窗口 | ||
//CmdProcess.StartInfo.UseShellExecute = false; //不启用shell启动进程 | ||
//CmdProcess.StartInfo.RedirectStandardInput = true; // 重定向输入 | ||
//CmdProcess.StartInfo.RedirectStandardOutput = true; // 重定向标准输出 | ||
//CmdProcess.StartInfo.RedirectStandardError = true; // 重定向错误输出 | ||
//CmdProcess.StartInfo.Arguments = zhilin;//“/C”表示执行完命令后马上退出 | ||
//CmdProcess.StartInfo.RedirectStandardOutput = true; | ||
//CmdProcess.Start();//执行 | ||
|
||
//CmdProcess.StandardOutput.ReadToEnd();//获取返回值 | ||
//StreamReader sr = CmdProcess.StandardOutput;//获取返回值 | ||
//CmdProcess.WaitForExit();//等待程序执行完退出进程 | ||
|
||
//CmdProcess.Close();//结束 | ||
|
||
//string line = sr.ReadLine(); | ||
//return line; | ||
return ""; | ||
if (!string.IsNullOrWhiteSpace(e.Data)) | ||
{ | ||
commandOutput += e.Data + "\n"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
using LibreHardwareMonitor.Hardware; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System; | ||
using System.Management; | ||
using System.Threading; | ||
using System; | ||
using System.Linq; | ||
using System.Timers; | ||
//using OpenHardwareMonitor.Hardware; | ||
|
||
namespace DarkMode_2.Models; | ||
|
||
public class GetGPULoad | ||
namespace DarkMode_2.Models | ||
{ | ||
/// <summary> | ||
/// 获取利用率 | ||
/// </summary> | ||
/// <param name="lstCounters">计数集合</param> | ||
/// <returns>利用率</returns> | ||
//public static float GetUsage() | ||
//{ | ||
//PerformanceCounter counter = new PerformanceCounter("Video Card", "GPU Busy", string.Empty); | ||
//float gpuUsage = counter.NextValue(); | ||
//return gpuUsage; | ||
//} | ||
class Program | ||
{ | ||
static int threshold = 80; // 注册表中设置的阈值(占用率百分比) | ||
static System.Timers.Timer timer = new System.Timers.Timer(1000); // 每1秒执行一次 | ||
//static void Main(string[] args) | ||
//{ | ||
// timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); | ||
// timer.Start(); | ||
|
||
// Console.WriteLine("Press any key to exit..."); | ||
// Console.ReadKey(); | ||
//} | ||
|
||
static void OnTimedEvent(object source, ElapsedEventArgs e) | ||
{ | ||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController"); | ||
foreach (var item in searcher.Get()) | ||
{ | ||
int usage = Convert.ToInt32(item["AdapterRAM"]) * 100 / Convert.ToInt32(item["AdapterCompatibility"]); | ||
Console.WriteLine("GPU Usage: " + usage + "%"); | ||
|
||
// 如果达到阈值,执行一些代码 | ||
if (usage >= threshold) | ||
{ | ||
Console.WriteLine("GPU is heavily utilized. Taking action..."); | ||
// TODO: 执行你需要的代码 | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.Win32.TaskScheduler; | ||
using System.Linq; | ||
|
||
namespace DarkMode_2.Models | ||
{ | ||
public static class StartupHelper | ||
{ | ||
private const string TaskName = "DarkMode2"; | ||
private const string TaskDescription = "DarkMode2自启动任务计划"; | ||
private static readonly string TaskPath = $@"\{TaskName}"; | ||
|
||
public static void Enable() | ||
{ | ||
using (var taskService = new TaskService()) | ||
{ | ||
var taskDefinition = taskService.NewTask(); | ||
taskDefinition.RegistrationInfo.Description = TaskDescription; | ||
|
||
var bootTrigger = new BootTrigger(); | ||
taskDefinition.Triggers.Add(bootTrigger); | ||
|
||
var action = new ExecAction(System.Reflection.Assembly.GetEntryAssembly().Location); | ||
taskDefinition.Actions.Add(action); | ||
|
||
taskService.RootFolder.RegisterTaskDefinition(TaskPath, taskDefinition); | ||
} | ||
} | ||
|
||
public static void Disable() | ||
{ | ||
using (var taskService = new TaskService()) | ||
{ | ||
taskService.RootFolder.DeleteTask(TaskPath, false); | ||
} | ||
} | ||
|
||
public static bool IsEnabled() | ||
{ | ||
using (var taskService = new TaskService()) | ||
{ | ||
var task = taskService.RootFolder.GetTasks().FirstOrDefault(t => t.Path.EndsWith(TaskPath)); | ||
return task != null; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
|
||
namespace DarkMode_2.Models | ||
{ | ||
public class WallpaperChanger | ||
{ | ||
private string _wallpaperEnginePath; | ||
private string _wallpaperFilePath; | ||
|
||
public WallpaperChanger(string wallpapernEginePath, string wallpaperFilePath) | ||
{ | ||
_wallpaperEnginePath = wallpapernEginePath; | ||
_wallpaperFilePath = wallpaperFilePath; | ||
} | ||
public void openWallpaper() | ||
{ | ||
string command = $"{_wallpaperEnginePath} -control openWallpaper -file {_wallpaperFilePath}"; | ||
Console.WriteLine("小子看这里:"+command); | ||
CommandLine run = new CommandLine(command); | ||
} | ||
|
||
// Wallpaper Engine官方对于这个命令存在bug | ||
public string getNowWallpaper() | ||
{ | ||
string command = $"{_wallpaperEnginePath} -control getWallpaper"; | ||
CommandLine run = new CommandLine(command); | ||
return run.CommandOutput.Trim(); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.