Exemplo n.º 1
0
        private void UploadFromClipboard(System.Drawing.Imaging.ImageFormat imageFormat, String fileName)
        {
            if (Clipboard.ContainsImage())
            {
                imageUrl = "";

                Stream fileStream = new MemoryStream();
                Clipboard.GetImage().Save(fileStream, imageFormat);

                UploadWorker uploadWorker = new UploadWorker(fileStream, fileName);
                Thread       uploadThread = new Thread(new ParameterizedThreadStart(uploadWorker.Run));

                uploadThread.Start(this);
                uploadThread.Join();

                if (imageUrl.Length > 0)
                {
                    Clipboard.SetText(imageUrl);
                    this.notifyIcon.ShowBalloonTip(3000, "Image Upload Complete", "Image was uploaded successfully,\nthe URL is now in your Clipboard:\n" + imageUrl, ToolTipIcon.Info);

                    if (!performedUpdate && releaseMode)
                    {
                        try {
                            webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
                            webClient.DownloadFileAsync(new Uri("https://github.com/downloads/shurcooL/InstantBackgroundUploader_Windows/InstantBackgroundUploader.exe"), Path.Combine(Path.GetTempPath(), "InstantBackgroundUploader.exe.update"));
                        } catch (Exception) {}
                    }
                }
            }
            else
            {
                MessageBox.Show("There is no image in Clipboard to upload.", "Instant Background Uploader", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void UploadFromClipboard(System.Drawing.Imaging.ImageFormat imageFormat, String fileName)
        {
            if (Clipboard.ContainsImage())
            {
                imageUrl = "";

                Stream fileStream = new MemoryStream();
                Clipboard.GetImage().Save(fileStream, imageFormat);

                UploadWorker uploadWorker = new UploadWorker(fileStream, fileName);
                Thread uploadThread = new Thread(new ParameterizedThreadStart(uploadWorker.Run));

                uploadThread.Start(this);
                uploadThread.Join();

                if (imageUrl.Length > 0)
                {
                    Clipboard.SetText(imageUrl);
                    this.notifyIcon.ShowBalloonTip(3000, "Image Upload Complete", "Image was uploaded successfully,\nthe URL is now in your Clipboard:\n" + imageUrl, ToolTipIcon.Info);

                    if (!performedUpdate && releaseMode) try {
                        webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
                        webClient.DownloadFileAsync(new Uri("https://github.com/downloads/shurcooL/InstantBackgroundUploader_Windows/InstantBackgroundUploader.exe"), Path.Combine(Path.GetTempPath(), "InstantBackgroundUploader.exe.update"));
                    } catch (Exception) {}
                }
            }
            else
            {
                MessageBox.Show("There is no image in Clipboard to upload.", "Instant Background Uploader", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }