From 865aa6742c3ba4c2ec7eff91d0fdacb76fa5f09a Mon Sep 17 00:00:00 2001
From: matty <10895809+murrty@users.noreply.github.com>
Date: Sat, 24 Sep 2022 05:04:26 -0500
Subject: [PATCH] use special designed Point + Size structs
---
.../Classes/DataClasses/YoutubeDlData.cs | 2 +-
youtube-dl-gui/Classes/Verification.cs | 1 -
youtube-dl-gui/Config/Config.cs | 25 +--
youtube-dl-gui/Config/Config_Saved.cs | 18 +--
youtube-dl-gui/Config/Point.cs | 64 ++++++++
youtube-dl-gui/Config/Size.cs | 72 +++++++++
youtube-dl-gui/CopyData/CopyData.cs | 13 +-
youtube-dl-gui/Forms/frmArchiveDownloader.cs | 2 +-
youtube-dl-gui/Forms/frmBatchConverter.cs | 3 +-
youtube-dl-gui/Forms/frmBatchDownloader.cs | 3 +-
youtube-dl-gui/Forms/frmDownloadLanguage.cs | 3 +-
youtube-dl-gui/Forms/frmDownloader.cs | 2 +-
youtube-dl-gui/Forms/frmExtendedDownloader.cs | 4 +-
.../Forms/frmGenericDownloadProgress.cs | 4 +-
youtube-dl-gui/Forms/frmMain.cs | 6 +-
youtube-dl-gui/Forms/frmSettings.cs | 13 +-
youtube-dl-gui/GlobalNamespaces.cs | 4 +-
youtube-dl-gui/Logging/Forms/frmLog.cs | 4 +-
.../Updater/API Data/GithubAsset.cs | 2 +-
youtube-dl-gui/Updater/API Data/GithubData.cs | 3 +-
.../Updater/API Data/GithubRepoContent.cs | 2 +-
.../Updater/Form/frmUpdateAvailable.cs | 3 +-
youtube-dl-gui/Updater/GitID.cs | 2 +-
youtube-dl-gui/Updater/GithubLinks.cs | 2 +-
youtube-dl-gui/Updater/UpdateChecker.cs | 2 +-
youtube-dl-gui/Updater/Version.cs | 143 ++++++++++++------
youtube-dl-gui/youtube-dl-gui.csproj | 2 +
27 files changed, 279 insertions(+), 125 deletions(-)
create mode 100644 youtube-dl-gui/Config/Point.cs
create mode 100644 youtube-dl-gui/Config/Size.cs
diff --git a/youtube-dl-gui/Classes/DataClasses/YoutubeDlData.cs b/youtube-dl-gui/Classes/DataClasses/YoutubeDlData.cs
index 63a398bf..bec93318 100644
--- a/youtube-dl-gui/Classes/DataClasses/YoutubeDlData.cs
+++ b/youtube-dl-gui/Classes/DataClasses/YoutubeDlData.cs
@@ -75,7 +75,7 @@ public static YoutubeDlData GenerateData(string URL, out string RetrievedData) {
return null;
}
public Image GetThumbnail() {
- if (Config.Settings.Downloads.YtdlType switch { (int)updater.GitID.YtDlp or (int)updater.GitID.YtDlpNightly => false, _ => true }) {
+ if (Config.Settings.Downloads.YtdlType switch { (int)GitID.YtDlp or (int)GitID.YtDlpNightly => false, _ => true }) {
Log.Write($"Cannot download the thumbnail for \"{URL}\" because the selected youtube-dl fork is not supported.");
return null;
}
diff --git a/youtube-dl-gui/Classes/Verification.cs b/youtube-dl-gui/Classes/Verification.cs
index 965f6834..318a3201 100644
--- a/youtube-dl-gui/Classes/Verification.cs
+++ b/youtube-dl-gui/Classes/Verification.cs
@@ -1,7 +1,6 @@
namespace youtube_dl_gui;
using System.IO;
-using youtube_dl_gui.updater;
internal static class Verification {
private static GitID YoutubeDlGitType = GitID.YtDlp;
diff --git a/youtube-dl-gui/Config/Config.cs b/youtube-dl-gui/Config/Config.cs
index e42a6679..c39e3568 100644
--- a/youtube-dl-gui/Config/Config.cs
+++ b/youtube-dl-gui/Config/Config.cs
@@ -1,12 +1,7 @@
namespace youtube_dl_gui;
-
-using System.Drawing;
-
internal class Config {
public static volatile Config Settings;
- internal static readonly Point InvalidPoint = new(-32_000, -32_000);
-
public Config_Initialization Initialization;
public Config_Batch Batch;
public Config_Converts Converts;
@@ -110,22 +105,4 @@ public void Save(ConfigType Type) {
break;
}
}
-
- ///
- /// Checks if a point is a valid one to use.
- ///
- /// The value to validate.
- /// If the input is a valid point.
- public static bool ValidPoint(Point input) {
- return input.X != InvalidPoint.X && input.Y != InvalidPoint.Y;
- }
-
- ///
- /// Checks if a size is a valid one to use.
- ///
- /// The value to validate.
- /// If the input is a valid size.
- public static bool ValidSize(Size input) {
- return input.Width > 0 && input.Height > 0;
- }
-}
+}
\ No newline at end of file
diff --git a/youtube-dl-gui/Config/Config_Saved.cs b/youtube-dl-gui/Config/Config_Saved.cs
index 40298c46..aa42de16 100644
--- a/youtube-dl-gui/Config/Config_Saved.cs
+++ b/youtube-dl-gui/Config/Config_Saved.cs
@@ -1,7 +1,5 @@
namespace youtube_dl_gui;
-using System.Drawing;
-
internal class Config_Saved {
private const string ConfigName = "Saved";
@@ -79,24 +77,24 @@ public void Load() {
VideoFormat = fVideoFormat = IniProvider.Read(VideoFormat, 0, ConfigName);
AudioFormat = fAudioFormat = IniProvider.Read(AudioFormat, 0, ConfigName);
AudioVBRQuality = fAudioVBRQuality = IniProvider.Read(AudioVBRQuality, 0, ConfigName);
- BatchDownloaderLocation = fBatchDownloaderLocation = IniProvider.Read(BatchDownloaderLocation, Config.InvalidPoint, ConfigName);
- BatchConverterLocation = fBatchConverterLocation = IniProvider.Read(BatchConverterLocation, Config.InvalidPoint, ConfigName);
+ BatchDownloaderLocation = fBatchDownloaderLocation = IniProvider.Read(BatchDownloaderLocation, Point.Invalid, ConfigName);
+ BatchConverterLocation = fBatchConverterLocation = IniProvider.Read(BatchConverterLocation, Point.Invalid, ConfigName);
MainFormSize = fMainFormSize = IniProvider.Read(MainFormSize, Size.Empty, ConfigName);
SettingsFormSize = fSettingsFormSize = IniProvider.Read(SettingsFormSize, Size.Empty, ConfigName);
FileNameSchemaHistory = fFileNameSchemaHistory = IniProvider.Read(FileNameSchemaHistory, "%(title)s-%(id)s.%(ext)s|%(uploader)s\\(%(playlist_index)s) %(title)s-%(id)s.%(ext)s", ConfigName);
DownloadCustomArguments = fDownloadCustomArguments = IniProvider.Read(DownloadCustomArguments, string.Empty, ConfigName);
CustomArgumentsIndex = fCustomArgumentsIndex = IniProvider.Read(CustomArgumentsIndex, -1, ConfigName);
- MainFormLocation = fMainFormLocation = IniProvider.Read(MainFormLocation, Config.InvalidPoint, ConfigName);
- MainFormLocation = fMainFormLocation = IniProvider.Read(MainFormLocation, Config.InvalidPoint, ConfigName);
- ExtendedDownloaderLocation = fExtendedDownloaderLocation = IniProvider.Read(ExtendedDownloaderLocation, Config.InvalidPoint, ConfigName);
+ MainFormLocation = fMainFormLocation = IniProvider.Read(MainFormLocation, Point.Invalid, ConfigName);
+ MainFormLocation = fMainFormLocation = IniProvider.Read(MainFormLocation, Point.Invalid, ConfigName);
+ ExtendedDownloaderLocation = fExtendedDownloaderLocation = IniProvider.Read(ExtendedDownloaderLocation, Point.Invalid, ConfigName);
ExtendedDownloaderSize = fExtendedDownloaderSize = IniProvider.Read(ExtendedDownloaderSize, Size.Empty, ConfigName);
- ArchiveDownloaderLocation = fArchiveDownloaderLocation = IniProvider.Read(ArchiveDownloaderLocation, Config.InvalidPoint, ConfigName);
- LogLocation = fLogLocation = IniProvider.Read(LogLocation, Config.InvalidPoint, ConfigName);
+ ArchiveDownloaderLocation = fArchiveDownloaderLocation = IniProvider.Read(ArchiveDownloaderLocation, Point.Invalid, ConfigName);
+ LogLocation = fLogLocation = IniProvider.Read(LogLocation, Point.Invalid, ConfigName);
LogSize = fLogSize = IniProvider.Read(LogSize, Size.Empty, ConfigName);
ExtendedDownloadVideoColumns = fExtendedDownloadVideoColumns = IniProvider.Read(ExtendedDownloadVideoColumns, string.Empty, ConfigName);
ExtendedDownloadAudioColumns = fExtendedDownloadAudioColumns = IniProvider.Read(ExtendedDownloadAudioColumns, string.Empty, ConfigName);
ExtendedDownloadUnknownColumns = fExtendedDownloadUnknownColumns = IniProvider.Read(ExtendedDownloadUnknownColumns, string.Empty, ConfigName);
- QuickDownloaderLocation = fQuickDownloaderLocation = IniProvider.Read(QuickDownloaderLocation, Config.InvalidPoint, ConfigName);
+ QuickDownloaderLocation = fQuickDownloaderLocation = IniProvider.Read(QuickDownloaderLocation, Point.Invalid, ConfigName);
}
public void Save() {
diff --git a/youtube-dl-gui/Config/Point.cs b/youtube-dl-gui/Config/Point.cs
new file mode 100644
index 00000000..d6cd58dd
--- /dev/null
+++ b/youtube-dl-gui/Config/Point.cs
@@ -0,0 +1,64 @@
+namespace murrty.structs;
+using System.Runtime.InteropServices;
+[StructLayout(LayoutKind.Sequential)]
+public struct Point {
+ ///
+ /// Represents an invalid Point value.
+ ///
+ public static readonly Point Invalid = new(-32_000, -32_000);
+ ///
+ /// The X-coordinate of the Point.
+ ///
+ public int X {
+ get; set;
+ }
+
+ ///
+ /// The Y-coordinate of the Point.
+ ///
+ public int Y {
+ get; set;
+ }
+
+ ///
+ /// Whether the can be considered a valid compared to .
+ ///
+ public bool Valid => this.X != Invalid.X && this.Y != Invalid.Y;
+
+ public Point() {
+ X = 0;
+ Y = 0;
+ }
+
+ public Point(int X, int Y) {
+ this.X = X;
+ this.Y = Y;
+ }
+
+ ///
+ public override bool Equals(object obj) => obj is Point point && this.X == point.X && this.Y == point.Y;
+
+ ///
+ public override int GetHashCode() {
+ int hashCode = 1861411795;
+ hashCode = hashCode * -1521134295 + this.X.GetHashCode();
+ hashCode = hashCode * -1521134295 + this.Y.GetHashCode();
+ return hashCode;
+ }
+
+ public static bool operator ==(Point a, Point b) => a.X == b.X && a.Y == b.Y;
+
+ public static bool operator !=(Point a, Point b) => a.X != b.X || a.Y != b.Y;
+
+ ///
+ /// Implicitly converts this Point structure to a System.Drawing.Point structure.
+ ///
+ ///
+ public static implicit operator System.Drawing.Point(Point p) => new(p.X, p.Y);
+
+ ///
+ /// Implicity converts a System.Drawing.Point structure to this Point structure.
+ ///
+ ///
+ public static implicit operator Point(System.Drawing.Point p) => new(p.X, p.Y);
+}
\ No newline at end of file
diff --git a/youtube-dl-gui/Config/Size.cs b/youtube-dl-gui/Config/Size.cs
new file mode 100644
index 00000000..b87967d1
--- /dev/null
+++ b/youtube-dl-gui/Config/Size.cs
@@ -0,0 +1,72 @@
+namespace murrty.structs;
+using System.Runtime.InteropServices;
+[StructLayout(LayoutKind.Sequential)]
+public struct Size {
+ ///
+ /// Represents an empty Size value.
+ ///
+ public static readonly Size Empty = new(0, 0);
+ ///
+ /// The width of the Size.
+ ///
+ public int Width {
+ get; set;
+ }
+ ///
+ /// The height of the Size.
+ ///
+ public int Height {
+ get; set;
+ }
+ ///
+ /// Whether the can be considered a valid compared to .
+ ///
+ public bool Valid => this.Width > Empty.Width && this.Height > Empty.Height;
+
+ public Size() {
+ this = Empty;
+ }
+
+ public Size(int Width, int Height) {
+ this.Width = Width;
+ this.Height = Height;
+ }
+
+ ///
+ public override bool Equals(object obj) => obj is Size size && this.Width == size.Width && this.Height == size.Height;
+
+ ///
+ public override int GetHashCode() {
+ int hashCode = 859600377;
+ hashCode = hashCode * -1521134295 + this.Width.GetHashCode();
+ hashCode = hashCode * -1521134295 + this.Height.GetHashCode();
+ return hashCode;
+ }
+
+ ///
+ /// Equals-to operator.
+ ///
+ ///
+ ///
+ ///
+ public static bool operator ==(Size a, Size b) => a.Width == b.Width && a.Height == b.Height;
+ ///
+ /// Not equals-to operator.
+ ///
+ ///
+ ///
+ ///
+ public static bool operator !=(Size a, Size b) => a.Width != b.Width || a.Height != b.Height;
+
+ ///
+ /// Implicitly converts this Point structure to a System.Drawing.Point structure.
+ ///
+ ///
+ public static implicit operator System.Drawing.Size(Size s) => new(s.Width, s.Height);
+
+ ///
+ /// Implicity converts a System.Drawing.Point structure to this Point structure.
+ ///
+ ///
+ public static implicit operator Size(System.Drawing.Size s) => new(s.Width, s.Height);
+}
\ No newline at end of file
diff --git a/youtube-dl-gui/CopyData/CopyData.cs b/youtube-dl-gui/CopyData/CopyData.cs
index c5c47894..9e621ef5 100644
--- a/youtube-dl-gui/CopyData/CopyData.cs
+++ b/youtube-dl-gui/CopyData/CopyData.cs
@@ -10,7 +10,7 @@ internal sealed class CopyData {
public const int WM_UPDATEDATA = 0x1002;
public const int WM_UPDATERREADY = 0x1003;
- public static nint NintAlloc(T param) {
+ public static nint NintAlloc(StructVal param) {
nint retval = Marshal.AllocHGlobal(Marshal.SizeOf(param));
Marshal.StructureToPtr(param, retval, false);
return retval;
@@ -28,20 +28,9 @@ public static T GetParam(nint LParam) {
return Marshal.PtrToStructure(DataStruct.lpData);
}
- ///
- /// The FindWindow function retrieves a handle to the top-level
- /// window whose class name and window name match the specified strings.
- /// This function does not search child windows. This function does not perform a case-sensitive search.
- ///
- /// the class name for the window to search for
- /// the name of the window to search for
- ///
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern nint FindWindow(string strClassName, string strWindowName);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern int GetClassName(nint hWnd, StringBuilder lpClassName, int nMaxCount);
-
[DllImport("user32.dll", SetLastError = true)]
public static extern int SendMessage(nint hWnd, int Msg, nint wParam, nint lParam);
}
\ No newline at end of file
diff --git a/youtube-dl-gui/Forms/frmArchiveDownloader.cs b/youtube-dl-gui/Forms/frmArchiveDownloader.cs
index a90954f5..769b58e2 100644
--- a/youtube-dl-gui/Forms/frmArchiveDownloader.cs
+++ b/youtube-dl-gui/Forms/frmArchiveDownloader.cs
@@ -9,7 +9,7 @@ public frmArchiveDownloader() {
LoadLanguage();
this.Load += (s, e) => {
- if (Config.ValidPoint(Config.Settings.Saved.ArchiveDownloaderLocation)) {
+ if (Config.Settings.Saved.ArchiveDownloaderLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.ArchiveDownloaderLocation;
}
diff --git a/youtube-dl-gui/Forms/frmBatchConverter.cs b/youtube-dl-gui/Forms/frmBatchConverter.cs
index 73df533a..20d75474 100644
--- a/youtube-dl-gui/Forms/frmBatchConverter.cs
+++ b/youtube-dl-gui/Forms/frmBatchConverter.cs
@@ -18,7 +18,8 @@ public frmBatchConverter() {
lvBatchConvertQueue.SmallImageList = Program.BatchStatusImages;
this.Load += (s, e) => {
- if (Config.ValidPoint(Config.Settings.Saved.BatchConverterLocation)) {
+ if (Config.Settings.Saved.BatchConverterLocation.Valid) {
+ this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.BatchConverterLocation;
}
};
diff --git a/youtube-dl-gui/Forms/frmBatchDownloader.cs b/youtube-dl-gui/Forms/frmBatchDownloader.cs
index 01e5a2ae..a4d9da6d 100644
--- a/youtube-dl-gui/Forms/frmBatchDownloader.cs
+++ b/youtube-dl-gui/Forms/frmBatchDownloader.cs
@@ -94,7 +94,8 @@ private void frmBatchDownloader_Load(object sender, EventArgs e) {
cbBatchFormat.SelectedIndex = Config.Settings.Batch.SelectedAudioFormat;
}
- if (Config.ValidPoint(Config.Settings.Saved.BatchConverterLocation)) {
+ if (Config.Settings.Saved.BatchConverterLocation.Valid) {
+ this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.BatchConverterLocation;
}
chkBatchDownloadClipboardScanVerifyLinks.Checked = Config.Settings.Batch.ClipboardScannerVerifyLinks;
diff --git a/youtube-dl-gui/Forms/frmDownloadLanguage.cs b/youtube-dl-gui/Forms/frmDownloadLanguage.cs
index d1df99cd..427133b7 100644
--- a/youtube-dl-gui/Forms/frmDownloadLanguage.cs
+++ b/youtube-dl-gui/Forms/frmDownloadLanguage.cs
@@ -1,7 +1,6 @@
using System.Drawing;
using System.Windows.Forms;
-
-using youtube_dl_gui.updater;
+using murrty.updater;
namespace youtube_dl_gui {
public partial class frmDownloadLanguage : Form {
diff --git a/youtube-dl-gui/Forms/frmDownloader.cs b/youtube-dl-gui/Forms/frmDownloader.cs
index 43c02867..cddd91e1 100644
--- a/youtube-dl-gui/Forms/frmDownloader.cs
+++ b/youtube-dl-gui/Forms/frmDownloader.cs
@@ -47,7 +47,7 @@ private void frmExtendedMassDownloader_Load(object sender, EventArgs e) {
}
}
- if (Config.ValidPoint(Config.Settings.Saved.QuickDownloaderLocation)) {
+ if (Config.Settings.Saved.QuickDownloaderLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.QuickDownloaderLocation;
}
diff --git a/youtube-dl-gui/Forms/frmExtendedDownloader.cs b/youtube-dl-gui/Forms/frmExtendedDownloader.cs
index f9481719..710844d5 100644
--- a/youtube-dl-gui/Forms/frmExtendedDownloader.cs
+++ b/youtube-dl-gui/Forms/frmExtendedDownloader.cs
@@ -90,11 +90,11 @@ public frmExtendedDownloader(string URL, bool Archived) {
lvUnknownFormats.SmallImageList = Program.ExtendedDownloaderSelectedImages;
this.Load += (s, e) => {
- if (Config.ValidPoint(Config.Settings.Saved.ExtendedDownloaderLocation)) {
+ if (Config.Settings.Saved.ExtendedDownloaderLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.ExtendedDownloaderLocation;
}
- if (Config.ValidSize(Config.Settings.Saved.ExtendedDownloaderSize))
+ if (Config.Settings.Saved.ExtendedDownloaderSize.Valid)
this.Size = Config.Settings.Saved.ExtendedDownloaderSize;
if (!Config.Settings.Saved.ExtendedDownloadVideoColumns.IsNullEmptyWhitespace())
lvVideoFormats.SetColumnWidths(Config.Settings.Saved.ExtendedDownloadVideoColumns);
diff --git a/youtube-dl-gui/Forms/frmGenericDownloadProgress.cs b/youtube-dl-gui/Forms/frmGenericDownloadProgress.cs
index eabb48b2..edd176db 100644
--- a/youtube-dl-gui/Forms/frmGenericDownloadProgress.cs
+++ b/youtube-dl-gui/Forms/frmGenericDownloadProgress.cs
@@ -84,9 +84,9 @@ public frmGenericDownloadProgress(string URL, string Output) {
}
};
}
- public frmGenericDownloadProgress(string URL, string Output, System.Drawing.Point Location) : this(URL, Output) {
+ public frmGenericDownloadProgress(string URL, string Output, Point Location) : this(URL, Output) {
this.Load += (s, e) => {
- if (Config.ValidPoint(Location)) {
+ if (Location.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Location;
}
diff --git a/youtube-dl-gui/Forms/frmMain.cs b/youtube-dl-gui/Forms/frmMain.cs
index a09f892d..01bee0dc 100644
--- a/youtube-dl-gui/Forms/frmMain.cs
+++ b/youtube-dl-gui/Forms/frmMain.cs
@@ -129,10 +129,12 @@ private void frmMain_Load(object sender, EventArgs e) {
YtdlUpdateCheckThread.Start();
}
- if (Config.ValidPoint(Config.Settings.Saved.MainFormLocation))
+ if (Config.Settings.Saved.MainFormLocation.Valid) {
+ this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.MainFormLocation;
+ }
- this.Size = Config.ValidSize(Config.Settings.Saved.MainFormSize) ?
+ this.Size = Config.Settings.Saved.MainFormSize.Valid ?
Config.Settings.Saved.MainFormSize : this.MinimumSize;
LoadLanguage();
diff --git a/youtube-dl-gui/Forms/frmSettings.cs b/youtube-dl-gui/Forms/frmSettings.cs
index 70b3304a..7cbe178f 100644
--- a/youtube-dl-gui/Forms/frmSettings.cs
+++ b/youtube-dl-gui/Forms/frmSettings.cs
@@ -26,8 +26,8 @@ public partial class frmSettings : Form {
public frmSettings() {
InitializeComponent();
- for (int i = 0; i < updater.GithubLinks.Repos.Length; i++) {
- cbSettingsDownloadsUpdatingYtdlType.Items.Add($"{updater.GithubLinks.Users[i]}/{updater.GithubLinks.Repos[i]}{(i == 0 ? " (default)" : "")}");
+ for (int i = 0; i < GithubLinks.Repos.Length; i++) {
+ cbSettingsDownloadsUpdatingYtdlType.Items.Add($"{GithubLinks.Users[i]}/{GithubLinks.Repos[i]}{(i == 0 ? " (default)" : "")}");
}
LoadingForm = true;
@@ -38,11 +38,10 @@ public frmSettings() {
}
private void frmSettings_Load(object sender, EventArgs e) {
- if (Config.Settings.Saved.SettingsFormSize != System.Drawing.Size.Empty) {
+ if (Config.Settings.Saved.SettingsFormSize.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Size = Config.Settings.Saved.SettingsFormSize;
}
-
LoadingForm = false;
}
@@ -747,9 +746,9 @@ private void llbSettingsDownloadsYtdlTypeViewRepo_LinkClicked(object sender, Lin
if (cbSettingsDownloadsUpdatingYtdlType.SelectedIndex > -1) {
Process.Start(
string.Format(
- updater.GithubLinks.GithubRepoUrl,
- updater.GithubLinks.Users[cbSettingsDownloadsUpdatingYtdlType.SelectedIndex],
- updater.GithubLinks.Repos[cbSettingsDownloadsUpdatingYtdlType.SelectedIndex]
+ GithubLinks.GithubRepoUrl,
+ GithubLinks.Users[cbSettingsDownloadsUpdatingYtdlType.SelectedIndex],
+ GithubLinks.Repos[cbSettingsDownloadsUpdatingYtdlType.SelectedIndex]
)
);
}
diff --git a/youtube-dl-gui/GlobalNamespaces.cs b/youtube-dl-gui/GlobalNamespaces.cs
index dd944bca..3b99105b 100644
--- a/youtube-dl-gui/GlobalNamespaces.cs
+++ b/youtube-dl-gui/GlobalNamespaces.cs
@@ -2,4 +2,6 @@
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
-global using Version = youtube_dl_gui.updater.Version;
\ No newline at end of file
+global using Point = murrty.structs.Point;
+global using Size = murrty.structs.Size;
+global using Version = murrty.updater.Version;
\ No newline at end of file
diff --git a/youtube-dl-gui/Logging/Forms/frmLog.cs b/youtube-dl-gui/Logging/Forms/frmLog.cs
index 02cbd22a..c914f068 100644
--- a/youtube-dl-gui/Logging/Forms/frmLog.cs
+++ b/youtube-dl-gui/Logging/Forms/frmLog.cs
@@ -23,12 +23,12 @@ public frmLog() {
}
private void frmLog_Load(object sender, EventArgs e) {
- if (Config.ValidPoint(Config.Settings.Saved.LogLocation)) {
+ if (Config.Settings.Saved.LogLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.LogLocation;
}
- if (Config.ValidSize(Config.Settings.Saved.LogSize)) {
+ if (Config.Settings.Saved.LogSize.Valid) {
this.Size = Config.Settings.Saved.LogSize;
}
}
diff --git a/youtube-dl-gui/Updater/API Data/GithubAsset.cs b/youtube-dl-gui/Updater/API Data/GithubAsset.cs
index 567e16b1..c65a0db5 100644
--- a/youtube-dl-gui/Updater/API Data/GithubAsset.cs
+++ b/youtube-dl-gui/Updater/API Data/GithubAsset.cs
@@ -1,4 +1,4 @@
-namespace youtube_dl_gui.updater;
+namespace murrty.updater;
using System.Runtime.Serialization;
diff --git a/youtube-dl-gui/Updater/API Data/GithubData.cs b/youtube-dl-gui/Updater/API Data/GithubData.cs
index 6c82268e..5cb86f58 100644
--- a/youtube-dl-gui/Updater/API Data/GithubData.cs
+++ b/youtube-dl-gui/Updater/API Data/GithubData.cs
@@ -1,7 +1,8 @@
-namespace youtube_dl_gui.updater;
+namespace murrty.updater;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
+using youtube_dl_gui;
[DataContract]
public sealed class GithubData {
diff --git a/youtube-dl-gui/Updater/API Data/GithubRepoContent.cs b/youtube-dl-gui/Updater/API Data/GithubRepoContent.cs
index 210eb97f..49c8fdc8 100644
--- a/youtube-dl-gui/Updater/API Data/GithubRepoContent.cs
+++ b/youtube-dl-gui/Updater/API Data/GithubRepoContent.cs
@@ -1,4 +1,4 @@
-namespace youtube_dl_gui.updater;
+namespace murrty.updater;
public class GithubRepoContent {
public string name { get; init; }
diff --git a/youtube-dl-gui/Updater/Form/frmUpdateAvailable.cs b/youtube-dl-gui/Updater/Form/frmUpdateAvailable.cs
index 59a7c2a4..e71ec4d4 100644
--- a/youtube-dl-gui/Updater/Form/frmUpdateAvailable.cs
+++ b/youtube-dl-gui/Updater/Form/frmUpdateAvailable.cs
@@ -1,4 +1,5 @@
using System.Windows.Forms;
+using murrty.updater;
namespace youtube_dl_gui {
@@ -12,7 +13,7 @@ public partial class frmUpdateAvailable : Form {
///
/// The update that is available.
///
- internal updater.GithubData UpdateData { get; init; } = null;
+ internal GithubData UpdateData { get; init; } = null;
public frmUpdateAvailable() {
InitializeComponent();
diff --git a/youtube-dl-gui/Updater/GitID.cs b/youtube-dl-gui/Updater/GitID.cs
index ccc11800..df2edffb 100644
--- a/youtube-dl-gui/Updater/GitID.cs
+++ b/youtube-dl-gui/Updater/GitID.cs
@@ -1,4 +1,4 @@
-namespace youtube_dl_gui.updater;
+namespace youtube_dl_gui;
public enum GitID : int {
YtDlp = 0,
diff --git a/youtube-dl-gui/Updater/GithubLinks.cs b/youtube-dl-gui/Updater/GithubLinks.cs
index 69d5f6a3..6c934562 100644
--- a/youtube-dl-gui/Updater/GithubLinks.cs
+++ b/youtube-dl-gui/Updater/GithubLinks.cs
@@ -1,4 +1,4 @@
-namespace youtube_dl_gui.updater;
+namespace youtube_dl_gui;
internal static class GithubLinks {
public const string GithubRepoUrl = "https://github.com/{0}/{1}";
diff --git a/youtube-dl-gui/Updater/UpdateChecker.cs b/youtube-dl-gui/Updater/UpdateChecker.cs
index c44e794f..1b0a2717 100644
--- a/youtube-dl-gui/Updater/UpdateChecker.cs
+++ b/youtube-dl-gui/Updater/UpdateChecker.cs
@@ -4,7 +4,7 @@
using System.Net;
using System.Threading;
using System.Windows.Forms;
-using youtube_dl_gui.updater;
+using murrty.updater;
namespace youtube_dl_gui {
internal class UpdateChecker {
diff --git a/youtube-dl-gui/Updater/Version.cs b/youtube-dl-gui/Updater/Version.cs
index aa0a00c3..60ac28bc 100644
--- a/youtube-dl-gui/Updater/Version.cs
+++ b/youtube-dl-gui/Updater/Version.cs
@@ -1,13 +1,14 @@
-namespace youtube_dl_gui.updater;
+namespace murrty.updater;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
+using youtube_dl_gui;
///
-/// Represents a modified Version.
+/// Represents a Version structure that can only be read from.
///
[System.Diagnostics.DebuggerStepThrough]
-[StructLayout(LayoutKind.Sequential)]
+[StructLayout(LayoutKind.Sequential), Serializable]
public struct Version {
///
/// Contains an empty Version with no version information relevant.
@@ -18,24 +19,55 @@ public struct Version {
///
/// The major of the version.
///
- public byte Major { get; init; }
+ public byte Major {
+ get; init;
+ }
///
/// The minor of the version.
///
- public byte Minor { get; init; }
+ public byte Minor {
+ get; init;
+ }
///
/// The revision of the version.
///
- public byte Revision { get; init; }
+ public byte Revision {
+ get; init;
+ }
///
/// The beta number of the version.
///
- public byte Beta { get; init; }
+ public byte Beta {
+ get; init;
+ }
///
/// Whether the version is a beta version.
///
- public bool IsBeta => Beta != 0;
+ public bool IsBeta {
+ get => Beta > 0;
+ }
+ ///
+ /// Initializes a new structure for defining the current application version.
+ ///
+ /// The major version of the release.
+ public Version(byte Major) {
+ this.Major = Major;
+ this.Minor = 0;
+ this.Revision = 0;
+ Beta = 0;
+ }
+ ///
+ /// Initializes a new structure for defining the current application version.
+ ///
+ /// The major version of the release.
+ /// The minor version of the release.
+ public Version(byte Major, byte Minor) {
+ this.Major = Major;
+ this.Minor = Minor;
+ this.Revision = 0;
+ Beta = 0;
+ }
///
/// Initializes a new structure for defining the current application version.
///
@@ -78,13 +110,21 @@ public Version(string Data) {
}
///
- /// Converts a string representation of the to a structure with the data.
+ /// Parses a string value to a structure representing the data.
///
/// The string data to convert.
/// A new structure filled with relevant information.
///
- public static Version ToVersion(string Data) =>
- TryParse(Data, out Version vers) ? vers : throw new ArgumentException($"Data {Data} is not a valid version to parse.");
+ ///
+ public static Version Parse(string Data) {
+ try {
+ return InternalParse(Data, out Version ver) ? ver : throw new ArgumentException($"Data {Data} is not a valid version to parse.");
+ }
+ catch {
+ throw;
+ }
+ }
+
///
/// Tries to parsre a string value to a structure representing the data.
///
@@ -100,13 +140,25 @@ public static bool TryParse(string Data, out Version vers) {
return false;
}
}
+
+ ///
+ /// Internal method for parsing a string value.
+ ///
+ /// The string representation of the version.
+ /// The out version struct that will be given if successful.
+ /// if the version was parsed successfully; otherwise, .
+ ///
+ ///
private static bool InternalParse(string Data, out Version vers) {
+#pragma warning disable IDE0018 // Inline variable declaration
+#pragma warning disable IDE0059 // Inline variable declaration
if (Data.IsNullEmptyWhitespace()) {
vers = Empty;
return false;
}
- if (Regex.IsMatch(Data, @"^[\d]{1,3}((.[\d]{1,3}){1,2})?(-[\d]{1,3})?$", RegexOptions.Compiled)) {
+ if (Regex.IsMatch(Data, @"^\d{1,3}((.\d{1,3}){1,2})?(-\d{1,3})?$", RegexOptions.Compiled)) {
+ byte Major = 0;
byte Minor = 0;
byte Revision = 0;
byte Beta = 0;
@@ -120,44 +172,39 @@ private static bool InternalParse(string Data, out Version vers) {
string[] Splits = Data.Split('.');
switch (Splits.Length) {
- case 1 when byte.TryParse(Splits[0], out byte Major): {
+ case 1 when byte.TryParse(Splits[0], out Major): {
vers = new(Major, Minor, Revision, Beta);
- }
- return true;
+ } return true;
case 1: {
- }
- throw new InvalidCastException($"Cannot use {Splits[0]} as the major.");
+ } throw new InvalidCastException($"Cannot use {Splits[0]} as the major.");
- case 2 when byte.TryParse(Splits[0], out byte Major) && byte.TryParse(Splits[1], out Minor): {
+ case 2 when byte.TryParse(Splits[0], out Major) && byte.TryParse(Splits[1], out Minor): {
vers = new(Major, Minor, Revision, Beta);
- }
- return true;
+ } return true;
case 2: {
- }
- throw new InvalidCastException($"Cannot use {Splits[1]} as the minor.");
+ } throw new InvalidCastException($"Cannot use {Splits[1]} as the minor.");
- case 3 when byte.TryParse(Splits[0], out byte Major) && byte.TryParse(Splits[1], out Minor) && byte.TryParse(Splits[2], out Revision): {
+ case 3 when byte.TryParse(Splits[0], out Major) && byte.TryParse(Splits[1], out Minor) && byte.TryParse(Splits[2], out Revision): {
vers = new(Major, Minor, Revision, Beta);
- }
- return true;
+ } return true;
case 3: {
- }
- throw new InvalidCastException($"Cannot use {Splits[2]} as the revision.");
+ } throw new InvalidCastException($"Cannot use {Splits[2]} as the revision.");
default: {
- }
- throw new ArgumentException($"Cannot use {Data} as a version.");
+ } throw new ArgumentException($"Cannot use {Data} as a version.");
}
}
vers = Empty;
return false;
+#pragma warning restore IDE0018 // Inline variable declaration
+#pragma warning restore IDE0059 // Inline variable declaration
}
///
- public override string ToString() => $"{Major}.{Minor}.{Revision}{(IsBeta ? $"-{Beta}" : "")}";
+ public override string ToString() => IsBeta ? $"{Major}.{Minor}.{Revision}-{Beta}" : $"{Major}.{Minor}.{Revision}";
///
public override bool Equals(object obj) =>
@@ -173,6 +220,24 @@ public override int GetHashCode() {
return hashCode;
}
+ ///
+ /// Determines if the two versions compared are equal to each other.
+ ///
+ ///
+ ///
+ /// if the versions are equal; otherwise, .
+ public static bool operator ==(Version versa, Version versb) =>
+ versa.Major == versb.Major && versa.Minor == versb.Minor && versa.Revision == versb.Revision && versa.Beta == versb.Beta;
+
+ ///
+ /// Determines if the two versions compared are not equal to each other.
+ ///
+ ///
+ ///
+ /// if the versions are different; otherwise, .
+ public static bool operator !=(Version versa, Version versb) =>
+ versa.Major != versb.Major || versa.Minor != versb.Minor || versa.Revision != versb.Revision || versa.Beta != versb.Beta;
+
///
/// Determines if the left version is older-than the right version.
///
@@ -306,22 +371,4 @@ public override int GetHashCode() {
public static bool operator >=(Version versa, Version versb) {
return versa == versb || versa >= versb;
}
-
- ///
- /// Determines if the two versions compared are equal to each other.
- ///
- ///
- ///
- /// if the versions are equal; otherwise, .
- public static bool operator ==(Version versa, Version versb) =>
- versa.Major == versb.Major && versa.Minor == versb.Minor && versa.Revision == versb.Revision && versa.Beta == versb.Beta;
-
- ///
- /// Determines if the two versions compared are not equal to each other.
- ///
- ///
- ///
- /// if the versions are different; otherwise, .
- public static bool operator !=(Version versa, Version versb) =>
- versa.Major != versb.Major || versa.Minor != versb.Minor || versa.Revision != versb.Revision || versa.Beta != versb.Beta;
}
\ No newline at end of file
diff --git a/youtube-dl-gui/youtube-dl-gui.csproj b/youtube-dl-gui/youtube-dl-gui.csproj
index 18f911b7..86b53378 100644
--- a/youtube-dl-gui/youtube-dl-gui.csproj
+++ b/youtube-dl-gui/youtube-dl-gui.csproj
@@ -96,6 +96,8 @@
Controls\Shared\Events\RegexMatchEventArgs.cs
+
+
Component