Skip to content

Commit

Permalink
feat: rework UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Virenbar committed May 26, 2024
1 parent e4c5e57 commit 78a31ae
Show file tree
Hide file tree
Showing 16 changed files with 2,246 additions and 1,747 deletions.
14 changes: 13 additions & 1 deletion GDPIControl/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ internal static class Config
{
public static ControlSettings Current { get; set; }

private static ControlSettings Default => new() { Modeset = Modeset.M5, GDPISettings = GDPISettings.ModesetSettings(Modeset.M5) };
private static ControlSettings Default => new()
{
Modeset = Modeset.M5,
CustomSettings1 = new GDPISettings(),
CustomSettings2 = new GDPISettings(),
CustomSettings3 = new GDPISettings()
};

public static void Load()
{
Expand All @@ -20,6 +26,12 @@ public static void Load()
var XS = new XmlSerializer(typeof(ControlSettings));
using var SR = new StreamReader(Constants.ConfigPath);
Current = (ControlSettings)XS.Deserialize(SR);

var def = Default;
if (Current.Modeset == Modeset.Custom) { Current.Modeset = Modeset.Custom1; }
Current.CustomSettings1 ??= Current.GDPISettings ?? def.CustomSettings1;
Current.CustomSettings2 ??= def.CustomSettings2;
Current.CustomSettings3 ??= def.CustomSettings3;
}
catch (Exception)
{
Expand Down
2,094 changes: 477 additions & 1,617 deletions GDPIControl/FormMain.Designer.cs

Large diffs are not rendered by default.

149 changes: 70 additions & 79 deletions GDPIControl/FormMain.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
using GDPIControl.Model;
using GDPIControl.Forms;
using GDPIControl.Model;
using GDPIControl.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDPIControl
{
public partial class FormMain : Form
{
private readonly Regex IP_R = new(@"^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$");
private readonly HashSet<Modeset> CustomModesets;
private readonly List<(RadioButton Button, Modeset Modeset)> RBModesets;
private readonly ControlSettings Settings = Config.Current;

public FormMain()
{
InitializeComponent();
CustomModesets = new() {
Modeset.Custom1,
Modeset.Custom2,
Modeset.Custom3
};
RBModesets = new List<(RadioButton Button, Modeset Modeset)>
{
(RB_M1,Modeset.M1),
Expand All @@ -27,17 +33,19 @@ public FormMain()
(RB_M4,Modeset.M4),
(RB_M5,Modeset.M5),
(RB_M6,Modeset.M6),
(RB_Custom,Modeset.Custom)
(RB_Custom_1,Modeset.Custom1),
(RB_Custom_2,Modeset.Custom2),
(RB_Custom_3,Modeset.Custom3)
};
RBModesets.First(X => X.Modeset == Settings.Modeset).Button.Checked = true;
MI_Autostart.Checked = Settings.AutostartGDPI;
MI_Minimized.Checked = Settings.LaunchMinimazed;
MI_Logon.Checked = ControlTask.IsRegistered;

BS_ControlSettings.DataSource = Settings;
BS_GDPISettings.DataSource = Settings.GDPISettings;

SetArguments();
RefreshUI();
RefreshArguments();
if (Settings.AutostartGDPI) { StartGDPI(); } else { StopGDPI(); }
}

Expand All @@ -47,27 +55,30 @@ private void CloseGDPIControl()
TrayControl.Icon = null;
TrayControl.Visible = false;
TrayControl.Dispose();
SetArguments();
RefreshArguments();
Application.Exit();
}

private void SetArguments()
private void RefreshArguments()
{
string Arguments;
Settings.Modeset = RBModesets.First(X => X.Button.Checked).Modeset;
if (Settings.Modeset == Modeset.Custom)
{
Arguments = Settings.GDPISettings.ToArguments();
}
else
var Arguments = Settings.Modeset switch
{
Arguments = GDPISettings.ModesetArgument(Settings.Modeset);
}
Modeset.Custom1 => Settings.CustomSettings1.ToArguments(),
Modeset.Custom2 => Settings.CustomSettings2.ToArguments(),
Modeset.Custom3 => Settings.CustomSettings3.ToArguments(),
_ => GDPISettings.ModesetArgument(Settings.Modeset)
};

if (Settings.UseBlacklist) { Arguments += $@" --blacklist ""{Constants.BlacklistPath}"""; }
if (Settings.UseUserlist) { Arguments += $@" --blacklist ""{Constants.UserlistPath}"""; }
Settings.Arguments = Arguments;
}

B_Copy.Enabled = Settings.Modeset != Modeset.Custom;
private void RefreshUI()
{
B_Edit.Enabled = CustomModesets.Contains(Settings.Modeset);
B_Restart.Enabled = GDPIProcess.IsRunning;
}

private void ShowGDPIControl()
Expand All @@ -84,7 +95,7 @@ private void StartGDPI()
MI_Stop.Enabled = true;
TrayControl.Icon = Resources.icon_green;
Icon = Resources.icon_green;
SetArguments();
RefreshArguments();
GDPIProcess.Start();
}

Expand All @@ -96,25 +107,44 @@ private void StopGDPI()
MI_Stop.Enabled = false;
TrayControl.Icon = Resources.icon_red;
Icon = Resources.icon_red;
SetArguments();
RefreshArguments();
GDPIProcess.Stop();
}

private void UIState(bool state)
{
B_Restart.Enabled = state;
B_Start.Enabled = state;
B_Close.Enabled = state;
}

#region UIEvents

private void B_Close_Click(object sender, EventArgs e) => CloseGDPIControl();

private void B_Copy_Click(object sender, EventArgs e)
private void B_Edit_Click(object sender, EventArgs e)
{
using var form = new FormGDPISettings(Settings);
if (form.ShowDialog(this) == DialogResult.OK)
{
RefreshArguments();
}
}

private async void B_Restart_Click(object sender, EventArgs e)
{
Settings.GDPISettings = GDPISettings.ModesetSettings(Settings.Modeset);
RB_Custom.Checked = true;
TC_Main.SelectedTab = TP_Custom;
BS_GDPISettings.DataSource = Settings.GDPISettings;
UIState(false);
StopGDPI();
await Task.Delay(500);
StartGDPI();
UIState(true);
}

private void B_Start_Click(object sender, EventArgs e)
{
UIState(false);
if (GDPIProcess.IsRunning) { StopGDPI(); } else { StartGDPI(); }
UIState(true);
}

private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
Expand All @@ -124,23 +154,24 @@ private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
Visible = false;
}

private void FormMain_ResizeBegin(object sender, EventArgs e)
{
TP_Custom.SuspendLayout();
}

private void FormMain_ResizeEnd(object sender, EventArgs e)
{
TP_Custom.ResumeLayout();
}

private void MI_About_Click(object sender, EventArgs e)
{
var F = new FormAbout();
F.ShowDialog(this);
}

private void RB_CheckedChanged(object sender, EventArgs e) => SetArguments();
private void RB_CheckedChanged(object sender, EventArgs e)
{
var RB = (RadioButton)sender;
if (!RB.Checked) { return; }
foreach (var entry in RBModesets)
{
if (entry.Button == RB) { continue; }
entry.Button.Checked = false;
}
RefreshArguments();
RefreshUI();
}

#region Lists

Expand All @@ -152,7 +183,10 @@ private void MI_Blacklist_Click(object sender, EventArgs e)

private void MI_Userlist_Click(object sender, EventArgs e)
{
if (!File.Exists(Constants.UserlistPath)) { File.WriteAllText(Constants.UserlistPath, ""); }
if (!File.Exists(Constants.UserlistPath))
{
File.WriteAllText(Constants.UserlistPath, "");
}
Process.Start(new ProcessStartInfo(Constants.UserlistPath) { UseShellExecute = true });
}

Expand Down Expand Up @@ -185,49 +219,6 @@ private void MI_Minimized_CheckedChanged(object sender, EventArgs e)

#endregion Control settings

#region Validating
/*
Private Sub DNS_IP_Validating(sender As Object, e As CancelEventArgs) Handles DNS_IP.Validating
If DNS_IP.Text = "" Then Exit Sub
Try
Dim M = IP_R.Match(DNS_IP.Text)
e.Cancel = Not M.Success
Catch ex As Exception
e.Cancel = True
End Try
End Sub
Private Sub DNS_Port_Validating(sender As Object, e As CancelEventArgs) Handles DNS_Port.Validating
Try
Dim p = CInt(DNS_Port.Text)
e.Cancel = p <= 0 Or p > 65535
Catch ex As Exception
e.Cancel = True
End Try
End Sub
Private Sub DNS6_IP_Validating(sender As Object, e As CancelEventArgs) Handles DNS6_IP.Validating
If DNS6_IP.Text = "" Then Exit Sub
Try
Dim IP As IPAddress = Nothing
Dim r = IPAddress.TryParse(DNS6_IP.Text, IP)
Dim T = IP.AddressFamily
Catch ex As Exception
e.Cancel = True
End Try
End Sub
Private Sub DNS6_Port_Validating(sender As Object, e As CancelEventArgs) Handles DNS6_Port.Validating
Try
Dim p = CInt(DNS6_Port.Text)
e.Cancel = p <= 0 Or p > 65535
Catch ex As Exception
e.Cancel = True
End Try
End Sub
*/
#endregion Validating

#region Tray

private void MI_Close_Click(object sender, EventArgs e) => CloseGDPIControl();
Expand Down
58 changes: 26 additions & 32 deletions GDPIControl/FormMain.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -328,14 +328,8 @@
<value>236, 17</value>
</metadata>
<metadata name="BS_ControlSettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>484, 17</value>
<value>349, 17</value>
</metadata>
<metadata name="BS_GDPISettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>347, 17</value>
</metadata>
<data name="label22.Text" xml:space="preserve">
<value>Fragment (split) the packets just as --native-frag, but send them in the reversed order. Works with the websites which could not handle segmented HTTPS TLS ClientHello (because they receive the TCP flow "combined")</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAQEAAAAEAIAC/FAAANgAAADAwAAABACAA1BAAAPUUAAAgIAAAAQAgABcIAADJJQAAiVBORw0K
Expand Down
Loading

0 comments on commit 78a31ae

Please sign in to comment.