From e91fd94d2bfcecf276893fee1dd7d115939b6c0c Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 5 Mar 2023 22:16:45 +0300 Subject: [PATCH] Use GetApplicationVersion function --- ShareX.HelpersLib/Helpers/Helpers.cs | 15 +++++++++++++-- ShareX.HelpersLib/Settings/SettingsBase.cs | 5 ++--- ShareX.HelpersLib/ShareXResources.cs | 4 +--- .../CustomUploader/CustomUploaderItem.cs | 5 ++--- ShareX/Forms/ApplicationSettingsForm.cs | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index 80b792908..d8c9f7ba5 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -277,6 +277,17 @@ public static string GetProperName(string name, bool keepCase = false) return sb.ToString(); } + public static string GetApplicationVersion(bool includeRevision = false) + { + Version version = Version.Parse(Application.ProductVersion); + string result = $"{version.Major}.{version.Minor}.{version.Build}"; + if (includeRevision) + { + result = $"{result}.{version.Revision}"; + } + return result; + } + /// /// If version1 newer than version2 = 1 /// If version1 equal to version2 = 0 @@ -302,9 +313,9 @@ public static int CompareVersion(Version version1, Version version2) /// If version equal to ApplicationVersion = 0 /// If version older than ApplicationVersion = -1 /// - public static int CompareApplicationVersion(string version) + public static int CompareApplicationVersion(string version, bool includeRevision = false) { - return CompareVersion(version, Application.ProductVersion); + return CompareVersion(version, GetApplicationVersion(includeRevision)); } public static Version NormalizeVersion(string version) diff --git a/ShareX.HelpersLib/Settings/SettingsBase.cs b/ShareX.HelpersLib/Settings/SettingsBase.cs index bbe469d08..02c5b57dc 100644 --- a/ShareX.HelpersLib/Settings/SettingsBase.cs +++ b/ShareX.HelpersLib/Settings/SettingsBase.cs @@ -32,7 +32,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Windows.Forms; namespace ShareX.HelpersLib { @@ -86,7 +85,7 @@ protected virtual void OnSettingsSaveFailed(Exception e) public bool Save(string filePath) { FilePath = filePath; - ApplicationVersion = Application.ProductVersion; + ApplicationVersion = Helpers.GetApplicationVersion(); bool result = SaveInternal(FilePath); @@ -112,7 +111,7 @@ public void SaveAsync() public MemoryStream SaveToMemoryStream(bool supportDPAPIEncryption = false) { - ApplicationVersion = Application.ProductVersion; + ApplicationVersion = Helpers.GetApplicationVersion(); MemoryStream ms = new MemoryStream(); SaveToStream(ms, supportDPAPIEncryption, true); diff --git a/ShareX.HelpersLib/ShareXResources.cs b/ShareX.HelpersLib/ShareXResources.cs index 5a83f468b..aea26f042 100644 --- a/ShareX.HelpersLib/ShareXResources.cs +++ b/ShareX.HelpersLib/ShareXResources.cs @@ -24,7 +24,6 @@ #endregion License Information (GPL v3) using ShareX.HelpersLib.Properties; -using System; using System.ComponentModel; using System.Drawing; using System.Reflection; @@ -40,8 +39,7 @@ public static string UserAgent { get { - Version version = Version.Parse(Application.ProductVersion); - return $"{Name}/{version.Major}.{version.Minor}.{version.Build}"; + return $"{Name}/{Helpers.GetApplicationVersion()}"; } } diff --git a/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs b/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs index d75ab69a9..3bbdc8e98 100644 --- a/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs +++ b/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs @@ -32,7 +32,6 @@ using System.ComponentModel; using System.Linq; using System.Text; -using System.Windows.Forms; namespace ShareX.UploadersLib { @@ -111,7 +110,7 @@ public static CustomUploaderItem Init() { return new CustomUploaderItem() { - Version = Application.ProductVersion, + Version = Helpers.GetApplicationVersion(), RequestMethod = HttpMethod.POST, Body = CustomUploaderBody.MultipartFormData }; @@ -449,7 +448,7 @@ public void CheckBackwardCompatibility() DeletionURL = MigrateOldSyntax(DeletionURL); ErrorMessage = MigrateOldSyntax(ErrorMessage); - Version = Application.ProductVersion; + Version = Helpers.GetApplicationVersion(); } } diff --git a/ShareX/Forms/ApplicationSettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs index 5ef085808..fdeafce7b 100644 --- a/ShareX/Forms/ApplicationSettingsForm.cs +++ b/ShareX/Forms/ApplicationSettingsForm.cs @@ -745,7 +745,7 @@ private async void btnExport_Click(object sender, EventArgs e) using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.DefaultExt = "sxb"; - sfd.FileName = $"ShareX-{Application.ProductVersion}-backup.sxb"; + sfd.FileName = $"ShareX-{Helpers.GetApplicationVersion()}-backup.sxb"; sfd.Filter = "ShareX backup (*.sxb)|*.sxb|All files (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK)