LumaTunnel
【WinUI】LumaTunnel 是一个面向个人多设备的 Windows 代理系统。客户端在本机提供 HTTP/HTTPS CONNECT 与 SOCKS5 TCP 代理,并通过一个受信任 TLS 证书保护的 WSS 会话,将多个 TCP 流复用到自建 Windows Server 节点。
关注
0
Fork
0
Star
0
using System.IO.Compression;
using System.IO;
namespace LumaTunnel.Client.Installer;
internal static class InstallerActions
{
private static readonly string InstallDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "LumaTunnel");
private static string Executable => Path.Combine(InstallDirectory, "LumaTunnel.exe");
public static async Task<string> InstallAsync(bool desktopShortcut)
{
var payload = Path.Combine(AppContext.BaseDirectory, "LumaTunnel.Client.zip");
if (!File.Exists(payload))
throw new FileNotFoundException("安装负载 LumaTunnel.Client.zip 不存在。", payload);
Directory.CreateDirectory(InstallDirectory);
await Task.Run(() => ZipFile.ExtractToDirectory(payload, InstallDirectory, true)).ConfigureAwait(false);
if (!File.Exists(Executable))
throw new InvalidDataException("安装负载中缺少 LumaTunnel.exe。");
var programs = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "LumaTunnel.lnk");
CreateShortcut(programs, Executable);
if (desktopShortcut)
CreateShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "LumaTunnel.lnk"), Executable);
return Executable;
}
public static async Task<bool> UninstallAsync()
{
try
{
DeleteShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "LumaTunnel.lnk"));
DeleteShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "LumaTunnel.lnk"));
if (Directory.Exists(InstallDirectory))
await Task.Run(() => Directory.Delete(InstallDirectory, true)).ConfigureAwait(false);
return true;
}
catch
{
return false;
}
}
private static void CreateShortcut(string shortcutPath, string targetPath)
{
var type = Type.GetTypeFromProgID("WScript.Shell") ?? throw new PlatformNotSupportedException("Windows Script Host is unavailable.");
dynamic shell = Activator.CreateInstance(type)!;
dynamic shortcut = shell.CreateShortcut(shortcutPath);
shortcut.TargetPath = targetPath;
shortcut.WorkingDirectory = InstallDirectory;
shortcut.IconLocation = targetPath + ",0";
shortcut.Description = "LumaTunnel 光隧";
shortcut.Save();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell);
}
private static void DeleteShortcut(string path)
{
if (File.Exists(path)) File.Delete(path);
}
}
using System.IO.Compression;
using System.IO;
namespace LumaTunnel.Client.Installer;
internal static class InstallerActions
{
private static readonly string InstallDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "LumaTunnel");
private static string Executable => Path.Combine(InstallDirectory, "LumaTunnel.exe");
public static async Task<string> InstallAsync(bool desktopShortcut)
{
var payload = Path.Combine(AppContext.BaseDirectory, "LumaTunnel.Client.zip");
if (!File.Exists(payload))
throw new FileNotFoundException("安装负载 LumaTunnel.Client.zip 不存在。", payload);
Directory.CreateDirectory(InstallDirectory);
await Task.Run(() => ZipFile.ExtractToDirectory(payload, InstallDirectory, true)).ConfigureAwait(false);
if (!File.Exists(Executable))
throw new InvalidDataException("安装负载中缺少 LumaTunnel.exe。");
var programs = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "LumaTunnel.lnk");
CreateShortcut(programs, Executable);
if (desktopShortcut)
CreateShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "LumaTunnel.lnk"), Executable);
return Executable;
}
public static async Task<bool> UninstallAsync()
{
try
{
DeleteShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "LumaTunnel.lnk"));
DeleteShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "LumaTunnel.lnk"));
if (Directory.Exists(InstallDirectory))
await Task.Run(() => Directory.Delete(InstallDirectory, true)).ConfigureAwait(false);
return true;
}
catch
{
return false;
}
}
private static void CreateShortcut(string shortcutPath, string targetPath)
{
var type = Type.GetTypeFromProgID("WScript.Shell") ?? throw new PlatformNotSupportedException("Windows Script Host is unavailable.");
dynamic shell = Activator.CreateInstance(type)!;
dynamic shortcut = shell.CreateShortcut(shortcutPath);
shortcut.TargetPath = targetPath;
shortcut.WorkingDirectory = InstallDirectory;
shortcut.IconLocation = targetPath + ",0";
shortcut.Description = "LumaTunnel 光隧";
shortcut.Save();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell);
}
private static void DeleteShortcut(string path)
{
if (File.Exists(path)) File.Delete(path);
}
}