improve:展台
新增将展台替换为希沃展台快捷启动功能
This commit is contained in:
@@ -1,72 +1,151 @@
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
internal class SoftwareLauncher
|
||||
internal static class SoftwareLauncher
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
|
||||
/// <summary>与 ICA 一致:在「程序和功能」卸载列表中按 DisplayName 匹配后启动 sweclauncher.exe。</summary>
|
||||
public static void LaunchEasiCamera(string softwareName)
|
||||
{
|
||||
string executablePath = FindEasiCameraExecutablePath(softwareName);
|
||||
|
||||
if (!string.IsNullOrEmpty(executablePath))
|
||||
if (string.IsNullOrEmpty(executablePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(executablePath);
|
||||
//Console.WriteLine(softwareName + " 启动成功!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("启动失败: " + ex.Message);
|
||||
//MessageBox.Show("启动失败: " + ex.Message);
|
||||
}
|
||||
MessageBox.Show(
|
||||
"未找到希沃视频展台安装信息(已扫描 64 位与 32 位卸载注册表)。请确认已通过官方安装包安装「希沃视频展台」。",
|
||||
"Ink Canvas",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var directory = Path.GetDirectoryName(executablePath);
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = executablePath,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = string.IsNullOrEmpty(directory) ? Environment.SystemDirectory : directory
|
||||
};
|
||||
Process.Start(psi);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"无法启动希沃视频展台:" + ex.Message,
|
||||
"Ink Canvas",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
}
|
||||
//Console.WriteLine(softwareName + " 未找到可执行文件路径。");
|
||||
}
|
||||
|
||||
private static string FindEasiCameraExecutablePath(string softwareName)
|
||||
{
|
||||
string executablePath = null;
|
||||
if (string.IsNullOrWhiteSpace(softwareName))
|
||||
return null;
|
||||
|
||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"))
|
||||
// 64 位进程默认只枚举 64 位注册表视图;32 位希沃常写在 WOW6432Node 下,需一并扫描。
|
||||
string[] uninstallRoots =
|
||||
{
|
||||
foreach (string subkeyName in key.GetSubKeyNames())
|
||||
{
|
||||
using (RegistryKey subkey = key.OpenSubKey(subkeyName))
|
||||
{
|
||||
string displayName = subkey.GetValue("DisplayName") as string;
|
||||
string installLocation = subkey.GetValue("InstallLocation") as string;
|
||||
string uninstallString = subkey.GetValue("UninstallString") as string;
|
||||
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
|
||||
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(displayName) && displayName.Contains(softwareName))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(installLocation))
|
||||
{
|
||||
executablePath = Path.Combine(installLocation, "sweclauncher.exe");
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(uninstallString))
|
||||
{
|
||||
int lastSlashIndex = uninstallString.LastIndexOf("\\");
|
||||
if (lastSlashIndex >= 0)
|
||||
{
|
||||
string folderPath = uninstallString.Substring(0, lastSlashIndex);
|
||||
executablePath = Path.Combine(folderPath, "sweclauncher", "sweclauncher.exe");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (string root in uninstallRoots)
|
||||
{
|
||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(root))
|
||||
{
|
||||
if (key == null) continue;
|
||||
string found = FindInUninstallKey(key, softwareName);
|
||||
if (!string.IsNullOrEmpty(found))
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return executablePath;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string FindInUninstallKey(RegistryKey uninstallKey, string softwareName)
|
||||
{
|
||||
foreach (string subkeyName in uninstallKey.GetSubKeyNames())
|
||||
{
|
||||
using (RegistryKey subkey = uninstallKey.OpenSubKey(subkeyName))
|
||||
{
|
||||
if (subkey == null) continue;
|
||||
|
||||
string displayName = subkey.GetValue("DisplayName") as string;
|
||||
if (string.IsNullOrEmpty(displayName) || !displayName.Contains(softwareName))
|
||||
continue;
|
||||
|
||||
string installLocation = subkey.GetValue("InstallLocation") as string;
|
||||
string uninstallString = subkey.GetValue("UninstallString") as string;
|
||||
|
||||
string resolved = TryResolveSweclauncher(installLocation, uninstallString);
|
||||
if (!string.IsNullOrEmpty(resolved) && File.Exists(resolved))
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string TryResolveSweclauncher(string installLocation, string uninstallString)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(installLocation))
|
||||
{
|
||||
string fromLoc = ResolveSweclauncherUnderInstallRoot(installLocation.Trim().TrimEnd('\\'));
|
||||
if (!string.IsNullOrEmpty(fromLoc))
|
||||
return fromLoc;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(uninstallString))
|
||||
{
|
||||
// 常见:"...\uninstall.exe" 或带引号路径
|
||||
string trimmed = uninstallString.Trim();
|
||||
if (trimmed.Length >= 2 && trimmed[0] == '"')
|
||||
{
|
||||
int end = trimmed.IndexOf('"', 1);
|
||||
if (end > 1)
|
||||
trimmed = trimmed.Substring(1, end - 1);
|
||||
}
|
||||
|
||||
int lastSlash = trimmed.LastIndexOf('\\');
|
||||
if (lastSlash < 0)
|
||||
return null;
|
||||
|
||||
string folderPath = trimmed.Substring(0, lastSlash);
|
||||
string candidate = Path.Combine(folderPath, "sweclauncher", "sweclauncher.exe");
|
||||
if (File.Exists(candidate))
|
||||
return candidate;
|
||||
|
||||
candidate = Path.Combine(folderPath, "sweclauncher.exe");
|
||||
if (File.Exists(candidate))
|
||||
return candidate;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string ResolveSweclauncherUnderInstallRoot(string installRoot)
|
||||
{
|
||||
string[] candidates =
|
||||
{
|
||||
Path.Combine(installRoot, "sweclauncher.exe"),
|
||||
Path.Combine(installRoot, "sweclauncher", "sweclauncher.exe"),
|
||||
};
|
||||
|
||||
foreach (string p in candidates)
|
||||
{
|
||||
if (File.Exists(p))
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user