mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Added $select:domain1|domain2$ syntax to custom uploader parser
This commit is contained in:
parent
8e059e2115
commit
472f885b41
5 changed files with 325 additions and 12 deletions
70
ShareX.UploadersLib/Forms/ParserSelectForm.Designer.cs
generated
Normal file
70
ShareX.UploadersLib/Forms/ParserSelectForm.Designer.cs
generated
Normal file
|
@ -0,0 +1,70 @@
|
|||
namespace ShareX.UploadersLib
|
||||
{
|
||||
partial class ParserSelectForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
91
ShareX.UploadersLib/Forms/ParserSelectForm.cs
Normal file
91
ShareX.UploadersLib/Forms/ParserSelectForm.cs
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
120
ShareX.UploadersLib/Forms/ParserSelectForm.resx
Normal file
120
ShareX.UploadersLib/Forms/ParserSelectForm.resx
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -164,6 +164,12 @@
|
|||
<Compile Include="Forms\OCRSpaceForm.Designer.cs">
|
||||
<DependentUpon>OCRSpaceForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ParserSelectForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ParserSelectForm.Designer.cs">
|
||||
<DependentUpon>ParserSelectForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\PuushLoginForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -620,6 +626,9 @@
|
|||
<EmbeddedResource Include="Forms\OCRSpaceForm.zh-CN.resx">
|
||||
<DependentUpon>OCRSpaceForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\ParserSelectForm.resx">
|
||||
<DependentUpon>ParserSelectForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\PuushLoginForm.es-MX.resx">
|
||||
<DependentUpon>PuushLoginForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
Loading…
Reference in a new issue