From 9e808d0489aa368fe8a4bfc46a29d2515afd7e31 Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 2 Feb 2022 10:54:51 +0300 Subject: [PATCH] Automatically migrate old custom uploader syntax to new syntax --- ShareX.Setup/WindowsStore/AppxManifest.xml | 2 +- .../CustomUploader/CustomUploaderItem.cs | 66 +++++++++++++++++++ SharedAssemblyInfo.cs | 4 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/ShareX.Setup/WindowsStore/AppxManifest.xml b/ShareX.Setup/WindowsStore/AppxManifest.xml index 2e19cd96c..cb707ee53 100644 --- a/ShareX.Setup/WindowsStore/AppxManifest.xml +++ b/ShareX.Setup/WindowsStore/AppxManifest.xml @@ -1,6 +1,6 @@  - + ShareX ShareX Team diff --git a/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs b/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs index 4de2ac802..8b4a36dd3 100644 --- a/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs +++ b/ShareX.UploadersLib/CustomUploader/CustomUploaderItem.cs @@ -30,6 +30,8 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; +using System.Linq; +using System.Text; using System.Windows.Forms; namespace ShareX.UploadersLib @@ -409,10 +411,74 @@ public void CheckBackwardCompatibility() ResponseType = ResponseType.Text; + Version = "13.7.1"; + } + + if (Helpers.CompareVersion(Version, "13.7.1") <= 0) + { + RequestURL = MigrateOldSyntax(RequestURL); + + if (Parameters != null) + { + foreach (string key in Parameters.Keys.ToList()) + { + Parameters[key] = MigrateOldSyntax(Parameters[key]); + } + } + + if (Headers != null) + { + foreach (string key in Headers.Keys.ToList()) + { + Headers[key] = MigrateOldSyntax(Headers[key]); + } + } + + if (Arguments != null) + { + foreach (string key in Arguments.Keys.ToList()) + { + Arguments[key] = MigrateOldSyntax(Arguments[key]); + } + } + + Data = MigrateOldSyntax(Data); + URL = MigrateOldSyntax(URL); + ThumbnailURL = MigrateOldSyntax(ThumbnailURL); + DeletionURL = MigrateOldSyntax(DeletionURL); + ErrorMessage = MigrateOldSyntax(ErrorMessage); + Version = Application.ProductVersion; } } + private string MigrateOldSyntax(string input) + { + if (string.IsNullOrEmpty(input)) + { + return input; + } + + StringBuilder sbInput = new StringBuilder(input); + + bool start = true; + + for (int i = 0; i < input.Length; i++) + { + if (input[i] == '$') + { + sbInput[i] = start ? '{' : '}'; + start = !start; + } + else if (input[i] == '\\') + { + i++; + } + } + + return sbInput.ToString(); + } + private void CheckRequestURL() { if (!string.IsNullOrEmpty(RequestURL)) diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index eec3e5280..11692bb10 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -30,5 +30,5 @@ [assembly: AssemblyProduct("ShareX")] [assembly: AssemblyCopyright("Copyright (c) 2007-2022 ShareX Team")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("13.7.1")] -[assembly: AssemblyFileVersion("13.7.1")] \ No newline at end of file +[assembly: AssemblyVersion("13.7.2")] +[assembly: AssemblyFileVersion("13.7.2")] \ No newline at end of file