Skip to content

Commit

Permalink
Catch exception if pokemon could not be found.
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcuseMi committed Aug 9, 2016
1 parent 5b86382 commit 97dc26e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 13 additions & 5 deletions PogoLocationFeeder.GUI/Common/PokemonFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Newtonsoft.Json.Converters;
using PogoLocationFeeder.Config;
using PogoLocationFeeder.GUI.Models;
using PogoLocationFeeder.Helper;
using POGOProtos.Enums;

namespace PogoLocationFeeder.GUI.Common {
Expand Down Expand Up @@ -59,13 +60,20 @@ public static void Load() {
var set = GlobalSettings.PokekomsToFeedFilter;

foreach (var s in set) {
var id = (PokemonId) Enum.Parse(typeof(PokemonId), s);
var img = new BitmapImage(
try
{
var id = PokemonParser.ParsePokemon(s, true);
var img = new BitmapImage(
new Uri(
$"pack://application:,,,/PogoLocationFeeder.GUI;component/Assets/icons/{(int) id}.png",
$"pack://application:,,,/PogoLocationFeeder.GUI;component/Assets/icons/{(int)id}.png",
UriKind.Absolute));
img.Freeze();
GlobalVariables.PokemonToFeedFilterInternal.Add(new PokemonFilterModel(id.ToString(), img, true));
img.Freeze();
GlobalVariables.PokemonToFeedFilterInternal.Add(new PokemonFilterModel(id.ToString(), img, true));
}
catch (Exception e)
{
Log.Warn("Could not add pokemon to the filter" , e);
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions PogoLocationFeeder/Helper/PokemonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PokemonParser
new HashSet<string> {"Mime"})
};

public static PokemonId ParsePokemon(string input)
public static PokemonId ParsePokemon(string input, bool throwException = false)
{
foreach (var name in Enum.GetNames(typeof(PokemonId)))
{
Expand Down Expand Up @@ -49,7 +49,10 @@ public static PokemonId ParsePokemon(string input)
}
}


if (throwException)
{
throw new Exception($"No pokemon found with name {input}");
}
return PokemonId.Missingno;
}

Expand Down

0 comments on commit 97dc26e

Please sign in to comment.