Esempio n. 1
0
        private void buttonChangeCredentials_Click(object sender, EventArgs e)
        {
            AuthorizeForm accountCredentialsForm = new AuthorizeForm();
            DialogResult  res = accountCredentialsForm.ShowDialog(this);

            if (ImgurAPI.HasBeenAuthorized())
            {
                buttonForceTokenRefresh.Enabled = true;
            }
            else
            {
                buttonForceTokenRefresh.Enabled = false;
            }
        }
Esempio n. 2
0
        void singleInstance_ArgumentsReceived(object sender, ArgumentsReceivedEventArgs e)
        {
            // Using "/exit" anywhere in the command list will cause EasyImgur to exit after uploading;
            // this will happen regardless of the execution sending the exit command was the execution that
            // launched the initial instance of EasyImgur.
            bool exitWhenFinished = false;
            bool anonymous        = false;

            // mappings of switch names to actions
            Dictionary <string, Action> handlers = new Dictionary <string, Action>()
            {
                { "anonymous", () => anonymous = true },
                { "noinfo", () => Verbosity = (MessageVerbosity)Math.Max((int)Verbosity, (int)MessageVerbosity.NoInfo) },
                { "q", () => Verbosity = (MessageVerbosity)Math.Max((int)Verbosity, (int)MessageVerbosity.NoInfo) },
                { "noerr", () => Verbosity = (MessageVerbosity)Math.Max((int)Verbosity, (int)MessageVerbosity.NoError) },
                { "qq", () => Verbosity = (MessageVerbosity)Math.Max((int)Verbosity, (int)MessageVerbosity.NoError) },
                { "exit", () => exitWhenFinished = true },
                { "portable", () => { } } // ignore
            };

            try
            {
                // First scan for switches
                int badSwitchCount = 0;
                foreach (String str in e.Args.Where(s => s != null && s.StartsWith("/")))
                {
                    String param = str.Remove(0, 1); // Strip the leading '/' from the switch.

                    if (handlers.ContainsKey(param))
                    {
                        Log.Warning("Consuming command-line switch '" + param + "'.");
                        handlers[param]();
                    }
                    else
                    {
                        ++badSwitchCount;
                        Log.Warning("Ignoring unrecognized command-line switch '" + param + "'.");
                    }
                }

                if (badSwitchCount > 0 && ShouldShowMessage(MessageVerbosity.NoError))
                {
                    ShowBalloonTip(2000, "Invalid switch", badSwitchCount.ToString() + " invalid switch" + (badSwitchCount > 1 ? "es were" : " was") + " passed to EasyImgur (see log for details). No files were uploaded.", ToolTipIcon.Error, true);
                    return;
                }

                // Process actual arguments
                foreach (string path in e.Args.Where(s => s != null && !s.StartsWith("/")))
                {
                    if (!anonymous && !ImgurAPI.HasBeenAuthorized())
                    {
                        ShowBalloonTip(2000, "Not logged in", "You aren't logged in but you're trying to upload to an account. Authorize EasyImgur and try again.", ToolTipIcon.Error, true);
                        return;
                    }

                    if (Directory.Exists(path))
                    {
                        string[] fileTypes = new[] { ".jpg", ".jpeg", ".png", ".apng", ".bmp",
                                                     ".gif", ".tiff", ".tif", ".xcf" };
                        List <string> files = new List <string>();
                        foreach (string s in Directory.GetFiles(path))
                        {
                            bool cont = false;
                            foreach (string filetype in fileTypes)
                            {
                                if (s.EndsWith(filetype, true, null))
                                {
                                    cont = true;
                                    break;
                                }
                            }
                            if (!cont)
                            {
                                continue;
                            }

                            files.Add(s);
                        }

                        UploadAlbum(anonymous, files.ToArray(), path.Split('\\').Last());
                    }
                    else if (File.Exists(path))
                    {
                        UploadFile(anonymous, new string[] { path });
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unhandled exception in context menu thread: " + ex.ToString());
                ShowBalloonTip(2000, "Error", "An unknown exception occurred during upload. Check the log for further information.", ToolTipIcon.Error, true);
            }

            if (exitWhenFinished)
            {
                Application.Exit();
            }

            // reset verbosity
            Verbosity = MessageVerbosity.Normal;
        }
Esempio n. 3
0
 private void buttonForceTokenRefresh_Click(object sender, EventArgs e)
 {
     ImgurAPI.ForceRefreshTokens();
     SetAuthorizationStatusUI(ImgurAPI.HasBeenAuthorized());
 }
Esempio n. 4
0
        private void SelectedHistoryItemChanged()
        {
            HistoryItem item = listBoxHistory.SelectedItem as HistoryItem;

            if (item == null)
            {
                buttonRemoveFromImgur.Enabled     = false;
                buttonRemoveFromHistory.Enabled   = false;
                btnOpenImageLinkInBrowser.Enabled = false;
            }
            else
            {
                buttonRemoveFromImgur.Enabled     = item.anonymous || (!item.anonymous && ImgurAPI.HasBeenAuthorized());
                buttonRemoveFromHistory.Enabled   = true;
                btnOpenImageLinkInBrowser.Enabled = true;
            }
        }
Esempio n. 5
0
        private void SelectedHistoryItemChanged()
        {
            groupBoxHistorySelection.Text =
                String.Format("Selection: {0} {1}", listBoxHistory.SelectedItems.Count, listBoxHistory.SelectedItems.Count == 1 ? "item" : "items");
            HistoryItem item = listBoxHistory.SelectedItem as HistoryItem;

            if (item == null)
            {
                buttonRemoveFromImgur.Enabled     = false;
                buttonRemoveFromHistory.Enabled   = false;
                btnOpenImageLinkInBrowser.Enabled = false;
            }
            else
            {
                buttonRemoveFromImgur.Enabled     = item.Anonymous || (!item.Anonymous && ImgurAPI.HasBeenAuthorized());
                buttonRemoveFromHistory.Enabled   = true;
                btnOpenImageLinkInBrowser.Enabled = true;
            }
        }