檔案調整+關機錨點
This commit is contained in:
parent
9f517c54d4
commit
232aabcaf6
@ -15,16 +15,23 @@ namespace DualScreenDemo
|
|||||||
{
|
{
|
||||||
this.songListManager = songListManager;
|
this.songListManager = songListManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessData(string indata)
|
public async Task ProcessData(string indata)
|
||||||
{
|
{ //關機錨點
|
||||||
string filePath = Path.Combine(Application.StartupPath, "dataLog.txt");
|
string filePath = Path.Combine(Application.StartupPath, "dataLog.txt");
|
||||||
|
// 使用 Path.Combine 方法安全地將應用程式的啟動路徑與 "dataLog.txt" 檔案名結合,
|
||||||
|
// 建立完整的檔案路徑。Application.StartupPath 通常指向應用程式的可執行檔所在的目錄。
|
||||||
|
|
||||||
if (CheckLogForShutdown(filePath))
|
if (CheckLogForShutdown(filePath))
|
||||||
|
// 呼叫 CheckLogForShutdown 方法,並將建立的檔案路徑 (filePath) 作為參數傳遞。
|
||||||
|
// 這個方法預期會檢查指定的日誌檔案內容,以判斷是否符合關機的條件。
|
||||||
|
// 如果該方法回傳 true (表示符合關機條件),則執行 if 區塊內的程式碼。
|
||||||
{
|
{
|
||||||
Console.WriteLine("Shutdown condition met. Application will now close.");
|
Console.WriteLine("Shutdown condition met. Application will now close.");
|
||||||
|
// 在控制台輸出訊息,告知使用者已滿足關機條件,應用程式即將關閉。
|
||||||
ShutdownComputer();
|
ShutdownComputer();
|
||||||
|
// 呼叫 ShutdownComputer 方法,這個方法預期會執行關閉電腦的操作。
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (indata)
|
switch (indata)
|
||||||
{
|
{
|
||||||
case "A261A4":
|
case "A261A4":
|
||||||
|
@ -131,7 +131,7 @@ namespace DualScreenDemo
|
|||||||
|
|
||||||
public void PlayApplauseSound()
|
public void PlayApplauseSound()
|
||||||
{
|
{
|
||||||
mediaPlayer.URL = Path.Combine(Application.StartupPath, "zs.m4a");
|
mediaPlayer.URL = Path.Combine(Application.StartupPath, "sounds", "zs.m4a");
|
||||||
mediaPlayer.controls.play();
|
mediaPlayer.controls.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
48
Program.cs
48
Program.cs
@ -25,20 +25,6 @@ static void Main()
|
|||||||
Console.WriteLine("Failed to initialize COM library.");
|
Console.WriteLine("Failed to initialize COM library.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL ACL 配置
|
|
||||||
string ipAddress = "192.168.88.66";
|
|
||||||
string port = "9090";
|
|
||||||
string url = $"http://{ipAddress}:{port}/";
|
|
||||||
|
|
||||||
if (!IsUrlAclExists(url))
|
|
||||||
{
|
|
||||||
RunBatchFileToAddUrlAcl(ipAddress, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
Application.EnableVisualStyles();
|
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
|
||||||
|
|
||||||
// 初始化管理器
|
// 初始化管理器
|
||||||
|
|
||||||
songListManager = SongListManager.Instance; // 使用单例
|
songListManager = SongListManager.Instance; // 使用单例
|
||||||
@ -129,39 +115,7 @@ static void Main()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态创建并运行批处理文件以添加 URL ACL
|
|
||||||
private static void RunBatchFileToAddUrlAcl(string ipAddress, string port)
|
|
||||||
{
|
|
||||||
// 确保批处理文件在当前程序的同一目录下
|
|
||||||
string batchFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AddUrlAcl.bat");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 创建批处理内容
|
|
||||||
string batchContent =
|
|
||||||
$"netsh http add urlacl url=http://{ipAddress}:{port}/ user=Everyone\n";
|
|
||||||
|
|
||||||
// 写入批处理文件,确保使用 UTF-8 编码
|
|
||||||
File.WriteAllText(batchFilePath, batchContent);
|
|
||||||
|
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
||||||
{
|
|
||||||
FileName = "cmd.exe", // 使用 cmd 执行
|
|
||||||
Arguments = $"/c \"{batchFilePath}\"", // /c 参数用于执行命令后关闭命令窗口
|
|
||||||
UseShellExecute = true, // 使用系统外壳程序来启动
|
|
||||||
Verb = "runas" // 以管理员身份运行
|
|
||||||
};
|
|
||||||
|
|
||||||
Process process = Process.Start(startInfo);
|
|
||||||
process.WaitForExit(); // 等待批处理执行完成
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("执行批处理文件失败: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void InitializeSecondaryScreen()
|
private static void InitializeSecondaryScreen()
|
||||||
{
|
{
|
||||||
if (Screen.AllScreens.Length > 1)
|
if (Screen.AllScreens.Length > 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user