URL upload changes

This commit is contained in:
Jaex 2014-05-07 19:26:14 +03:00
parent 8ddae5f03d
commit b2fdc2a9fd
10 changed files with 76 additions and 70 deletions

View file

@ -1124,27 +1124,5 @@ public static Image LoadImage(string filePath)
return null;
}
public static Image LoadRemoteImage(string url)
{
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream stream = httpWebReponse.GetResponseStream())
{
return Image.FromStream(stream);
}
}
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
return null;
}
}
}

View file

@ -99,7 +99,7 @@ public string GetLatestDownloadURL()
if (releases != null && releases.Count > 0)
{
return GetDownloadURL(releases[releases.Count - 1]);
return GetDownloadURL(releases[0]);
}
return null;

View file

@ -92,12 +92,14 @@ private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClicked
{
if (updateChecker != null && updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable)
{
UpdaterForm updaterForm = new UpdaterForm(updateChecker);
updaterForm.ShowDialog();
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
using (UpdaterForm updaterForm = new UpdaterForm(updateChecker))
{
Application.Exit();
updaterForm.ShowDialog();
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
{
Application.Exit();
}
}
}
}

View file

@ -441,12 +441,14 @@ private void CheckUpdate()
MessageBox.Show("An update is available for ShareX.\r\nWould you like to download it?", "ShareX",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
UpdaterForm updaterForm = new UpdaterForm(updateChecker);
updaterForm.ShowDialog();
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
using (UpdaterForm updaterForm = new UpdaterForm(updateChecker))
{
Application.Exit();
updaterForm.ShowDialog();
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
{
Application.Exit();
}
}
}
}

View file

@ -85,7 +85,7 @@ public async void StartRecording(TaskSettings TaskSettings)
{
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg && !FFmpegCache.HasDependencies())
{
if (MessageBox.Show("FFmpeg files are not present. Would you like to download and install them?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
if (MessageBox.Show("FFmpeg files are not present. Would you like to download and install them?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("McoreD", "FFmpegNet");
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
@ -93,8 +93,10 @@ public async void StartRecording(TaskSettings TaskSettings)
if (!string.IsNullOrEmpty(downloadUrl))
{
UpdateInfo updateInfo = new UpdateInfo() { DownloadURL = downloadUrl };
UpdaterForm form = new UpdaterForm(updateInfo) { Proxy = ProxyInfo.Current.GetWebProxy() };
form.ShowDialog();
using (UpdaterForm form = new UpdaterForm(updateInfo) { Proxy = ProxyInfo.Current.GetWebProxy() })
{
form.ShowDialog();
}
}
}
return;

View file

@ -153,6 +153,7 @@ private void InitializeComponent()
this.lblNameFormatPatternPreview = new System.Windows.Forms.Label();
this.lblNameFormatPatternPreviewActiveWindow = new System.Windows.Forms.Label();
this.tpUploadClipboard = new System.Windows.Forms.TabPage();
this.chkClipboardUploadContents = new System.Windows.Forms.CheckBox();
this.cbClipboardUploadAutoIndexFolder = new System.Windows.Forms.CheckBox();
this.cbClipboardUploadAutoDetectURL = new System.Windows.Forms.CheckBox();
this.chkUseDefaultUploadSettings = new System.Windows.Forms.CheckBox();
@ -162,7 +163,6 @@ private void InitializeComponent()
this.tpAdvanced = new System.Windows.Forms.TabPage();
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
this.chkClipboardUploadContents = new System.Windows.Forms.CheckBox();
this.tcHotkeySettings.SuspendLayout();
this.tpTask.SuspendLayout();
this.cmsDestinations.SuspendLayout();
@ -1625,6 +1625,17 @@ private void InitializeComponent()
this.tpUploadClipboard.Text = "Clipboard upload";
this.tpUploadClipboard.UseVisualStyleBackColor = true;
//
// chkClipboardUploadContents
//
this.chkClipboardUploadContents.AutoSize = true;
this.chkClipboardUploadContents.Location = new System.Drawing.Point(16, 16);
this.chkClipboardUploadContents.Name = "chkClipboardUploadContents";
this.chkClipboardUploadContents.Size = new System.Drawing.Size(345, 17);
this.chkClipboardUploadContents.TabIndex = 3;
this.chkClipboardUploadContents.Text = "If clipboard contains a image/text URL then download it and upload";
this.chkClipboardUploadContents.UseVisualStyleBackColor = true;
this.chkClipboardUploadContents.CheckedChanged += new System.EventHandler(this.chkClipboardUploadContents_CheckedChanged);
//
// cbClipboardUploadAutoIndexFolder
//
this.cbClipboardUploadAutoIndexFolder.AutoSize = true;
@ -1736,17 +1747,6 @@ private void InitializeComponent()
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged);
//
// chkClipboardUploadContents
//
this.chkClipboardUploadContents.AutoSize = true;
this.chkClipboardUploadContents.Location = new System.Drawing.Point(16, 16);
this.chkClipboardUploadContents.Name = "chkClipboardUploadContents";
this.chkClipboardUploadContents.Size = new System.Drawing.Size(323, 17);
this.chkClipboardUploadContents.TabIndex = 3;
this.chkClipboardUploadContents.Text = "If clipboard contains a file path or URL then upload its contents";
this.chkClipboardUploadContents.UseVisualStyleBackColor = true;
this.chkClipboardUploadContents.CheckedChanged += new System.EventHandler(this.chkClipboardUploadContents_CheckedChanged);
//
// TaskSettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View file

@ -196,9 +196,9 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false)
cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern;
// Upload / Clipboard upload
chkClipboardUploadContents.Checked = TaskSettings.UploadSettings.ClipboardUploadURLContents;
cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShortenURL;
cbClipboardUploadAutoIndexFolder.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder;
chkClipboardUploadContents.Checked = TaskSettings.UploadSettings.ClipboardUploadFileContents;
// Indexer
pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings;
@ -907,6 +907,11 @@ private void txtNameFormatPattern_TextChanged(object sender, EventArgs e)
lblNameFormatPatternPreview.Text = "Preview: " + nameParser.Parse(TaskSettings.UploadSettings.NameFormatPattern);
}
private void chkClipboardUploadContents_CheckedChanged(object sender, EventArgs e)
{
TaskSettings.UploadSettings.ClipboardUploadURLContents = chkClipboardUploadContents.Checked;
}
private void cbClipboardUploadAutoDetectURL_CheckedChanged(object sender, EventArgs e)
{
TaskSettings.UploadSettings.ClipboardUploadShortenURL = cbClipboardUploadAutoDetectURL.Checked;
@ -917,11 +922,6 @@ private void cbClipboardUploadAutoIndexFolder_CheckedChanged(object sender, Even
TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder = cbClipboardUploadAutoIndexFolder.Checked;
}
private void chkClipboardUploadContents_CheckedChanged(object sender, EventArgs e)
{
TaskSettings.UploadSettings.ClipboardUploadFileContents = chkClipboardUploadContents.Checked;
}
#endregion Upload
#region Indexer

View file

@ -302,9 +302,9 @@ public class TaskSettingsUpload
#region Upload / Clipboard upload
public bool ClipboardUploadURLContents = false;
public bool ClipboardUploadShortenURL = false;
public bool ClipboardUploadAutoIndexFolder = false;
public bool ClipboardUploadFileContents = false;
#endregion Upload / Clipboard upload
}

View file

@ -29,6 +29,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using UploadersLib;
@ -36,15 +37,15 @@ namespace ShareX
{
public static class UploadManager
{
public async static void UploadFile(string filePath, TaskSettings taskSettings = null)
public static void UploadFile(string filePath, TaskSettings taskSettings = null)
{
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
if (!string.IsNullOrEmpty(filePath))
{
if (File.Exists(filePath) || Helpers.IsValidURLRegex(filePath))
if (File.Exists(filePath))
{
UploadTask task = await UploadTask.CreateFileUploaderTaskAsync(filePath, taskSettings);
UploadTask task = UploadTask.CreateFileUploaderTask(filePath, taskSettings);
TaskManager.Start(task);
}
else if (Directory.Exists(filePath))
@ -171,13 +172,16 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
if (!string.IsNullOrEmpty(text))
{
if (taskSettings.UploadSettings.ClipboardUploadFileContents && Helpers.IsValidURLRegex(text))
string url = text.Trim();
bool isURL = Helpers.IsValidURLRegex(url);
if (taskSettings.UploadSettings.ClipboardUploadURLContents && isURL && (Helpers.IsImageFile(url) || Helpers.IsTextFile(url)))
{
UploadFile(text, taskSettings);
DownloadAndUploadFile(url, taskSettings);
}
else if (taskSettings.UploadSettings.ClipboardUploadShortenURL && Helpers.IsValidURLRegex(text))
else if (taskSettings.UploadSettings.ClipboardUploadShortenURL && isURL)
{
ShortenURL(text.Trim(), taskSettings);
ShortenURL(url, taskSettings);
}
else if (taskSettings.UploadSettings.ClipboardUploadAutoIndexFolder && text.Length <= 260 && Directory.Exists(text))
{
@ -314,5 +318,27 @@ public static void ShortenURL(string url, TaskSettings taskSettings = null)
TaskManager.Start(task);
}
}
public static void DownloadAndUploadFile(string url, TaskSettings taskSettings = null)
{
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
string downloadPath = null;
Helpers.AsyncJob(() =>
{
downloadPath = TaskHelpers.CheckFilePath(taskSettings.CaptureFolder, Path.GetFileName(url), taskSettings);
using (WebClient wc = new WebClient())
{
wc.Proxy = ProxyInfo.Current.GetWebProxy();
wc.DownloadFile(url, downloadPath);
}
},
() =>
{
UploadFile(downloadPath, taskSettings);
});
}
}
}

View file

@ -93,7 +93,7 @@ public static UploadTask CreateDataUploaderTask(EDataType dataType, Stream strea
return task;
}
public async static System.Threading.Tasks.Task<UploadTask> CreateFileUploaderTaskAsync(string filePath, TaskSettings taskSettings)
public static UploadTask CreateFileUploaderTask(string filePath, TaskSettings taskSettings)
{
EDataType dataType = Helpers.FindDataType(filePath);
UploadTask task = new UploadTask(taskSettings);
@ -107,19 +107,15 @@ public async static System.Threading.Tasks.Task<UploadTask> CreateFileUploaderTa
task.Info.FileName = TaskHelpers.GetFilename(task.Info.TaskSettings, ext);
}
if ((task.Info.TaskSettings.UploadSettings.ClipboardUploadFileContents || task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload) && dataType == EDataType.Image)
if (task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload && dataType == EDataType.Image)
{
task.Info.Job = TaskJob.ImageJob;
if (File.Exists(filePath))
task.tempImage = ImageHelpers.LoadImage(filePath);
else if (Helpers.IsValidURLRegex(filePath))
task.tempImage = await System.Threading.Tasks.TaskEx.Run<Image>(() => ImageHelpers.LoadRemoteImage(filePath));
task.tempImage = ImageHelpers.LoadImage(filePath);
}
else
{
task.Info.Job = TaskJob.FileUpload;
if (File.Exists(filePath))
task.Data = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
task.Data = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
return task;