Esempio n. 1
0
        static void InitializeUpload()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            List <string> validFileExtensions = new List <string> {
                "png", "jpg", "jpeg", "bmp", "gif"
            };

            List <string> validFiles = SubmittedFiles.Where((f) => File.Exists(f) &&
                                                            validFileExtensions.Contains(
                                                                Path.GetExtension(f).ToLower().Remove(0, 1))).ToList();

            if (validFiles.Count < 1)
            {
                MessageBox.Show(Message_NoValidFiles);
                return;
            }

            //make progress form
            ImgurUploader i = new ImgurUploader {
                Files = validFiles
            };

            i.UpdateStatus += new ImgurUploader.UploadStatusHandler(i_UpdateStatus);

            _f = new ProgressForm();

            _uploadThread = new Thread(i.UploadFiles);
            _uploadThread.Start();

            Application.Run(_f);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            string[] submittedFiles = new string[] {};
            if (args.Length != 0)
            {
                submittedFiles = args;
            }
            else
            { // show a file chooser dialog
                OpenFileDialog fd = new OpenFileDialog()
                {
                    Multiselect        = true,
                    AutoUpgradeEnabled = true,
                    Filter             = "Images(*.png;*.jpg;*.jpeg;*.gif;*.bmp)|*.png;*.jpg;*.jpeg;*.gif;*.bmp"
                };
                fd.ShowDialog();
                submittedFiles = fd.FileNames;
            }

            List <string> validFileExtensions = new List <string> {
                "png", "jpg", "jpeg", "bmp", "gif"
            };

            var validFileNames =
                from a in submittedFiles
                where
                File.Exists(a) &&
                validFileExtensions.Contains(Path.GetExtension(a).ToLower().Remove(0, 1))
                select a;

            if (validFileNames.Count() == 0)
            {
                MessageBox.Show(ConfigurationManager.AppSettings["Message_NoValidFiles"]); return;
            }

            //make our progress form
            ImgurUploader i = new ImgurUploader {
                Files = new List <string>(validFileNames)
            };

            i.UpdateStatus     += new ImgurUploader.UploadStatusHandler(i_UpdateStatus);
            i.InvalidFileFound += new ImgurUploader.InvalidFileHandler(i_InvalidFileFound);
            i.FileComplete     += new ImgurUploader.FileCompleteHandler(i_FileComplete);

            _f = new ProgressForm();

            _uploadThread = new Thread(i.UploadFiles);
            _uploadThread.Start();

            Application.Run(_f);
        }
Esempio n. 3
0
 private void btnActivate_Click(object sender, EventArgs e)
 {
     btnActivate.Enabled = false;
     try {
         ImgurUploader.Authorize(GrantType.Pin, txtPIN.Text.Trim());
     }
     catch (AuthorizationException ex) {
         MessageBox.Show("Something went wrong, could not authorize", "Error");
         btnActivate.Enabled = true;
         return;
     }
     txtPIN.Clear();
     PopulateAccount();
 }
Esempio n. 4
0
        private async Task Add(Stream data, string name)
        {
            var indicator = new Progress <int>(i => progress.Value = i);

            progress.Value   = 0;
            progress.Visible = true;

            var resp = await ImgurUploader.Upload(data, indicator);

            if (resp == null)
            {
                // TODO: error handling
                MessageBox.Show($"Cannot upload: '{name}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                progress.Visible = false;
                return;
            }

            resultsListView.Items.Add(new ListViewItem(new[] { name, resp.Link }));
            resultsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            progress.Visible = false;
        }
Esempio n. 5
0
        static bool CheckForUpdate()
        {
            if (!Settings.Default.CheckUpdates)
            {
                return(false);
            }

            string latestVersion = ImgurUploader.GetLatestRelease();

            if (!string.IsNullOrEmpty(latestVersion) &&
                "v" + Application.ProductVersion != latestVersion)
            {
                DialogResult result = MessageBox.Show(
                    "There is an update available. Would you like to download now?",
                    "Imgur Uploader", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Process.Start(Settings.Default.DownloadURL);
                    return(true);
                }
            }
            return(false);
        }