diff --git a/ShareX.UploadersLib/Forms/ParserSelectForm.Designer.cs b/ShareX.UploadersLib/Forms/ParserSelectForm.Designer.cs new file mode 100644 index 000000000..8a99431d1 --- /dev/null +++ b/ShareX.UploadersLib/Forms/ParserSelectForm.Designer.cs @@ -0,0 +1,70 @@ +namespace ShareX.UploadersLib +{ + partial class ParserSelectForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.flpMain = new System.Windows.Forms.FlowLayoutPanel(); + this.SuspendLayout(); + // + // flpMain + // + this.flpMain.AutoSize = true; + this.flpMain.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flpMain.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flpMain.Location = new System.Drawing.Point(0, 0); + this.flpMain.Name = "flpMain"; + this.flpMain.Size = new System.Drawing.Size(0, 0); + this.flpMain.TabIndex = 0; + // + // ParserSelectForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.ClientSize = new System.Drawing.Size(469, 400); + this.Controls.Add(this.flpMain); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(200, 50); + this.Name = "ParserSelectForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "ShareX - Select"; + this.TopMost = true; + this.Shown += new System.EventHandler(this.ParserSelectForm_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel flpMain; + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/Forms/ParserSelectForm.cs b/ShareX.UploadersLib/Forms/ParserSelectForm.cs new file mode 100644 index 000000000..4342f576f --- /dev/null +++ b/ShareX.UploadersLib/Forms/ParserSelectForm.cs @@ -0,0 +1,91 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2018 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.Drawing; +using System.Windows.Forms; + +namespace ShareX.UploadersLib +{ + public partial class ParserSelectForm : Form + { + public string[] Texts { get; private set; } + public string SelectedText { get; private set; } + + public ParserSelectForm(string[] texts) + { + InitializeComponent(); + Icon = ShareXResources.Icon; + + Texts = texts; + SelectedText = Texts[0]; + + SuspendLayout(); + + int maxButtonWidth = 0; + int rowSize = 10; + + for (int i = 0; i < Texts.Length; i++) + { + string text = Texts[i]; + + if (!string.IsNullOrEmpty(text)) + { + Button button = new Button() + { + AutoSize = true, + Margin = new Padding(i < rowSize ? 5 : 0, i % rowSize == 0 ? 5 : 0, 5, 5), + Padding = new Padding(5), + Font = new Font(Font.FontFamily, 12), + Text = text + }; + + button.Click += (sender, e) => + { + SelectedText = text; + Close(); + }; + + flpMain.Controls.Add(button); + if ((i + 1) % rowSize == 0) flpMain.SetFlowBreak(button, true); + maxButtonWidth = Math.Max(button.Width, maxButtonWidth); + } + } + + foreach (Control control in flpMain.Controls) + { + control.Width = maxButtonWidth; + } + + ResumeLayout(); + } + + private void ParserSelectForm_Shown(object sender, EventArgs e) + { + this.ForceActivate(); + } + } +} \ No newline at end of file diff --git a/ShareX.UploadersLib/Forms/ParserSelectForm.resx b/ShareX.UploadersLib/Forms/ParserSelectForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ShareX.UploadersLib/Forms/ParserSelectForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShareX.UploadersLib/Helpers/CustomUploaderParser.cs b/ShareX.UploadersLib/Helpers/CustomUploaderParser.cs index 2f58fcaae..a885370d4 100644 --- a/ShareX.UploadersLib/Helpers/CustomUploaderParser.cs +++ b/ShareX.UploadersLib/Helpers/CustomUploaderParser.cs @@ -28,6 +28,7 @@ You should have received a copy of the GNU General Public License using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Xml.XPath; @@ -131,32 +132,36 @@ private string ParseSyntax(string syntax) } else if (syntax.StartsWith("regex:", StringComparison.InvariantCultureIgnoreCase)) // Example: $regex:1|1$ { - return ParseRegexSyntax(syntax.Substring(6)); + return ParseSyntaxRegex(syntax.Substring(6)); } else if (syntax.StartsWith("json:", StringComparison.InvariantCultureIgnoreCase)) // Example: $json:Files[0].URL$ { - return ParseJsonSyntax(syntax.Substring(5)); + return ParseSyntaxJson(syntax.Substring(5)); } else if (syntax.StartsWith("xml:", StringComparison.InvariantCultureIgnoreCase)) // Example: $xml:/Files/File[1]/URL$ { - return ParseXmlSyntax(syntax.Substring(4)); + return ParseSyntaxXml(syntax.Substring(4)); } } if (syntax.StartsWith("random:", StringComparison.InvariantCultureIgnoreCase)) // Example: $random:domain1.com|domain2.com$ { - return ParseRandomSyntax(syntax.Substring(7)); + return ParseSyntaxRandom(syntax.Substring(7)); + } + else if (syntax.StartsWith("select:", StringComparison.InvariantCultureIgnoreCase)) // Example: $select:domain1.com|domain2.com$ + { + return ParseSyntaxSelect(syntax.Substring(7)); } + // Invalid syntax return null; } - private string ParseRegexSyntax(string syntax) + private string ParseSyntaxRegex(string syntax) { if (!string.IsNullOrEmpty(syntax)) { string regexIndexString = ""; - int regexIndex; bool isGroupRegex = false; int i; @@ -177,16 +182,15 @@ private string ParseRegexSyntax(string syntax) } } - if (regexIndexString.Length > 0 && int.TryParse(regexIndexString, out regexIndex)) + if (regexIndexString.Length > 0 && int.TryParse(regexIndexString, out int regexIndex)) { Match match = RegexMatches[regexIndex - 1]; if (isGroupRegex && i + 1 < syntax.Length) { string group = syntax.Substring(i + 1); - int groupNumber; - if (int.TryParse(group, out groupNumber)) + if (int.TryParse(group, out int groupNumber)) { return match.Groups[groupNumber].Value; } @@ -202,7 +206,7 @@ private string ParseRegexSyntax(string syntax) } // http://goessner.net/articles/JsonPath/ - private string ParseJsonSyntax(string syntaxJsonPath) + private string ParseSyntaxJson(string syntaxJsonPath) { if (!string.IsNullOrEmpty(syntaxJsonPath)) { @@ -214,7 +218,7 @@ private string ParseJsonSyntax(string syntaxJsonPath) // http://www.w3schools.com/xsl/xpath_syntax.asp // https://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx - private string ParseXmlSyntax(string syntaxXPath) + private string ParseSyntaxXml(string syntaxXPath) { if (!string.IsNullOrEmpty(syntaxXPath)) { @@ -234,7 +238,7 @@ private string ParseXmlSyntax(string syntaxXPath) return null; } - private string ParseRandomSyntax(string syntax) + private string ParseSyntaxRandom(string syntax) { if (!string.IsNullOrEmpty(syntax)) { @@ -248,5 +252,24 @@ private string ParseRandomSyntax(string syntax) return null; } + + private string ParseSyntaxSelect(string syntax) + { + if (!string.IsNullOrEmpty(syntax)) + { + string[] values = syntax.Split(SyntaxParameterChar).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/ShareX.UploadersLib.csproj b/ShareX.UploadersLib/ShareX.UploadersLib.csproj index d3d92517b..98974a5fe 100644 --- a/ShareX.UploadersLib/ShareX.UploadersLib.csproj +++ b/ShareX.UploadersLib/ShareX.UploadersLib.csproj @@ -164,6 +164,12 @@ OCRSpaceForm.cs + + Form + + + ParserSelectForm.cs + Form @@ -620,6 +626,9 @@ OCRSpaceForm.cs + + ParserSelectForm.cs + PuushLoginForm.cs