mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
URL upload changes
This commit is contained in:
parent
8ddae5f03d
commit
b2fdc2a9fd
10 changed files with 76 additions and 70 deletions
|
@ -1124,27 +1124,5 @@ public static Image LoadImage(string filePath)
|
||||||
|
|
||||||
return null;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -99,7 +99,7 @@ public string GetLatestDownloadURL()
|
||||||
|
|
||||||
if (releases != null && releases.Count > 0)
|
if (releases != null && releases.Count > 0)
|
||||||
{
|
{
|
||||||
return GetDownloadURL(releases[releases.Count - 1]);
|
return GetDownloadURL(releases[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -92,12 +92,14 @@ private void llblUpdateAvailable_LinkClicked(object sender, LinkLabelLinkClicked
|
||||||
{
|
{
|
||||||
if (updateChecker != null && updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable)
|
if (updateChecker != null && updateChecker.UpdateInfo != null && updateChecker.UpdateInfo.Status == UpdateStatus.UpdateAvailable)
|
||||||
{
|
{
|
||||||
UpdaterForm updaterForm = new UpdaterForm(updateChecker);
|
using (UpdaterForm updaterForm = new UpdaterForm(updateChecker))
|
||||||
updaterForm.ShowDialog();
|
|
||||||
|
|
||||||
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
|
|
||||||
{
|
{
|
||||||
Application.Exit();
|
updaterForm.ShowDialog();
|
||||||
|
|
||||||
|
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
|
||||||
|
{
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,12 +441,14 @@ private void CheckUpdate()
|
||||||
MessageBox.Show("An update is available for ShareX.\r\nWould you like to download it?", "ShareX",
|
MessageBox.Show("An update is available for ShareX.\r\nWould you like to download it?", "ShareX",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
UpdaterForm updaterForm = new UpdaterForm(updateChecker);
|
using (UpdaterForm updaterForm = new UpdaterForm(updateChecker))
|
||||||
updaterForm.ShowDialog();
|
|
||||||
|
|
||||||
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
|
|
||||||
{
|
{
|
||||||
Application.Exit();
|
updaterForm.ShowDialog();
|
||||||
|
|
||||||
|
if (updaterForm.Status == DownloaderFormStatus.InstallStarted)
|
||||||
|
{
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public async void StartRecording(TaskSettings TaskSettings)
|
||||||
{
|
{
|
||||||
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg && !FFmpegCache.HasDependencies())
|
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");
|
GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("McoreD", "FFmpegNet");
|
||||||
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||||
|
@ -93,8 +93,10 @@ public async void StartRecording(TaskSettings TaskSettings)
|
||||||
if (!string.IsNullOrEmpty(downloadUrl))
|
if (!string.IsNullOrEmpty(downloadUrl))
|
||||||
{
|
{
|
||||||
UpdateInfo updateInfo = new UpdateInfo() { DownloadURL = downloadUrl };
|
UpdateInfo updateInfo = new UpdateInfo() { DownloadURL = downloadUrl };
|
||||||
UpdaterForm form = new UpdaterForm(updateInfo) { Proxy = ProxyInfo.Current.GetWebProxy() };
|
using (UpdaterForm form = new UpdaterForm(updateInfo) { Proxy = ProxyInfo.Current.GetWebProxy() })
|
||||||
form.ShowDialog();
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
24
ShareX/Forms/TaskSettingsForm.Designer.cs
generated
24
ShareX/Forms/TaskSettingsForm.Designer.cs
generated
|
@ -153,6 +153,7 @@ private void InitializeComponent()
|
||||||
this.lblNameFormatPatternPreview = new System.Windows.Forms.Label();
|
this.lblNameFormatPatternPreview = new System.Windows.Forms.Label();
|
||||||
this.lblNameFormatPatternPreviewActiveWindow = new System.Windows.Forms.Label();
|
this.lblNameFormatPatternPreviewActiveWindow = new System.Windows.Forms.Label();
|
||||||
this.tpUploadClipboard = new System.Windows.Forms.TabPage();
|
this.tpUploadClipboard = new System.Windows.Forms.TabPage();
|
||||||
|
this.chkClipboardUploadContents = new System.Windows.Forms.CheckBox();
|
||||||
this.cbClipboardUploadAutoIndexFolder = new System.Windows.Forms.CheckBox();
|
this.cbClipboardUploadAutoIndexFolder = new System.Windows.Forms.CheckBox();
|
||||||
this.cbClipboardUploadAutoDetectURL = new System.Windows.Forms.CheckBox();
|
this.cbClipboardUploadAutoDetectURL = new System.Windows.Forms.CheckBox();
|
||||||
this.chkUseDefaultUploadSettings = 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.tpAdvanced = new System.Windows.Forms.TabPage();
|
||||||
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
|
this.pgTaskSettings = new System.Windows.Forms.PropertyGrid();
|
||||||
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
|
this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox();
|
||||||
this.chkClipboardUploadContents = new System.Windows.Forms.CheckBox();
|
|
||||||
this.tcHotkeySettings.SuspendLayout();
|
this.tcHotkeySettings.SuspendLayout();
|
||||||
this.tpTask.SuspendLayout();
|
this.tpTask.SuspendLayout();
|
||||||
this.cmsDestinations.SuspendLayout();
|
this.cmsDestinations.SuspendLayout();
|
||||||
|
@ -1625,6 +1625,17 @@ private void InitializeComponent()
|
||||||
this.tpUploadClipboard.Text = "Clipboard upload";
|
this.tpUploadClipboard.Text = "Clipboard upload";
|
||||||
this.tpUploadClipboard.UseVisualStyleBackColor = true;
|
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
|
// cbClipboardUploadAutoIndexFolder
|
||||||
//
|
//
|
||||||
this.cbClipboardUploadAutoIndexFolder.AutoSize = true;
|
this.cbClipboardUploadAutoIndexFolder.AutoSize = true;
|
||||||
|
@ -1736,17 +1747,6 @@ private void InitializeComponent()
|
||||||
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
|
this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true;
|
||||||
this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged);
|
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
|
// TaskSettingsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
|
|
@ -196,9 +196,9 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false)
|
||||||
cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern;
|
cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern;
|
||||||
|
|
||||||
// Upload / Clipboard upload
|
// Upload / Clipboard upload
|
||||||
|
chkClipboardUploadContents.Checked = TaskSettings.UploadSettings.ClipboardUploadURLContents;
|
||||||
cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShortenURL;
|
cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShortenURL;
|
||||||
cbClipboardUploadAutoIndexFolder.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder;
|
cbClipboardUploadAutoIndexFolder.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder;
|
||||||
chkClipboardUploadContents.Checked = TaskSettings.UploadSettings.ClipboardUploadFileContents;
|
|
||||||
|
|
||||||
// Indexer
|
// Indexer
|
||||||
pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings;
|
pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings;
|
||||||
|
@ -907,6 +907,11 @@ private void txtNameFormatPattern_TextChanged(object sender, EventArgs e)
|
||||||
lblNameFormatPatternPreview.Text = "Preview: " + nameParser.Parse(TaskSettings.UploadSettings.NameFormatPattern);
|
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)
|
private void cbClipboardUploadAutoDetectURL_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
TaskSettings.UploadSettings.ClipboardUploadShortenURL = cbClipboardUploadAutoDetectURL.Checked;
|
TaskSettings.UploadSettings.ClipboardUploadShortenURL = cbClipboardUploadAutoDetectURL.Checked;
|
||||||
|
@ -917,11 +922,6 @@ private void cbClipboardUploadAutoIndexFolder_CheckedChanged(object sender, Even
|
||||||
TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder = cbClipboardUploadAutoIndexFolder.Checked;
|
TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder = cbClipboardUploadAutoIndexFolder.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chkClipboardUploadContents_CheckedChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
TaskSettings.UploadSettings.ClipboardUploadFileContents = chkClipboardUploadContents.Checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Upload
|
#endregion Upload
|
||||||
|
|
||||||
#region Indexer
|
#region Indexer
|
||||||
|
|
|
@ -302,9 +302,9 @@ public class TaskSettingsUpload
|
||||||
|
|
||||||
#region Upload / Clipboard upload
|
#region Upload / Clipboard upload
|
||||||
|
|
||||||
|
public bool ClipboardUploadURLContents = false;
|
||||||
public bool ClipboardUploadShortenURL = false;
|
public bool ClipboardUploadShortenURL = false;
|
||||||
public bool ClipboardUploadAutoIndexFolder = false;
|
public bool ClipboardUploadAutoIndexFolder = false;
|
||||||
public bool ClipboardUploadFileContents = false;
|
|
||||||
|
|
||||||
#endregion Upload / Clipboard upload
|
#endregion Upload / Clipboard upload
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using UploadersLib;
|
using UploadersLib;
|
||||||
|
|
||||||
|
@ -36,15 +37,15 @@ namespace ShareX
|
||||||
{
|
{
|
||||||
public static class UploadManager
|
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 (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filePath))
|
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);
|
TaskManager.Start(task);
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(filePath))
|
else if (Directory.Exists(filePath))
|
||||||
|
@ -171,13 +172,16 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(text))
|
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))
|
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);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -93,7 +93,7 @@ public static UploadTask CreateDataUploaderTask(EDataType dataType, Stream strea
|
||||||
return task;
|
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);
|
EDataType dataType = Helpers.FindDataType(filePath);
|
||||||
UploadTask task = new UploadTask(taskSettings);
|
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);
|
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;
|
task.Info.Job = TaskJob.ImageJob;
|
||||||
if (File.Exists(filePath))
|
task.tempImage = ImageHelpers.LoadImage(filePath);
|
||||||
task.tempImage = ImageHelpers.LoadImage(filePath);
|
|
||||||
else if (Helpers.IsValidURLRegex(filePath))
|
|
||||||
task.tempImage = await System.Threading.Tasks.TaskEx.Run<Image>(() => ImageHelpers.LoadRemoteImage(filePath));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
task.Info.Job = TaskJob.FileUpload;
|
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;
|
return task;
|
||||||
|
|
Loading…
Reference in a new issue