Beispiel #1
0
        public static void ShowShortenURLDialog(TaskSettings taskSettings = null)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            string inputText = null;

            if (Clipboard.ContainsText())
            {
                string text = Clipboard.GetText();

                if (URLHelpers.IsValidURL(text))
                {
                    inputText = text;
                }
            }

            string url = InputBox.GetInputText("ShareX - " + ShareX.Properties.Resources.UploadManager_ShowShortenURLDialog_ShortenURL, inputText, ShareX.Properties.Resources.UploadManager_ShowShortenURLDialog_Shorten);

            if (!string.IsNullOrEmpty(url))
            {
                ShortenURL(url, taskSettings);
            }
        }
Beispiel #2
0
        public void AddNewsItem(NewsItem item)
        {
            int             index = dgvNews.Rows.Add();
            DataGridViewRow row   = dgvNews.Rows[index];

            row.Tag = item;

            row.Cells[1].Value = item.DateTime.ToShortDateString();

            string dateTimeTooltip;
            double days = (DateTime.Now - item.DateTime).TotalDays;

            if (days < 1)
            {
                dateTimeTooltip = "Today.";
            }
            else if (days < 2)
            {
                dateTimeTooltip = "Yesterday.";
            }
            else
            {
                dateTimeTooltip = (int)days + " days ago.";
            }

            row.Cells[1].ToolTipText = dateTimeTooltip;

            row.Cells[2].Value = item.Text;

            if (URLHelpers.IsValidURL(item.URL))
            {
                row.Cells[2].ToolTipText = item.URL;
            }
        }
Beispiel #3
0
        public static void ShowShortenURLDialog(TaskSettings taskSettings = null)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            string inputText = null;

            if (Clipboard.ContainsText())
            {
                string text = Clipboard.GetText();

                if (URLHelpers.IsValidURL(text))
                {
                    inputText = text;
                }
            }

            string url = InputBox.GetInputText("ShareX - " + "Shorten URL", inputText, "Shorten");

            if (!string.IsNullOrEmpty(url))
            {
                ShortenURL(url, taskSettings);
            }
        }
Beispiel #4
0
        public static void UploadURL(TaskSettings taskSettings = null)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            string inputText = null;

            if (Clipboard.ContainsText())
            {
                string text = Clipboard.GetText();

                if (URLHelpers.IsValidURL(text))
                {
                    inputText = text;
                }
            }

            string url = InputBox.GetInputText("ShareX - " + Resources.UploadManager_UploadURL_URL_to_download_from_and_upload, inputText);

            if (!string.IsNullOrEmpty(url))
            {
                DownloadAndUploadFile(url, taskSettings);
            }
        }
        private void B2UpdateCustomDomainPreview()
        {
            string uploadPath = NameParser.Parse(NameParserType.FolderPath, Config.B2UploadPath);

            if (cbB2CustomUrl.Checked)
            {
                string customUrl = NameParser.Parse(NameParserType.FolderPath, Config.B2CustomUrl);
                if (URLHelpers.IsValidURL(customUrl))
                {
                    txtB2UrlPreview.Text = customUrl + uploadPath + "example.png";
                }
                else
                {
                    txtB2UrlPreview.Text = "invalid custom URL";
                }
            }
            else
            {
                string bucket = string.IsNullOrEmpty(Config.B2BucketName) ?
                                "[bucket]" :
                                URLHelpers.URLEncode(Config.B2BucketName);
                string url = $"https://f001.backblazeb2.com/file/{bucket}/{uploadPath}example.png";
                txtB2UrlPreview.Text = url;
            }
        }
Beispiel #6
0
        public async Task UseCommandLineArgs(List <CLICommand> commands)
        {
            TaskSettings taskSettings = FindCLITask(commands);

            foreach (CLICommand command in commands)
            {
                DebugHelper.WriteLine("CommandLine: " + command);

                if (command.IsCommand)
                {
                    if (CheckCustomUploader(command) || CheckImageEffect(command) || await CheckCLIHotkey(command) || await CheckCLIWorkflow(command) ||
                        CheckNativeMessagingInput(command))
                    {
                    }

                    continue;
                }

                if (URLHelpers.IsValidURL(command.Command))
                {
                    UploadManager.DownloadAndUploadFile(command.Command, taskSettings);
                }
                else
                {
                    UploadManager.UploadFile(command.Command, taskSettings);
                }
            }
        }
Beispiel #7
0
 private void dgvNews_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left && e.ColumnIndex == 2)
     {
         DataGridViewRow row      = dgvNews.Rows[e.RowIndex];
         NewsItem        newsItem = row.Tag as NewsItem;
         if (newsItem != null && URLHelpers.IsValidURL(newsItem.URL))
         {
             URLHelpers.OpenURL(newsItem.URL);
         }
     }
 }
Beispiel #8
0
        private void CheckClipboardURL()
        {
            if (Clipboard.ContainsText())
            {
                string text = Clipboard.GetText();

                if (URLHelpers.IsValidURL(text))
                {
                    txtURL.Text = text;
                }
            }
        }
Beispiel #9
0
        public override UploadResult UploadText(string text, string fileName)
        {
            UploadResult ur = new UploadResult();

            if (!string.IsNullOrEmpty(text) && Settings != null)
            {
                Dictionary <string, string> args = new Dictionary <string, string>();

                args.Add("api_dev_key", APIKey);  // which is your unique API Developers Key
                args.Add("api_option", "paste");  // set as 'paste', this will indicate you want to create a new paste
                args.Add("api_paste_code", text); // this is the text that will be written inside your paste

                // Optional args
                args.Add("api_paste_name", Settings.Title);                            // this will be the name / title of your paste
                args.Add("api_paste_format", Settings.TextFormat);                     // this will be the syntax highlighting value
                args.Add("api_paste_private", GetPrivacy(Settings.Exposure));          // this makes a paste public or private, public = 0, private = 1
                args.Add("api_paste_expire_date", GetExpiration(Settings.Expiration)); // this sets the expiration date of your paste

                if (!string.IsNullOrEmpty(Settings.UserKey))
                {
                    args.Add("api_user_key", Settings.UserKey); // this paramater is part of the login system
                }

                ur.Response = SendRequestMultiPart("https://pastebin.com/api/api_post.php", args);

                if (URLHelpers.IsValidURL(ur.Response))
                {
                    if (Settings.RawURL)
                    {
                        string id = URLHelpers.GetFileName(ur.Response);
                        ur.URL = "https://pastebin.com/raw/" + id;
                    }
                    else
                    {
                        ur.URL = ur.Response;
                    }
                }
                else
                {
                    Errors.Add(ur.Response);
                }
            }

            return(ur);
        }
Beispiel #10
0
        public QRCodeForm(string text = null)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;

            if (!string.IsNullOrEmpty(text))
            {
                txtQRCode.Text = text;
            }
            else
            {
                if (Clipboard.ContainsText())
                {
                    text = Clipboard.GetText();

                    if (URLHelpers.IsValidURL(text))
                    {
                        txtQRCode.Text = text;
                    }
                }
            }
        }
Beispiel #11
0
        public QRCodeForm(string text = null)
        {
            InitializeComponent();
            Icon       = ShareXResources.Icon;
            ClientSize = new Size(400, 400);

            if (!string.IsNullOrEmpty(text))
            {
                qrMain.Dock   = DockStyle.Fill;
                qrMain.Cursor = Cursors.Hand;
                Text         += ": " + text;
                qrMain.Text   = text;
            }
            else
            {
                EditMode          = true;
                txtQRCode.Visible = true;

                if (Clipboard.ContainsText())
                {
                    text = Clipboard.GetText();

                    if (URLHelpers.IsValidURL(text))
                    {
                        txtQRCode.Text = text;
                    }
                    else
                    {
                        SetDefaultText();
                    }
                }
                else
                {
                    SetDefaultText();
                }

                txtQRCode.SelectAll();
            }
        }
Beispiel #12
0
        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);
                }
            }
        }
Beispiel #13
0
        public static void ClipboardUpload(TaskSettings taskSettings = null)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            if (Clipboard.ContainsImage())
            {
                Image img = ClipboardHelpers.GetImage();

                if (img != null)
                {
                    if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload)
                    {
                        taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost;
                    }

                    RunImageTask(img, taskSettings);
                }
            }
            else if (Clipboard.ContainsText())
            {
                string text = Clipboard.GetText();

                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);
                    }
                }
            }
            else if (Clipboard.ContainsFileDropList())
            {
                string[] files = Clipboard.GetFileDropList().OfType <string>().ToArray();

                if (files.Length > 0)
                {
                    UploadFile(files, taskSettings);
                }
            }
        }
Beispiel #14
0
        public void AddNewsItem(NewsItem item)
        {
            RowStyle style = new RowStyle(SizeType.AutoSize);

            tlpMain.RowStyles.Add(style);
            int index = tlpMain.RowCount++ - 1;

            Label lblDateTime = new Label()
            {
                Anchor    = AnchorStyles.Left | AnchorStyles.Right,
                AutoSize  = true,
                BackColor = Color.Transparent,
                Font      = new Font("Arial", 10),
                Margin    = new Padding(0),
                Padding   = new Padding(10, 8, 5, 8),
                Text      = item.DateTime.ToShortDateString()
            };

            string dateTimeTooltip;
            double days = (DateTime.Now - item.DateTime).TotalDays;

            if (days < 1)
            {
                dateTimeTooltip = "Today.";
            }
            else if (days < 2)
            {
                dateTimeTooltip = "Yesterday.";
            }
            else
            {
                dateTimeTooltip = (int)days + " days ago.";
            }

            tooltip.SetToolTip(lblDateTime, dateTimeTooltip);

            tlpMain.Controls.Add(lblDateTime, 0, index);

            Label lblText = new Label()
            {
                Anchor    = AnchorStyles.Left | AnchorStyles.Right,
                AutoSize  = true,
                BackColor = Color.Transparent,
                Font      = new Font("Arial", 10),
                Margin    = new Padding(0),
                Padding   = new Padding(5, 8, 5, 8),
                Text      = item.Text
            };

            if (URLHelpers.IsValidURL(item.URL))
            {
                tooltip.SetToolTip(lblText, item.URL);
                lblText.Cursor      = Cursors.Hand;
                lblText.MouseEnter += (sender, e) => lblText.ForeColor = Color.Blue;
                lblText.MouseLeave += (sender, e) => lblText.ForeColor = SystemColors.ControlText;
                lblText.MouseClick += (sender, e) =>
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        URLHelpers.OpenURL(item.URL);
                    }
                };
            }

            tlpMain.Controls.Add(lblText, 1, index);
        }