From 7860feeaa4adeae516552a3323cd72012bf844ce Mon Sep 17 00:00:00 2001 From: "Go Johansson (neku)" Date: Sun, 30 Jan 2022 01:06:33 +0100 Subject: [PATCH 1/6] Update Uguu.cs --- ShareX.UploadersLib/FileUploaders/Uguu.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/ShareX.UploadersLib/FileUploaders/Uguu.cs b/ShareX.UploadersLib/FileUploaders/Uguu.cs index 1c2569f9c..3435c0d84 100644 --- a/ShareX.UploadersLib/FileUploaders/Uguu.cs +++ b/ShareX.UploadersLib/FileUploaders/Uguu.cs @@ -42,23 +42,11 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer public class Uguu : FileUploader { - public bool RandomName { get; set; } - public string CustomName { get; set; } public override UploadResult Upload(Stream stream, string fileName) { - Dictionary arguments = new Dictionary(); - - if (RandomName) - { - arguments.Add("randomname", "on"); - } - else if (!string.IsNullOrEmpty(CustomName)) - { - arguments.Add("name", CustomName); - } - - UploadResult result = SendRequestFile("https://uguu.se/api.php?d=upload-tool", stream, fileName, "file", arguments); + + UploadResult result = SendRequestFile("https://uguu.se/upload.php?output=text", stream, fileName, "files[]"); if (result.IsSuccess) { @@ -68,4 +56,4 @@ public override UploadResult Upload(Stream stream, string fileName) return result; } } -} \ No newline at end of file +} From 4a132700f2d6cab0aac3c1ea27be985748b54d20 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 30 Jan 2022 03:37:24 +0300 Subject: [PATCH 2/6] Remove empty lines --- ShareX.UploadersLib/FileUploaders/Uguu.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ShareX.UploadersLib/FileUploaders/Uguu.cs b/ShareX.UploadersLib/FileUploaders/Uguu.cs index 3435c0d84..13a5a9255 100644 --- a/ShareX.UploadersLib/FileUploaders/Uguu.cs +++ b/ShareX.UploadersLib/FileUploaders/Uguu.cs @@ -23,7 +23,6 @@ #endregion License Information (GPL v3) -using System.Collections.Generic; using System.IO; namespace ShareX.UploadersLib.FileUploaders @@ -42,10 +41,8 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer public class Uguu : FileUploader { - public override UploadResult Upload(Stream stream, string fileName) { - UploadResult result = SendRequestFile("https://uguu.se/upload.php?output=text", stream, fileName, "files[]"); if (result.IsSuccess) @@ -56,4 +53,4 @@ public override UploadResult Upload(Stream stream, string fileName) return result; } } -} +} \ No newline at end of file From 081a65edc92bd896435303d989cc22fdbc869f3d Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 30 Jan 2022 04:31:07 +0300 Subject: [PATCH 3/6] fixed #6057: Support FFmpeg 5.0 --- ShareX.MediaLib/FFmpegCLIManager.cs | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/ShareX.MediaLib/FFmpegCLIManager.cs b/ShareX.MediaLib/FFmpegCLIManager.cs index ff352274b..c4ce20cbf 100644 --- a/ShareX.MediaLib/FFmpegCLIManager.cs +++ b/ShareX.MediaLib/FFmpegCLIManager.cs @@ -230,20 +230,19 @@ public DirectShowDevices GetDirectShowDevices() string output = Output.ToString(); string[] lines = output.Lines(); - bool isVideo = true; - Regex regex = new Regex(@"\[dshow @ \w+\] ""(.+)""", RegexOptions.Compiled | RegexOptions.CultureInvariant); + bool isAudio = false; + Regex regex = new Regex(@"\[dshow @ \w+\] +""(.+)""", RegexOptions.Compiled | RegexOptions.CultureInvariant); foreach (string line in lines) { - if (line.Contains("] DirectShow video devices", StringComparison.InvariantCulture)) + if (line.Contains("] DirectShow video devices")) { - isVideo = true; + isAudio = false; continue; } - - if (line.Contains("] DirectShow audio devices", StringComparison.InvariantCulture)) + else if (line.Contains("] DirectShow audio devices")) { - isVideo = false; + isAudio = true; continue; } @@ -251,15 +250,24 @@ public DirectShowDevices GetDirectShowDevices() if (match.Success) { - string value = match.Groups[1].Value; - - if (isVideo) + if (line.EndsWith("\" (video)")) { - devices.VideoDevices.Add(value); + isAudio = false; + } + else if (line.EndsWith("\" (audio)")) + { + isAudio = true; + } + + string deviceName = match.Groups[1].Value; + + if (isAudio) + { + devices.AudioDevices.Add(deviceName); } else { - devices.AudioDevices.Add(value); + devices.VideoDevices.Add(deviceName); } } } From 8f5799c4cfacfecab811f3d73ae75690124488b4 Mon Sep 17 00:00:00 2001 From: L1Q <0xL1Q@ex.ua> Date: Sun, 30 Jan 2022 04:40:04 +0200 Subject: [PATCH 4/6] Add "FPS Limit" line to resx --- ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs | 9 +++++++++ ShareX.ScreenCaptureLib/Properties/Resources.resx | 3 +++ ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs index 205054b6e..fb526b8ea 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs +++ b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs @@ -629,6 +629,15 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to FPS limit:. + /// + internal static string FPSLimit { + get { + return ResourceManager.GetString("FPSLimit", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.resx b/ShareX.ScreenCaptureLib/Properties/Resources.resx index 98cf4babb..1eb46074b 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.resx +++ b/ShareX.ScreenCaptureLib/Properties/Resources.resx @@ -792,4 +792,7 @@ X: {4} Y: {5} Auto copy image to clipboard + + FPS limit: + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index 41aa84802..c0acd4c39 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -989,8 +989,7 @@ internal void CreateToolbar() }; tsddbOptions.DropDownItems.Add(tsmiShowFPS); - // TODO: Translate - ToolStripLabeledNumericUpDown tslnudFPSLimit = new ToolStripLabeledNumericUpDown("FPS limit:"); + ToolStripLabeledNumericUpDown tslnudFPSLimit = new ToolStripLabeledNumericUpDown(Resources.FPSLimit); tslnudFPSLimit.Content.Minimum = 0; tslnudFPSLimit.Content.Maximum = 300; tslnudFPSLimit.Content.Value = Options.FPSLimit; From 6559bb51940da1dcc858e19a4b4da1fde548436d Mon Sep 17 00:00:00 2001 From: L1Q <0xL1Q@ex.ua> Date: Sun, 30 Jan 2022 04:40:52 +0200 Subject: [PATCH 5/6] Update Russian translation --- ShareX.HistoryLib/Forms/HistoryForm.ru.resx | 3 +++ ShareX.ScreenCaptureLib/Forms/CanvasSizeForm.ru.resx | 3 +++ ShareX.ScreenCaptureLib/Properties/Resources.ru.resx | 3 +++ ShareX/Forms/TaskSettingsForm.ru.resx | 6 ++++++ ShareX/Properties/Resources.ru.resx | 7 +++++-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.ru.resx b/ShareX.HistoryLib/Forms/HistoryForm.ru.resx index fa5624cd5..75772df68 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.ru.resx +++ b/ShareX.HistoryLib/Forms/HistoryForm.ru.resx @@ -177,4 +177,7 @@ Показать статистику... + + Закрыть + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/CanvasSizeForm.ru.resx b/ShareX.ScreenCaptureLib/Forms/CanvasSizeForm.ru.resx index 080a8d66f..668335734 100644 --- a/ShareX.ScreenCaptureLib/Forms/CanvasSizeForm.ru.resx +++ b/ShareX.ScreenCaptureLib/Forms/CanvasSizeForm.ru.resx @@ -138,4 +138,7 @@ Отменить + + Цвет полотна... + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.ru.resx b/ShareX.ScreenCaptureLib/Properties/Resources.ru.resx index bcba13231..7155cf879 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.ru.resx +++ b/ShareX.ScreenCaptureLib/Properties/Resources.ru.resx @@ -478,4 +478,7 @@ Автоматически копировать изображение в буфер обмена + + Лимит FPS: + \ No newline at end of file diff --git a/ShareX/Forms/TaskSettingsForm.ru.resx b/ShareX/Forms/TaskSettingsForm.ru.resx index 5d0f27a57..8e8c83b12 100644 --- a/ShareX/Forms/TaskSettingsForm.ru.resx +++ b/ShareX/Forms/TaskSettingsForm.ru.resx @@ -633,4 +633,10 @@ Заменить URL результата через регулярные выражения + + Лимит FPS: + + + Автоматически прятать при захвате экрана + \ No newline at end of file diff --git a/ShareX/Properties/Resources.ru.resx b/ShareX/Properties/Resources.ru.resx index bcf62eddd..82b474e8c 100644 --- a/ShareX/Properties/Resources.ru.resx +++ b/ShareX/Properties/Resources.ru.resx @@ -561,8 +561,8 @@ ShareX свернут в системный трей. - - Ваш анитвирус или контролируемый доступ к файлам в Windows 10 могут блокировать ShareX. + + Ваш анитвирус или контролируемый доступ к файлам в Windows могут блокировать ShareX. Не удалось сохранить настройки @@ -646,4 +646,7 @@ Ваш системный администратор отключил возможность загрузки. + + Не удалось сохранить изображение по пути: + \ No newline at end of file From bb091fee198899cdceb234d0785c3b06617190a4 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 30 Jan 2022 12:42:18 +0300 Subject: [PATCH 6/6] Adding new custom uploader parser --- .../CustomUploader/CustomUploaderParser2.cs | 134 ++++++++++++++++++ .../Functions/CustomUploaderFunction.cs | 34 +++++ .../Functions/CustomUploaderFunctionBase64.cs | 46 ++++++ .../CustomUploaderFunctionFileName.cs | 44 ++++++ .../Functions/CustomUploaderFunctionHeader.cs | 44 ++++++ .../Functions/CustomUploaderFunctionInput.cs | 44 ++++++ .../Functions/CustomUploaderFunctionJson.cs | 51 +++++++ .../Functions/CustomUploaderFunctionPrompt.cs | 60 ++++++++ .../Functions/CustomUploaderFunctionRandom.cs | 44 ++++++ .../Functions/CustomUploaderFunctionRegex.cs | 64 +++++++++ .../CustomUploaderFunctionResponse.cs | 37 +++++ .../CustomUploaderFunctionResponseURL.cs | 37 +++++ .../Functions/CustomUploaderFunctionSelect.cs | 50 +++++++ .../Functions/CustomUploaderFunctionXml.cs | 57 ++++++++ .../ShareX.UploadersLib.csproj | 14 ++ 15 files changed, 760 insertions(+) create mode 100644 ShareX.UploadersLib/CustomUploader/CustomUploaderParser2.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunction.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionBase64.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionFileName.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionHeader.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionInput.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionPrompt.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRandom.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRegex.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponse.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponseURL.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionSelect.cs create mode 100644 ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionXml.cs diff --git a/ShareX.UploadersLib/CustomUploader/CustomUploaderParser2.cs b/ShareX.UploadersLib/CustomUploader/CustomUploaderParser2.cs new file mode 100644 index 000000000..428ef7be1 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/CustomUploaderParser2.cs @@ -0,0 +1,134 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ShareX.UploadersLib +{ + public class CustomUploaderParser2 + { + private static IEnumerable Functions = Helpers.GetInstances(); + + public char SyntaxStart { get; private set; } = '{'; + public char SyntaxEnd { get; private set; } = '}'; + public char SyntaxParameterStart { get; private set; } = ':'; + public char SyntaxParameterDelimiter { get; private set; } = '|'; + public char SyntaxEscape { get; private set; } = '\\'; + + public string FileName { get; set; } + public string Input { get; set; } + public ResponseInfo ResponseInfo { get; set; } + public List RegexList { get; set; } + public bool URLEncode { get; set; } // Only URL encodes file name and input + + public string Parse(string text) + { + return ParseSyntax(text, 0, out _); + } + + private string ParseSyntax(string text, int startPosition, out int endPosition) + { + endPosition = startPosition; + + if (string.IsNullOrEmpty(text)) + { + return ""; + } + + StringBuilder sbResult = new StringBuilder(); + bool escape = false; + + for (int i = startPosition; i < text.Length; i++) + { + if (!escape) + { + if (text[i] == SyntaxStart) + { + string parsed = ParseSyntax(text, i + 1, out i); + parsed = ParseFunction(parsed); + sbResult.Append(parsed); + continue; + } + else if (text[i] == SyntaxEnd) + { + endPosition = i; + return sbResult.ToString(); + } + else if (text[i] == SyntaxEscape) + { + escape = true; + continue; + } + } + else + { + escape = false; + } + + sbResult.Append(text[i]); + } + + return sbResult.ToString(); + } + + private string ParseFunction(string text) + { + string functionName; + string[] parameterArray = null; + + int parameterPosition = text.IndexOf(SyntaxParameterStart); + + if (parameterPosition >= 0) + { + functionName = text.Remove(parameterPosition); + string parameters = text.Substring(parameterPosition + 1); + // TODO: Support delimiter escape + parameterArray = parameters.Split(SyntaxParameterDelimiter); + } + else + { + functionName = text; + } + + return CallFunction(functionName, parameterArray); + } + + private string CallFunction(string functionName, string[] parameters) + { + foreach (CustomUploaderFunction function in Functions) + { + if (function.Name.Equals(functionName, StringComparison.InvariantCultureIgnoreCase)) + { + return function.Call(this, parameters); + } + } + + throw new Exception("Invalid function name: " + functionName); + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunction.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunction.cs new file mode 100644 index 000000000..f28e3ea18 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunction.cs @@ -0,0 +1,34 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX.UploadersLib +{ + internal abstract class CustomUploaderFunction + { + public abstract string Name { get; } + + public abstract string Call(CustomUploaderParser2 parser, string[] parameters); + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionBase64.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionBase64.cs new file mode 100644 index 000000000..b1ad181dd --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionBase64.cs @@ -0,0 +1,46 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionBase64 : CustomUploaderFunction + { + public override string Name { get; } = "base64"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string text = parameters[0]; + + if (!string.IsNullOrEmpty(text)) + { + return TranslatorHelper.TextToBase64(text); + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionFileName.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionFileName.cs new file mode 100644 index 000000000..209b84c20 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionFileName.cs @@ -0,0 +1,44 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionFileName : CustomUploaderFunction + { + public override string Name { get; } = "filename"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + if (parser.URLEncode) + { + return URLHelpers.URLEncode(parser.FileName); + } + + return parser.FileName; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionHeader.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionHeader.cs new file mode 100644 index 000000000..2641f7dfd --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionHeader.cs @@ -0,0 +1,44 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionHeader : CustomUploaderFunction + { + public override string Name { get; } = "header"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string header = parameters[0]; + + if (parser.ResponseInfo.Headers != null) + { + return parser.ResponseInfo.Headers[header]; + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionInput.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionInput.cs new file mode 100644 index 000000000..b225f4f2f --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionInput.cs @@ -0,0 +1,44 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionInput : CustomUploaderFunction + { + public override string Name { get; } = "input"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + if (parser.URLEncode) + { + return URLHelpers.URLEncode(parser.Input); + } + + return parser.Input; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs new file mode 100644 index 000000000..4d5bb2b88 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionJson.cs @@ -0,0 +1,51 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using Newtonsoft.Json.Linq; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionJson : CustomUploaderFunction + { + public override string Name { get; } = "json"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string jsonPath = parameters[0]; + + if (!string.IsNullOrEmpty(jsonPath)) + { + if (!jsonPath.StartsWith("$.")) + { + jsonPath = "$." + jsonPath; + } + + return (string)JToken.Parse(parser.ResponseInfo.ResponseText).SelectToken(jsonPath); + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionPrompt.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionPrompt.cs new file mode 100644 index 000000000..fc01ea74f --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionPrompt.cs @@ -0,0 +1,60 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System.Windows.Forms; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionPrompt : CustomUploaderFunction + { + public override string Name { get; } = "prompt"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string title = "ShareX - Prompt", defaultValue = ""; + + if (parameters.Length > 0) + { + title = parameters[0]; + + if (parameters.Length > 1) + { + defaultValue = parameters[1]; + } + } + + using (InputBox inputBox = new InputBox(title, defaultValue)) + { + if (inputBox.ShowDialog() == DialogResult.OK) + { + return inputBox.InputText; + } + } + + return defaultValue; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRandom.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRandom.cs new file mode 100644 index 000000000..613ac33b2 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRandom.cs @@ -0,0 +1,44 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionRandom : CustomUploaderFunction + { + public override string Name { get; } = "random"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + if (parameters.Length > 0) + { + return RandomFast.Pick(parameters); + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRegex.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRegex.cs new file mode 100644 index 000000000..f79f998a5 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionRegex.cs @@ -0,0 +1,64 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System.Text.RegularExpressions; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionRegex : CustomUploaderFunction + { + public override string Name { get; } = "regex"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + if (parameters.Length > 0) + { + string regexIndex = parameters[0]; + + if (!string.IsNullOrEmpty(regexIndex) && int.TryParse(regexIndex, out int regexIndexNumber)) + { + string pattern = parser.RegexList[regexIndexNumber - 1]; + Match match = Regex.Match(parser.ResponseInfo.ResponseText, pattern); + + if (parameters.Length > 1) + { + string regexGroup = parameters[1]; + + if (!string.IsNullOrEmpty(regexGroup) && int.TryParse(regexGroup, out int regexGroupNumber)) + { + return match.Groups[regexGroupNumber].Value; + } + + return match.Groups[regexGroup].Value; + } + + return match.Value; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponse.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponse.cs new file mode 100644 index 000000000..fc1e69145 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponse.cs @@ -0,0 +1,37 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionResponse : CustomUploaderFunction + { + public override string Name { get; } = "response"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + return parser.ResponseInfo.ResponseText; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponseURL.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponseURL.cs new file mode 100644 index 000000000..7154c173c --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionResponseURL.cs @@ -0,0 +1,37 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionResponseURL : CustomUploaderFunction + { + public override string Name { get; } = "responseurl"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + return parser.ResponseInfo.ResponseURL; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionSelect.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionSelect.cs new file mode 100644 index 000000000..6c2f41537 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionSelect.cs @@ -0,0 +1,50 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System.Linq; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionSelect : CustomUploaderFunction + { + public override string Name { get; } = "select"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string[] values = parameters.Where(x => !string.IsNullOrEmpty(x)).ToArray(); + + if (values.Length > 0) + { + using (ParserSelectForm form = new ParserSelectForm(values)) + { + form.ShowDialog(); + return form.SelectedText; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionXml.cs b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionXml.cs new file mode 100644 index 000000000..ee4be53c1 --- /dev/null +++ b/ShareX.UploadersLib/CustomUploader/Functions/CustomUploaderFunctionXml.cs @@ -0,0 +1,57 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2022 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System.IO; +using System.Xml.XPath; + +namespace ShareX.UploadersLib +{ + internal class CustomUploaderFunctionXml : CustomUploaderFunction + { + public override string Name { get; } = "xml"; + + public override string Call(CustomUploaderParser2 parser, string[] parameters) + { + string xpath = parameters[0]; + + if (!string.IsNullOrEmpty(xpath)) + { + using (StringReader sr = new StringReader(parser.ResponseInfo.ResponseText)) + { + XPathDocument doc = new XPathDocument(sr); + XPathNavigator nav = doc.CreateNavigator(); + XPathNavigator node = nav.SelectSingleNode(xpath); + + if (node != null) + { + return node.Value; + } + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/ShareX.UploadersLib.csproj b/ShareX.UploadersLib/ShareX.UploadersLib.csproj index c93b36a68..cad20416c 100644 --- a/ShareX.UploadersLib/ShareX.UploadersLib.csproj +++ b/ShareX.UploadersLib/ShareX.UploadersLib.csproj @@ -125,6 +125,20 @@ + + + + + + + + + + + + + +