diff --git a/LoCyanFrpDesktop/App.xaml.cs b/LoCyanFrpDesktop/App.xaml.cs
index 04f5471..5954306 100644
--- a/LoCyanFrpDesktop/App.xaml.cs
+++ b/LoCyanFrpDesktop/App.xaml.cs
@@ -15,6 +15,10 @@
using CefSharp.Wpf;
using System.Runtime.ConstrainedExecution;
using CefSharp;
+using System.Diagnostics;
+using System.Security.Policy;
+using System.Text.RegularExpressions;
+using System.Text;
namespace LoCyanFrpDesktop
{
@@ -26,6 +30,8 @@ public partial class App : Application
{
private static string? Username = null;
private static string? Password = null;
+ private static bool DebugMode = Global.Config.DebugMode;
+ private static bool TokenMode = false;
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
@@ -43,46 +49,87 @@ protected override void OnStartup(StartupEventArgs e)
DispatcherUnhandledException += CurrentDomain_UnhandledException;
DispatcherUnhandledException += (_, e) => CrashInterception.ShowException(e.Exception);
- int UsernameNum = 0;
- int PasswordNum = 0;
- bool DebugMode = Global.Config.DebugMode;
+
+
// 处理启动参数
string[] args = e.Args;
- base.OnStartup(e);
-
+
+ ProcessStartupParameters(args);
+ if (!TokenMode)
+ {
+ base.OnStartup(e);
+ }
+
+ }
+ protected override void OnExit(ExitEventArgs e)
+ {
+ Cef.Shutdown();
+ base.OnExit(e);
+ }
+ private static void CurrentDomain_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
+ {
+ e.Handled = true;
+ }
+ private static void ProcessStartupParameters(string[] args)
+ {
+ int UsernameNum = 0;
+ int PasswordNum = 0;
if (args.Length > 0)
- {
- for (int j = 0; j < args.Count(); j++) {
+ {
+
+ string pattern = @"^locyanfrp://([^/]+)/(\d+)$";
+ Regex regex = new Regex(pattern);
+
+ for (int j = 0; j < args.Count(); j++)
+ {
if (args[j] == "--user" || args[j] == "--User" || args[j] == "--Username" || args[j] == "--username")
{
UsernameNum = j;
}
- else if(args[j] == "--password" || args[j] == "--Password")
+ else if (args[j] == "--password" || args[j] == "--Password")
{
PasswordNum = j;
- }else if(args[j] == "--debug")
+ }
+ else if (args[j] == "--debug")
{
DebugMode = true;
}
+ else
+ {
+ string url = args[j];
+ Match match = regex.Match(url);
+ if (match.Success) {
+ Console.WriteLine($"Received URL: {url}");
+ string[] parsedParameters = new string[]
+ {
+ match.Groups[1].Value,
+ match.Groups[2].Value
+ };
+ TokenMode = true;
+ DashBoard_Token dashBoard_Token = new DashBoard_Token(match.Groups[1].Value, int.Parse(match.Groups[2].Value));
+ dashBoard_Token.Show();
+
+ }
+ }
}
int Num = UsernameNum - PasswordNum;
- if (Num >= 2 && Num <= -2) {
+ if (Num >= 2 && Num <= -2)
+ {
Username = args[UsernameNum + 1];
Password = args[PasswordNum + 1];
if (Password != null && Username != null)
- {
+ {
Global.Config.Username = Username;
- foreach (char c in Password.ToCharArray()) {
+ foreach (char c in Password.ToCharArray())
+ {
Global.Password.AppendChar(c);
}
-
- //LoCyanFrpDesktop.Properties.Settings.Default.username = Username;
- //LoCyanFrpDesktop.Properties.Settings.Default.password = Password;
+
Global.LoginedByConsole = true;
}
}
-
+
if (DebugMode)
{
AllocConsole(); // 打开控制台
@@ -93,44 +140,18 @@ protected override void OnStartup(StartupEventArgs e)
}
// 解析和处理参数
// 这里可以根据参数的内容执行不同的操作
- ProcessUrlParameters(args);
- for (int x = 0; x < args.Count(); x++) {
+ for (int x = 0; x < args.Count(); x++)
+ {
if (x != args.Count() - 1)
{
Console.Write(args[x]);
}
- else {
+ else
+ {
Console.WriteLine(args[x]);
}
}
}
-
- }
- protected override void OnExit(ExitEventArgs e)
- {
- Cef.Shutdown();
- base.OnExit(e);
- }
- private static void CurrentDomain_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- e.Handled = true;
- }
- private void ProcessUrlParameters(string[] args)
- {
- string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- string filePath = Path.Combine(documentsPath, "auto_launch.ini");
-
- string arguments = string.Join(" ", args);
-
- try
- {
- File.WriteAllText(filePath, arguments);
- }
- catch (Exception ex)
- {
- // 处理写入文件时可能发生的异常
- MessageBox.Show("写入文件时出现错误:" + ex.Message);
- }
}
}
}
diff --git a/LoCyanFrpDesktop/DashBoard_Token.xaml b/LoCyanFrpDesktop/DashBoard_Token.xaml
new file mode 100644
index 0000000..5939b78
--- /dev/null
+++ b/LoCyanFrpDesktop/DashBoard_Token.xaml
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LoCyanFrpDesktop/DashBoard_Token.xaml.cs b/LoCyanFrpDesktop/DashBoard_Token.xaml.cs
new file mode 100644
index 0000000..f2faf8f
--- /dev/null
+++ b/LoCyanFrpDesktop/DashBoard_Token.xaml.cs
@@ -0,0 +1,187 @@
+using LoCyanFrpDesktop.Utils;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using Wpf.Ui.Appearance;
+using Wpf.Ui.Common;
+using Wpf.Ui.Controls;
+using static LoCyanFrpDesktop.Utils.PNAP;
+
+namespace LoCyanFrpDesktop
+{
+ ///
+ /// Interaction logic for DashBoard_Token.xaml
+ ///
+ public partial class DashBoard_Token : UiWindow
+ {
+
+ public static bool isFrpcInstalled;
+ private static SolidColorBrush DarkBrush = new SolidColorBrush(Color.FromRgb(32, 32, 32));
+ private static SolidColorBrush LightBrush = new SolidColorBrush(Color.FromRgb(250, 250, 250));
+ public DashBoard_Token(string Token, int Proxy)
+ {
+ InitializeComponent();
+ Uri iconUri = new Uri("pack://application:,,,/LoCyanFrpDesktop;component/Resource/favicon.ico", UriKind.RelativeOrAbsolute);
+ this.Icon = new BitmapImage(iconUri);
+ if (CheckIfFrpcInstalled())
+ {
+ RunCmdCommand($" -u {Token} -p ", Proxy);
+ }
+
+
+ }
+ private static void SortOutputHandler(object sender, DataReceivedEventArgs e)
+ {
+ if (!string.IsNullOrEmpty(e.Data))
+ {
+ Logger.Output(LogType.Info, e.Data);
+ }
+ }
+ private static void RunCmdCommand(string command, int ProxyID)
+ {
+ // 创建一个 ProcessStartInfo 对象
+ ProcessStartInfo psi = new ProcessStartInfo
+ {
+ FileName = Global.Config.FrpcPath, // 指定要运行的命令行程序
+ Arguments = command + ProxyID, // 使用 /k 参数保持 cmd 窗口打开,显示输出内容
+ Verb = "runas",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false, // 设置为 true 以便在新窗口中显示命令行窗口
+ CreateNoWindow = true, // 设置为 false 以显示命令行窗口
+ StandardOutputEncoding = Encoding.UTF8
+ };
+ // 启动进程
+ Process _FrpcProcess = Process.Start(psi);
+ _FrpcProcess.BeginOutputReadLine();
+
+ _FrpcProcess.OutputDataReceived += SortOutputHandler;
+ _FrpcProcess.EnableRaisingEvents = true;
+
+ // 读取标准输出和标准错误输出
+ //string output = process.StandardOutput.ReadToEnd();
+ //string error = process.StandardError.ReadToEnd();
+
+ // 等待进程完成
+ //process.WaitForExit();
+
+ // 打印输出
+ //Console.WriteLine("Output:\n" + output);
+ //Console.WriteLine("Error:\n" + error);
+
+ // 可以将输出存储到变量中,以便后续处理
+ // string combinedOutput = output + error;
+ }
+ public bool CheckIfFrpcInstalled()
+ {
+ if (!string.IsNullOrEmpty(Global.Config.FrpcPath))
+ {
+ if (!File.Exists(Global.Config.FrpcPath))
+ {
+ bool isConfirmed = Logger.MsgBox("您需要我们自动为您安装frpc吗?", "未检测到您安装的frpc", 1, 47, 1);
+ if (isConfirmed)
+ {
+ DownloadFrpc();
+ }
+ else
+ {
+ Environment.Exit(0);
+ }
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+
+ }
+ else
+ {
+ bool isConfirmed = Logger.MsgBox("您需要我们自动为您安装frpc吗?", "未检测到您安装的frpc", 1, 47, 1);
+ if (isConfirmed)
+ {
+ DownloadFrpc();
+ }
+ else
+ {
+ Environment.Exit(0);
+ }
+ return false;
+ }
+ return false;
+ }
+ public void DownloadFrpc()
+ {
+ Download downloader = new Download();
+ downloader.Owner = this;
+ downloader.Show();
+ }
+ public void OpenSnackbar(string title, string message, SymbolRegular icon)
+ {
+ Dispatcher.Invoke(() =>
+ {
+ Snackbar.Show(title, message, icon);
+ });
+ }
+ private void UiWindow_Closing(object sender, CancelEventArgs e)
+ {
+ e.Cancel = true;
+ ShowInTaskbar = false;
+ Hide();
+ }
+ public void UiWindow_StateChanged(object sender, EventArgs e)
+ {
+ }
+ public void UiWindow_ContentRendered(object sender, EventArgs e)
+ {
+
+ }
+ public void UiWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ => ShowInTaskbar = IsVisible;
+ public void Hide_Click(object sender, RoutedEventArgs e)
+ {
+ ShowInTaskbar = false;
+ Hide();
+ }
+
+ public void Exit_Click(object sender, RoutedEventArgs e)
+ {
+ Environment.Exit(0);
+ }
+ public void UiWindow_Loaded(object sender, EventArgs e)
+ {
+ ChangeColor();
+ }
+ public void ChangeColor()
+ {
+ Resources["ShadowColor"] = Global.isDarkThemeEnabled ? Colors.White : Colors.LightGray;
+ SolidColorBrush solidColorBrush = new SolidColorBrush(Global.isDarkThemeEnabled ? Colors.LightGray : Colors.WhiteSmoke);
+ Resources["MainBackgroundColor"] = solidColorBrush;
+ if (Global.isDarkThemeEnabled)
+ {
+ this.Background = DarkBrush;
+ Theme.Apply(ThemeType.Dark);
+ }
+ else
+ {
+ this.Background = LightBrush;
+ Theme.Apply(ThemeType.Light);
+ }
+ //Theme.Apply(Global.isDarkThemeEnabled ? ThemeType.Dark : ThemeType.Light);
+ //this.Background = solidColorBrush;
+ }
+ }
+}
diff --git a/LoCyanFrpDesktop/Global.cs b/LoCyanFrpDesktop/Global.cs
index d1b20dd..906c971 100644
--- a/LoCyanFrpDesktop/Global.cs
+++ b/LoCyanFrpDesktop/Global.cs
@@ -17,7 +17,7 @@ internal static class Global
public static bool LoginedByConsole = false;
public const string Version = "2.2.0";
public const string Branch = "Alpha";
- public const int Revision = 5;
+ public const int Revision = 6;
public static readonly BuildInfo BuildInfo = new();
public const string Developer = "Shiroiame-Kusu & Daiyangcheng";
public const string Copyright = "Copyright © 2021 - 2024 杭州樱芸网络科技有限公司 All Rights Reserved";
diff --git a/LoCyanFrpDesktop/MainWindow.xaml.cs b/LoCyanFrpDesktop/MainWindow.xaml.cs
index 4e06ec5..57d491a 100644
--- a/LoCyanFrpDesktop/MainWindow.xaml.cs
+++ b/LoCyanFrpDesktop/MainWindow.xaml.cs
@@ -44,11 +44,6 @@ public partial class MainWindow : UiWindow
public MainWindow()
{
- //InitialBanner initialBanner = new();
-
- //initialBanner.Show();
- //initialBanner.Hide();
-
InitializeComponent();
if (Random.Shared.Next(0, 10000) == 5000)
{
@@ -68,7 +63,7 @@ public MainWindow()
Access.MainWindow = this;
Update.Init();
ScheduledTask.Init();
-
+ ProtocolHandler.Init();
}
private async void CheckNetworkAvailability()
diff --git a/LoCyanFrpDesktop/Utils/ProtocolHandler.cs b/LoCyanFrpDesktop/Utils/ProtocolHandler.cs
new file mode 100644
index 0000000..6787dba
--- /dev/null
+++ b/LoCyanFrpDesktop/Utils/ProtocolHandler.cs
@@ -0,0 +1,41 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LoCyanFrpDesktop.Utils
+{
+ internal class ProtocolHandler
+ {
+ public static void Init()
+ {
+ RegisterUrlProtocol("locyanfrp", Assembly.GetExecutingAssembly().Location);
+ }
+ public static void RegisterUrlProtocol(string protocolName, string applicationPath)
+ {
+ using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(protocolName))
+ {
+ if (key != null)
+ {
+ key.SetValue(string.Empty, $"URL:{protocolName} Protocol");
+ key.SetValue("URL Protocol", string.Empty);
+
+ using (RegistryKey shellKey = key.CreateSubKey(@"shell\open\command"))
+ {
+ if (shellKey != null)
+ {
+ shellKey.SetValue(string.Empty, $"\"{applicationPath}\" \"%1\"");
+ }
+ }
+ }
+ }
+ }
+ public static void ProcessUrlParameters(string url)
+ {
+
+ }
+ }
+}