Skip to content

Commit

Permalink
Fixes for merge from pull request #13.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bkeiren committed Jan 6, 2015
1 parent 75ce6e4 commit 7ac77cf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion EasyImgur/EasyImgur.csproj
Expand Up @@ -61,8 +61,10 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
Expand Down
47 changes: 35 additions & 12 deletions EasyImgur/Form1.cs
Expand Up @@ -81,13 +81,19 @@ 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;
// 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 },
Expand All @@ -98,27 +104,39 @@ void singleInstance_ArgumentsReceived( object sender, ArgumentsReceivedEventArgs
{ "exit", () => exitWhenFinished = true },
{ "portable", () => { } } // ignore
};
List<int> processed = new List<int>();

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;
}

Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 7ac77cf

Please sign in to comment.