From 7ac77cf317a86bae5607199a52965af131b98ea9 Mon Sep 17 00:00:00 2001 From: Bryan Keiren Date: Tue, 6 Jan 2015 22:16:11 +0100 Subject: [PATCH] Fixes for merge from pull request #13. Fixes: - Removed unused variable(s) - Fixed actual switch parsing (couldn't have worked?) Changes: - Added function for testing if certain verbosity should currently be shown. - Changed wording in some tooltips. - Removed manifest generation. --- EasyImgur/EasyImgur.csproj | 4 +++- EasyImgur/Form1.cs | 47 ++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/EasyImgur/EasyImgur.csproj b/EasyImgur/EasyImgur.csproj index 1d45646..83584a0 100644 --- a/EasyImgur/EasyImgur.csproj +++ b/EasyImgur/EasyImgur.csproj @@ -61,8 +61,10 @@ 4 x86 + + - Properties\app.manifest + true diff --git a/EasyImgur/Form1.cs b/EasyImgur/Form1.cs index ec72f78..c6f3057 100644 --- a/EasyImgur/Form1.cs +++ b/EasyImgur/Form1.cs @@ -81,6 +81,11 @@ void ImplementPortableMode() } } + bool ShouldShowMessage(MessageVerbosity _Verbosity) + { + return Verbosity < _Verbosity; + } + void singleInstance_ArgumentsReceived( object sender, ArgumentsReceivedEventArgs e ) { // Using "/exit" anywhere in the command list will cause EasyImgur to exit after uploading; @@ -88,6 +93,7 @@ void singleInstance_ArgumentsReceived( object sender, ArgumentsReceivedEventArgs // launched the initial instance of EasyImgur. bool exitWhenFinished = false; bool anonymous = false; + // mappings of switch names to actions Dictionary handlers = new Dictionary() { { "anonymous", () => anonymous = true }, @@ -98,27 +104,39 @@ void singleInstance_ArgumentsReceived( object sender, ArgumentsReceivedEventArgs { "exit", () => exitWhenFinished = true }, { "portable", () => { } } // ignore }; - List processed = new List(); + try { - // first scan for switches - bool badSwitch = false; - foreach(string switch_ in e.Args.Where(s => s != null && s.StartsWith("/"))) - if(handlers.ContainsKey(switch_)) - handlers[switch_](); + // 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 - badSwitch = true; - if(badSwitch && Verbosity < MessageVerbosity.NoError) + { + ++badSwitchCount; + Log.Warning("Ignoring unrecognized command-line switch '" + param + "'."); + } + } + + if (badSwitchCount > 0 && ShouldShowMessage(MessageVerbosity.NoError)) { - ShowBalloonTip(2000, "Invalid switch", "An invalid switch was passed to EasyImgur. No files were uploaded.", ToolTipIcon.Error, true); + 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 + + // 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. Authorize EasyImgur and try again.", ToolTipIcon.Error, true); + 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; } @@ -163,10 +181,15 @@ void singleInstance_ArgumentsReceived( object sender, ArgumentsReceivedEventArgs private void ShowBalloonTip( int _Timeout, string _Title, string _Text, ToolTipIcon _Icon, bool error = false ) { - if(Verbosity < (error ? MessageVerbosity.NoError : MessageVerbosity.NoInfo)) + if (ShouldShowMessage(error ? MessageVerbosity.NoError : MessageVerbosity.NoInfo)) + { notifyIcon1.ShowBalloonTip(_Timeout, _Title, _Text, _Icon); + Log.Info(string.Format("Showed tooltip with title \"{0}\" and text \"{1}\".", _Title, _Text)); + } else + { Log.Info(string.Format("Tooltip with title \"{0}\" and text \"{1}\" was suppressed.", _Title, _Text)); + } } private void ApplicationExit( object sender, EventArgs e )