Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
Ver 2.2.0-Alpha.6: BIG FUCKING TRASH.
Browse files Browse the repository at this point in the history
Okay I know I'm producing more and more programming trash, but just give me more time to think about this shit.
  • Loading branch information
Shiroiame-Kusu committed Sep 8, 2024
1 parent 746e4c7 commit 32cc96d
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 53 deletions.
113 changes: 67 additions & 46 deletions LoCyanFrpDesktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand All @@ -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(); // 打开控制台
Expand All @@ -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);
}
}
}
}
87 changes: 87 additions & 0 deletions LoCyanFrpDesktop/DashBoard_Token.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<ui:UiWindow x:Class="LoCyanFrpDesktop.DashBoard_Token"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:LoCyanFrpDesktop"
xmlns:Dashboard="clr-namespace:LoCyanFrpDesktop.Dashboard"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="LoCyanFrp - DashBoard [用户界面]"
Height="450" Width="800"
MinHeight="450"
MinWidth="800"
Closing="UiWindow_Closing"
ContentRendered="UiWindow_ContentRendered"

Icon="/Resource/favicon.ico"
IsVisibleChanged="UiWindow_IsVisibleChanged"
Loaded="UiWindow_Loaded"
AllowDrop="True"
ExtendsContentIntoTitleBar="True"
StateChanged="UiWindow_StateChanged"
Style="{StaticResource UiWindow}"
WindowStyle="None">

<Grid>
<Grid.Resources>
<Color x:Key="ShadowColor"></Color>
<SolidColorBrush x:Key="MainBackgroundColor"></SolidColorBrush>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ui:TitleBar
x:Name="_TitleBar"
Title="LoCyanFrp - DashBoard [用户界面] [一键启动模式]"
Grid.Row="0"
Margin="5,0,0,0"
Padding="0"
Icon="/Resource/favicon.ico">

</ui:TitleBar>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="72"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ui:NavigationStore
x:Name="Navigation"
Grid.Column="0"
Margin="6,0,6,9"
Frame="{Binding ElementName=RootFrame}"
SelectedPageIndex="0">
<ui:NavigationStore.Items>
<ui:NavigationItem
Content="运行状态"
Icon="WindowConsole20"
PageTag="ProxyStatus"
PageType="{x:Type Dashboard:Status}"/>
</ui:NavigationStore.Items>
</ui:NavigationStore>
<Border
Grid.Column="1"
Margin="0"
CornerRadius="8,0,0,0">
<Frame x:Name="RootFrame" Margin="4,8" />
</Border>

<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:Snackbar
Margin="0,0,0,20"
x:Name="Snackbar"
Grid.Column="1"
Panel.ZIndex="999"
Timeout="5000" />
</Grid>
</Grid>

</Grid>
</ui:UiWindow>
Loading

0 comments on commit 32cc96d

Please sign in to comment.