Skip to content

Commit

Permalink
v2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
msasanmh committed Jul 31, 2023
1 parent b6c5881 commit 05a712e
Show file tree
Hide file tree
Showing 56 changed files with 4,372 additions and 2,915 deletions.
80 changes: 80 additions & 0 deletions CheckDotNet.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
mode con cols=100 lines=20
@echo OFF & color 1F
:START
title Check .Net 6 Runtime Installation - MSasanMH
REM SETLOCAL: ensure the lifetime of the environment will end with the termination of the batch.
SETLOCAL EnableExtensions EnableDelayedExpansion

REM =============== Get Current Path:
pushd %~dp0
set CurrentPath=%CD%
popd

REM =============== Get System Architecture:
REG Query "HKLM\Hardware\Description\System\CentralProcessor\0" >NUL 2>&1
IF %ERRORLEVEL% EQU 0 (
REG Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && SET sArchitecture=x86 || SET sArchitecture=x64
) ELSE (
REM Default Architecture if reading registry failed:
SET sArchitecture=x64
)

:Check
IF !sArchitecture! == x64 (
IF NOT EXIST "%HomeDrive%\Program Files\dotnet\dotnet.exe" GOTO :NotInstalledX64
IF NOT EXIST "%HomeDrive%\Program Files (x86)\dotnet\dotnet.exe" GOTO :NotInstalledX86

start /b /wait "" "%HomeDrive%\Program Files\dotnet\dotnet.exe" --list-runtimes >"%CurrentPath%\tmp.txt"
SET CheckNet64=false
for /f "tokens=*" %%a in ('find /I "Microsoft.WindowsDesktop.App 6" ^< "%CurrentPath%\tmp.txt"') do (
SET CheckNet64=true
)
IF !CheckNet64! == false GOTO :NotInstalledX64

start /b /wait "" "%HomeDrive%\Program Files (x86)\dotnet\dotnet.exe" --list-runtimes >"%CurrentPath%\tmp.txt"
SET CheckNet86=false
for /f "tokens=*" %%a in ('find /I "Microsoft.WindowsDesktop.App 6" ^< "%CurrentPath%\tmp.txt"') do (
SET CheckNet86=true
)
IF !CheckNet86! == false GOTO :NotInstalledX86

) ELSE IF !sArchitecture! == x86 (
IF NOT EXIST "%HomeDrive%\Program Files\dotnet\dotnet.exe" GOTO :NotInstalledX86

start /b /wait "" "%HomeDrive%\Program Files\dotnet\dotnet.exe" --list-runtimes >"%CurrentPath%\tmp.txt"
SET CheckNet=false
for /f "tokens=*" %%a in ('find /I "Microsoft.WindowsDesktop.App 6" ^< "%CurrentPath%\tmp.txt"') do (
SET CheckNet=true
)
IF !CheckNet! == false GOTO :NotInstalledX86

)

:Installed
ECHO.
ECHO All requirements are installed.
ECHO.
GOTO :Exit

:NotInstalledX64
ECHO.
ECHO .NET Desktop Runtime v6 x64 is Not Installed.
ECHO.
GOTO :DownloadNet

:NotInstalledX86
ECHO.
ECHO .NET Desktop Runtime v6 x86 is Not Installed.
ECHO.
GOTO :DownloadNet

:DownloadNet
ECHO Download:
ECHO https://dotnet.microsoft.com/en-us/download/dotnet/6.0
ECHO.
GOTO :Exit

:Exit
IF EXIST "%CurrentPath%\tmp.txt" DEL /F /Q "%CurrentPath%\tmp.txt" >nul 2>&1
EndLocal
Pause
137 changes: 72 additions & 65 deletions MsmhTools/CustomControls/CustomProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MsmhTools;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.Windows.Forms.Design;
/*
Expand All @@ -18,7 +19,7 @@ public class CustomProgressBar : ProgressBar
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new event EventHandler? RightToLeftLayoutChanged;

private Color mBorderColor = Color.Red;
private Color mBorderColor = Color.Blue;
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
[Editor(typeof(WindowsFormsComponentEditor), typeof(Color))]
[Category("Appearance"), Description("Border Color")]
Expand All @@ -35,6 +36,22 @@ public Color BorderColor
}
}

private int mRoundedCorners = 0;
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
[Category("Appearance"), Description("Rounded Corners")]
public int RoundedCorners
{
get { return mRoundedCorners; }
set
{
if (mRoundedCorners != value)
{
mRoundedCorners = value;
Invalidate();
}
}
}

private Color mChunksColor = Color.LightBlue;
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
[Editor(typeof(WindowsFormsComponentEditor), typeof(Color))]
Expand Down Expand Up @@ -84,26 +101,11 @@ public override Font Font
}
}

private DateTime? mStartTime = null;
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
[Category("Appearance"), Description("Set Start Time Programmatically (Optional)")]
public DateTime? StartTime
{
get { return mStartTime; }
set
{
if (mStartTime != value)
{
mStartTime = value;
Invalidate();
}
}
}
public bool StopTimer { get; set; } = false;

private readonly Stopwatch StopWatch = new();
private static bool ApplicationIdle = false;
private TimeSpan elapsedTime;
private string? elapsedTimeString;
private int once = 0;
private string ElapsedTimeString = string.Empty;
private bool onceIV = true;

public CustomProgressBar() : base()
Expand Down Expand Up @@ -183,18 +185,28 @@ protected override void OnPaint(PaintEventArgs e)
else
chunksColorGradient = chunksColor.ChangeBrightness(-0.5f);

Rectangle rect = ClientRectangle;
//Rectangle rect = ClientRectangle;
Rectangle rect = new(0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
Graphics g = e.Graphics;
// Draw horizontal bar (Background and Border) With Default System Color:
//ProgressBarRenderer.DrawHorizontalBar(g, rect);

// Draw horizontal bar (Background and Border) With Custom Color:
// Fill Background
using SolidBrush bgBrush = new(backColor);
g.FillRectangle(bgBrush, rect);
g.FillRoundedRectangle(bgBrush, rect, RoundedCorners, RoundedCorners, RoundedCorners, RoundedCorners);

// Draw Border
ControlPaint.DrawBorder(g, rect, borderColor, ButtonBorderStyle.Solid);
using Pen penB = new(borderColor);
g.DrawRoundedRectangle(penB, rect, RoundedCorners, RoundedCorners, RoundedCorners, RoundedCorners);

// Min
if (Value == Minimum)
{
if (!StopWatch.IsRunning) StopWatch.Start();
StopWatch.Restart();
return;
}

// Padding
if (Value > 0)
Expand All @@ -205,30 +217,32 @@ protected override void OnPaint(PaintEventArgs e)

// Draw Chunks By Custom Color:
// The Following Is The Width Of The Bar. This Will Vary With Each Value.
int fillWidth = Width * Value / (Maximum - Minimum);
int fillWidth = rect.Width * Value / (Maximum - Minimum);

// GDI+ Doesn't Like Rectangles 0px Wide or Height
if (fillWidth == 0)
{
// Draw Only Border And Exit
ControlPaint.DrawBorder(g, rect, borderColor, ButtonBorderStyle.Solid);
g.DrawRoundedRectangle(penB, rect, RoundedCorners, RoundedCorners, RoundedCorners, RoundedCorners);
return;
}
// Rectangles For Upper And Lower Half Of Bar
Rectangle topRect = new(0, 0, fillWidth, Height / 2);
Rectangle buttomRect = new(0, Height / 2, fillWidth, Height / 2);
int y = Value < 2 ? 1 : 0;
Rectangle topRect = new(0, y, fillWidth, (rect.Height / 2) + 1 - y); // +1 to avoid "having a dark line in the middle of the bar"
Rectangle buttomRect = new(0, (rect.Height / 2) - y, fillWidth, (rect.Height / 2) - y);

// Paint Upper Half
using LinearGradientBrush gbUH = new(new Point(0, 0), new Point(0, Height / 2), chunksColorGradient, chunksColor);
e.Graphics.FillRectangle(gbUH, topRect);
int right = Value < RoundedCorners ? Value : RoundedCorners;
using LinearGradientBrush gbUH = new(new Point(topRect.X, topRect.Y), new Point(topRect.X, topRect.Height), chunksColorGradient, chunksColor);
g.FillRoundedRectangle(gbUH, topRect, RoundedCorners, right, 0, 0);

// Paint Lower Half
// (this.Height/2 - 1 Because There Would Be A Dark Line In The Middle Of The Bar)
using LinearGradientBrush gbLH = new(new Point(0, Height / 2 - 1), new Point(0, Height), chunksColor, chunksColorGradient);
e.Graphics.FillRectangle(gbLH, buttomRect);
// -1 to avoid "out of memory exception"
using LinearGradientBrush gbLH = new(new Point(buttomRect.X, buttomRect.Y - 1), new Point(buttomRect.X, buttomRect.Height), chunksColor, chunksColorGradient);
g.FillRoundedRectangle(gbLH, buttomRect, 0, 0, right, RoundedCorners);

// Paint Border
ControlPaint.DrawBorder(g, rect, borderColor, ButtonBorderStyle.Solid);
g.DrawRoundedRectangle(penB, rect, RoundedCorners, RoundedCorners, RoundedCorners, RoundedCorners);
}

// Compute Percent
Expand Down Expand Up @@ -267,42 +281,35 @@ protected override void OnPaint(PaintEventArgs e)
g.DrawString(CustomText, Font, brush, locationCustomTextRight);
}
}

// Compute Elapsed Time
if (StartTime.HasValue == true)
if (StopTimer && StopWatch.IsRunning) StopWatch.Stop();

ElapsedTimeString = timer();

// Max
if (Value == Maximum)
{
if (percent == 0)
{
elapsedTime = new(0, 0, 0, 0, 0);
elapsedTimeString = string.Empty;
}
else if (1 < percent && percent < 100)
{
elapsedTime = (TimeSpan)(DateTime.Now - StartTime);
elapsedTimeString = string.Format(@"Time: {0:00}:{1:00}:{2:000}", elapsedTime.Minutes, elapsedTime.Seconds, Math.Round((double)elapsedTime.Milliseconds / 10));
once = 0;
}
else if (percent == 100)
{
if (once == 0)
{
elapsedTime = (TimeSpan)(DateTime.Now - StartTime);
elapsedTimeString = string.Format(@"Time: {0:00}:{1:00}:{2:000}", elapsedTime.Minutes, elapsedTime.Seconds, Math.Round((double)elapsedTime.Milliseconds / 10));
once++;
}
}
if (StopWatch.IsRunning) StopWatch.Stop();
}

SizeF lenElapsedTime = g.MeasureString(elapsedTimeString, Font);
if (RightToLeft == RightToLeft.No)
{
Point locationElapsedTimeRight = new(Convert.ToInt32(Width - lenElapsedTime.Width - 5), Convert.ToInt32((Height / 2) - lenElapsedTime.Height / 2));
g.DrawString(elapsedTimeString, Font, brush, locationElapsedTimeRight);
}
else
{
Point locationElapsedTimeLeft = new(5, Convert.ToInt32((Height / 2) - lenElapsedTime.Height / 2));
g.DrawString(elapsedTimeString, Font, brush, locationElapsedTimeLeft);
}
string timer()
{
TimeSpan eTime = StopWatch.Elapsed;
eTime = TimeSpan.FromMilliseconds(Math.Round(eTime.TotalMilliseconds, 1));
return $"Time: {eTime:hh\\:mm\\:ss\\.f}";
}

SizeF lenElapsedTime = g.MeasureString(ElapsedTimeString, Font);
if (RightToLeft == RightToLeft.No)
{
Point locationElapsedTimeRight = new(Convert.ToInt32(Width - lenElapsedTime.Width - 5), Convert.ToInt32((Height / 2) - lenElapsedTime.Height / 2));
g.DrawString(ElapsedTimeString, Font, brush, locationElapsedTimeRight);
}
else
{
Point locationElapsedTimeLeft = new(5, Convert.ToInt32((Height / 2) - lenElapsedTime.Height / 2));
g.DrawString(ElapsedTimeString, Font, brush, locationElapsedTimeLeft);
}
}

Expand Down
2 changes: 1 addition & 1 deletion MsmhTools/MsmhTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Version>$(VersionPrefix)1.1.0</Version>
<Version>$(VersionPrefix)1.2.0</Version>
<Company>$(Authors)MSasanMH</Company>
<Copyright>MSasanMH</Copyright>
</PropertyGroup>
Expand Down
19 changes: 12 additions & 7 deletions MsmhTools/MsmhTools/DnsTool/DNSCryptConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void DisableDoH()
}
}

public void ChangePersonalServer(string sdns)
public void ChangePersonalServer(string[] sdns)
{
string sectionName = "[static]";
string keyName = "stamp";
Expand All @@ -209,15 +209,20 @@ public void ChangePersonalServer(string sdns)
{
ConfigList.RemoveRange(n + 1, ConfigList.Count - (n + 1));
}

// e.g. [static.Personal]
// e.g. stamp = 'sdns://AgcAAAAAAAAABzEuMC4wLjEAEmRucy5jbG91ZGZsYXJlLmNvbQovZG5zLXF1ZXJ5'
string newLine1 = "[static.Personal]";
string newLine2 = $"{keyName} = '{sdns}'";
ConfigList.Add(string.Empty);
ConfigList.Add(newLine1);
ConfigList.Add(newLine2);
for (int i = 0; i < sdns.Length; i++)
{
ConfigList.Add(string.Empty);
string newLine1 = $"[static.Personal{i + 1}]";
ConfigList.Add(newLine1);

string sdnsOne = sdns[i];
string newLine2 = $"{keyName} = '{sdnsOne}'";
ConfigList.Add(newLine2);
}

break;
}
}
Expand Down
Loading

0 comments on commit 05a712e

Please sign in to comment.