fixed #12: Added Export/Import custom uploader

This commit is contained in:
Jaex 2013-12-02 14:08:09 +02:00
parent 0790fbe035
commit bee7bf7454
5 changed files with 120 additions and 27 deletions

View file

@ -323,6 +323,7 @@ private void btnSettingsExport_Click(object sender, EventArgs e)
{
string json = ImageEffectManager.ExportEffects(imageEffects);
ClipboardHelpers.CopyText(json);
MessageBox.Show("Image effects copied to your clipboard.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

View file

@ -320,6 +320,8 @@ private void InitializeComponent()
this.txtRapidSharePremiumUserName = new System.Windows.Forms.TextBox();
this.ttHelpTip = new System.Windows.Forms.ToolTip(this.components);
this.actRapidShareAccountType = new UploadersLib.GUI.AccountTypeControl();
this.btnCustomUploaderExport = new System.Windows.Forms.Button();
this.btnCustomUploaderImport = new System.Windows.Forms.Button();
this.tcUploaders.SuspendLayout();
this.tpImageUploaders.SuspendLayout();
this.tcImageUploaders.SuspendLayout();
@ -3007,7 +3009,9 @@ private void InitializeComponent()
//
// gbCustomUploaders
//
this.gbCustomUploaders.Controls.Add(this.btnCustomUploaderImport);
this.gbCustomUploaders.Controls.Add(this.lbCustomUploaderList);
this.gbCustomUploaders.Controls.Add(this.btnCustomUploaderExport);
this.gbCustomUploaders.Controls.Add(this.btnCustomUploaderRemove);
this.gbCustomUploaders.Controls.Add(this.btnCustomUploaderClear);
this.gbCustomUploaders.Controls.Add(this.btnCustomUploaderUpdate);
@ -3046,7 +3050,7 @@ private void InitializeComponent()
this.btnCustomUploaderClear.Name = "btnCustomUploaderClear";
this.btnCustomUploaderClear.Size = new System.Drawing.Size(88, 24);
this.btnCustomUploaderClear.TabIndex = 5;
this.btnCustomUploaderClear.Text = "Clear fields ->";
this.btnCustomUploaderClear.Text = "Clear fields -->";
this.btnCustomUploaderClear.UseVisualStyleBackColor = true;
this.btnCustomUploaderClear.Click += new System.EventHandler(this.btnCustomUploaderClear_Click);
//
@ -3421,6 +3425,26 @@ private void InitializeComponent()
this.actRapidShareAccountType.Size = new System.Drawing.Size(214, 29);
this.actRapidShareAccountType.TabIndex = 16;
//
// btnCustomUploaderExport
//
this.btnCustomUploaderExport.Location = new System.Drawing.Point(8, 328);
this.btnCustomUploaderExport.Name = "btnCustomUploaderExport";
this.btnCustomUploaderExport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderExport.TabIndex = 34;
this.btnCustomUploaderExport.Text = "Export";
this.btnCustomUploaderExport.UseVisualStyleBackColor = true;
this.btnCustomUploaderExport.Click += new System.EventHandler(this.btnCustomUploaderExport_Click);
//
// btnCustomUploaderImport
//
this.btnCustomUploaderImport.Location = new System.Drawing.Point(80, 328);
this.btnCustomUploaderImport.Name = "btnCustomUploaderImport";
this.btnCustomUploaderImport.Size = new System.Drawing.Size(64, 23);
this.btnCustomUploaderImport.TabIndex = 35;
this.btnCustomUploaderImport.Text = "Import";
this.btnCustomUploaderImport.UseVisualStyleBackColor = true;
this.btnCustomUploaderImport.Click += new System.EventHandler(this.btnCustomUploaderImport_Click);
//
// UploadersConfigForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -3817,5 +3841,7 @@ private void InitializeComponent()
private GUI.AccountTypeControl atcMegaAccountType;
private System.Windows.Forms.Button btnMegaRegister;
private System.Windows.Forms.Button btnMegaRefreshFolders;
private System.Windows.Forms.Button btnCustomUploaderImport;
private System.Windows.Forms.Button btnCustomUploaderExport;
}
}

View file

@ -817,6 +817,16 @@ private void lbCustomUploaderList_SelectedIndexChanged(object sender, EventArgs
}
}
private void btnCustomUploaderExport_Click(object sender, EventArgs e)
{
ExportCustomUploader();
}
private void btnCustomUploaderImport_Click(object sender, EventArgs e)
{
ImportCustomUploader();
}
private void cbCustomUploaderRequestType_SelectedIndexChanged(object sender, EventArgs e)
{
txtCustomUploaderFileForm.Enabled = (CustomUploaderRequestType)cbCustomUploaderRequestType.SelectedIndex == CustomUploaderRequestType.POST;

View file

@ -117,6 +117,33 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ttHelpTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="label1.ToolTip" xml:space="preserve">
<value>If URL textbox is empty then 'Response text' or 'Redirection URL' will be automatically used.
Regex usage for get regex result: $n$
'n' must be index number from 'Regex from response' list.
Example for get second regex result from list: $2$
Regex groups usage: $n,n$ or $n,name$
Second 'n' here must be group number or group name.
Example: $3,1$ or $2,thumbnail_result$</value>
</data>
<data name="lblCustomUploaderRequestTypeHelp.ToolTip" xml:space="preserve">
<value>For image uploader &amp; file uploader: The 'POST' request type is required along with the 'File form name'.
For text uploader or url shortener: 'POST' with no 'File Form Name' or 'GET' will replace an argument with
value '%input' or '$input$' with the text or URL.
For text uploader: Specifying 'POST' request type and a 'File Form Name' will upload the input as a file
(useful for very long inputs).
For example, if the argument name is 'pastebin_text' then a value of '%input' will be automatically
replaced with the text you're going to upload. Same thing applies for url shortener; '%input'
will be replaced with the url in the argument.</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pbDropboxLogo.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@ -237,28 +264,4 @@
<metadata name="ttHelpTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="label1.ToolTip" xml:space="preserve">
<value>If URL textbox is empty then 'Response text' or 'Redirection URL' will be automatically used.
Regex usage for get regex result: $n$
'n' must be index number from 'Regex from response' list.
Example for get second regex result from list: $2$
Regex groups usage: $n,n$ or $n,name$
Second 'n' here must be group number or group name.
Example: $3,1$ or $2,thumbnail_result$</value>
</data>
<data name="lblCustomUploaderRequestTypeHelp.ToolTip" xml:space="preserve">
<value>For image uploader &amp; file uploader: The 'POST' request type is required along with the 'File form name'.
For text uploader or url shortener: 'POST' with no 'File Form Name' or 'GET' will replace an argument with
value '%input' or '$input$' with the text or URL.
For text uploader: Specifying 'POST' request type and a 'File Form Name' will upload the input as a file
(useful for very long inputs).
For example, if the argument name is 'pastebin_text' then a value of '%input' will be automatically
replaced with the text you're going to upload. Same thing applies for url shortener; '%input'
will be replaced with the url in the argument.</value>
</data>
</root>

View file

@ -24,6 +24,7 @@
#endregion License Information (GPL v3)
using HelpersLib;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -1183,11 +1184,11 @@ private void UpdateCustomUploader()
{
int index = lbCustomUploaderList.SelectedIndex;
if (index != -1)
if (index >= 0)
{
CustomUploaderItem customUploader = GetCustomUploaderFromFields();
if (!string.IsNullOrEmpty(customUploader.Name))
if (customUploader != null && !string.IsNullOrEmpty(customUploader.Name))
{
Config.CustomUploadersList[index] = customUploader;
lbCustomUploaderList.Items[index] = customUploader.Name;
@ -1196,6 +1197,58 @@ private void UpdateCustomUploader()
}
}
private void ExportCustomUploader()
{
int index = lbCustomUploaderList.SelectedIndex;
if (index >= 0)
{
CustomUploaderItem customUploader = GetCustomUploaderFromFields();
if (customUploader != null && !string.IsNullOrEmpty(customUploader.Name))
{
try
{
string json = JsonConvert.SerializeObject(customUploader, Formatting.Indented);
ClipboardHelpers.CopyText(json);
MessageBox.Show("Selected custom uploader copied to your clipboard.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
}
}
}
private void ImportCustomUploader()
{
if (Clipboard.ContainsText())
{
string json = Clipboard.GetText();
if (!string.IsNullOrEmpty(json))
{
try
{
CustomUploaderItem customUploader = JsonConvert.DeserializeObject<CustomUploaderItem>(json);
if (customUploader != null && !string.IsNullOrEmpty(customUploader.Name))
{
Config.CustomUploadersList.Add(customUploader);
lbCustomUploaderList.Items.Add(customUploader.Name);
lbCustomUploaderList.SelectedIndex = lbCustomUploaderList.Items.Count - 1;
PrepareCustomUploaderList();
}
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
}
}
}
private void CustomUploaderClear()
{
LoadCustomUploader(new CustomUploaderItem());