mirror of
https://github.com/ShareX/ShareX.git
synced 2024-08-19 12:11:52 +12:00
Merge pull request #3697 from CookieMichal/code-factor-opti
Simplified code complexity
This commit is contained in:
commit
efb1c463e5
1 changed files with 88 additions and 124 deletions
|
@ -143,6 +143,65 @@ public static void UploadFolder(TaskSettings taskSettings = null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ProcessImageUpload(Image img, TaskSettings taskSettings)
|
||||||
|
{
|
||||||
|
if (img != null)
|
||||||
|
{
|
||||||
|
if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload)
|
||||||
|
{
|
||||||
|
taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunImageTask(img, taskSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessTextUpload(string text, TaskSettings taskSettings)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
string url = text.Trim();
|
||||||
|
|
||||||
|
if (URLHelpers.IsValidURL(url))
|
||||||
|
{
|
||||||
|
if (taskSettings.UploadSettings.ClipboardUploadURLContents)
|
||||||
|
{
|
||||||
|
DownloadAndUploadFile(url, taskSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskSettings.UploadSettings.ClipboardUploadShortenURL)
|
||||||
|
{
|
||||||
|
ShortenURL(url, taskSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskSettings.UploadSettings.ClipboardUploadShareURL)
|
||||||
|
{
|
||||||
|
ShareURL(url, taskSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskSettings.UploadSettings.ClipboardUploadAutoIndexFolder && text.Length <= 260 && Directory.Exists(text))
|
||||||
|
{
|
||||||
|
IndexFolder(text, taskSettings);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UploadText(text, taskSettings, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProcessFilesUpload(string[] files, TaskSettings taskSettings)
|
||||||
|
{
|
||||||
|
if (files.Length > 0)
|
||||||
|
{
|
||||||
|
UploadFile(files, taskSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ClipboardUpload(TaskSettings taskSettings = null)
|
public static void ClipboardUpload(TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
@ -151,67 +210,23 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
Image img = ClipboardHelpers.GetImage();
|
Image img = ClipboardHelpers.GetImage();
|
||||||
|
|
||||||
if (img != null)
|
ProcessImageUpload(img, taskSettings);
|
||||||
{
|
|
||||||
if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload)
|
|
||||||
{
|
|
||||||
taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
RunImageTask(img, taskSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (Clipboard.ContainsText())
|
else if (Clipboard.ContainsText())
|
||||||
{
|
{
|
||||||
string text = Clipboard.GetText();
|
string text = Clipboard.GetText();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(text))
|
ProcessTextUpload(text, taskSettings);
|
||||||
{
|
|
||||||
string url = text.Trim();
|
|
||||||
|
|
||||||
if (URLHelpers.IsValidURL(url))
|
|
||||||
{
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadURLContents)
|
|
||||||
{
|
|
||||||
DownloadAndUploadFile(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadShortenURL)
|
|
||||||
{
|
|
||||||
ShortenURL(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadShareURL)
|
|
||||||
{
|
|
||||||
ShareURL(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadAutoIndexFolder && text.Length <= 260 && Directory.Exists(text))
|
|
||||||
{
|
|
||||||
IndexFolder(text, taskSettings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UploadText(text, taskSettings, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (Clipboard.ContainsFileDropList())
|
else if (Clipboard.ContainsFileDropList())
|
||||||
{
|
{
|
||||||
string[] files = Clipboard.GetFileDropList().OfType<string>().ToArray();
|
string[] files = Clipboard.GetFileDropList().OfType<string>().ToArray();
|
||||||
|
|
||||||
if (files.Length > 0)
|
ProcessFilesUpload(files, taskSettings);
|
||||||
{
|
|
||||||
UploadFile(files, taskSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClipboardUploadCached(ClipboardContentViewer ccv, TaskSettings taskSettings = null)
|
private static void ClipboardUploadCached(ClipboardContentViewer ccv, TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
|
@ -219,72 +234,26 @@ public static void ClipboardUploadCached(ClipboardContentViewer ccv, TaskSetting
|
||||||
{
|
{
|
||||||
Image img = (Image)ccv.ClipboardContent;
|
Image img = (Image)ccv.ClipboardContent;
|
||||||
|
|
||||||
if (img != null)
|
ProcessImageUpload(img, taskSettings);
|
||||||
{
|
|
||||||
if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload)
|
|
||||||
{
|
|
||||||
taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
RunImageTask(img, taskSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (ccv.ClipboardContentType == EClipboardContentType.Text)
|
else if (ccv.ClipboardContentType == EClipboardContentType.Text)
|
||||||
{
|
{
|
||||||
string text = (string)ccv.ClipboardContent;
|
string text = (string)ccv.ClipboardContent;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(text))
|
ProcessTextUpload(text, taskSettings);
|
||||||
{
|
|
||||||
string url = text.Trim();
|
|
||||||
|
|
||||||
if (URLHelpers.IsValidURL(url))
|
|
||||||
{
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadURLContents)
|
|
||||||
{
|
|
||||||
DownloadAndUploadFile(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadShortenURL)
|
|
||||||
{
|
|
||||||
ShortenURL(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadShareURL)
|
|
||||||
{
|
|
||||||
ShareURL(url, taskSettings);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskSettings.UploadSettings.ClipboardUploadAutoIndexFolder && text.Length <= 260 && Directory.Exists(text))
|
|
||||||
{
|
|
||||||
IndexFolder(text, taskSettings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UploadText(text, taskSettings, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (ccv.ClipboardContentType == EClipboardContentType.Files)
|
else if (ccv.ClipboardContentType == EClipboardContentType.Files)
|
||||||
{
|
{
|
||||||
string[] files = (string[])ccv.ClipboardContent;
|
string[] files = (string[])ccv.ClipboardContent;
|
||||||
|
|
||||||
if (files.Length > 0)
|
ProcessFilesUpload(files, taskSettings);
|
||||||
{
|
|
||||||
UploadFile(files, taskSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClipboardUploadWithContentViewer(TaskSettings taskSettings = null)
|
private static void ProcessClipboardContentViewerDialog(ClipboardContentViewer ccv, TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
using (ClipboardContentViewer ccv = new ClipboardContentViewer())
|
|
||||||
{
|
|
||||||
if (ccv.ShowDialog() == DialogResult.OK && ccv.IsClipboardContentValid)
|
if (ccv.ShowDialog() == DialogResult.OK && ccv.IsClipboardContentValid)
|
||||||
{
|
{
|
||||||
if (ccv.ClipboardContentType != EClipboardContentType.Default)
|
if (ccv.ClipboardContentType != EClipboardContentType.Default)
|
||||||
|
@ -301,6 +270,15 @@ public static void ClipboardUploadWithContentViewer(TaskSettings taskSettings =
|
||||||
((Image)ccv.ClipboardContent).Dispose();
|
((Image)ccv.ClipboardContent).Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ClipboardUploadWithContentViewer(TaskSettings taskSettings = null)
|
||||||
|
{
|
||||||
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
|
using (ClipboardContentViewer ccv = new ClipboardContentViewer())
|
||||||
|
{
|
||||||
|
ProcessClipboardContentViewerDialog(ccv, taskSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClipboardUploadMainWindow(TaskSettings taskSettings = null)
|
public static void ClipboardUploadMainWindow(TaskSettings taskSettings = null)
|
||||||
|
@ -311,21 +289,7 @@ public static void ClipboardUploadMainWindow(TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
using (ClipboardContentViewer ccv = new ClipboardContentViewer(true))
|
using (ClipboardContentViewer ccv = new ClipboardContentViewer(true))
|
||||||
{
|
{
|
||||||
if (ccv.ShowDialog() == DialogResult.OK && ccv.IsClipboardContentValid)
|
ProcessClipboardContentViewerDialog(ccv, taskSettings);
|
||||||
{
|
|
||||||
if (ccv.ClipboardContentType != EClipboardContentType.Default)
|
|
||||||
{
|
|
||||||
ClipboardUploadCached(ccv, taskSettings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ClipboardUpload(taskSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ccv.ClipboardContentType == EClipboardContentType.Image)
|
|
||||||
{
|
|
||||||
((Image)ccv.ClipboardContent).Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Program.Settings.ShowClipboardContentViewer = !ccv.DontShowThisWindow;
|
Program.Settings.ShowClipboardContentViewer = !ccv.DontShowThisWindow;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue