Skip to content

Commit

Permalink
Merge branch 'master' into hero-portrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarroc2762 committed Apr 26, 2020
2 parents 6326b34 + 41b4fee commit 1f02f16
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
21 changes: 20 additions & 1 deletion E7 Gear Optimizer/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,26 @@ public Data()
skillEnhance.Add(jSkill.Value<int>("Enhance"));
}
}
Heroes.Add(new Hero(id, name, gearList, artifact, lvl, awakening, skillEnhance.Count == 3 ? skillEnhance.ToArray() : null));
try
{
Heroes.Add(new Hero(id, name, gearList, artifact, lvl, awakening, skillEnhance.Count == 3 ? skillEnhance.ToArray() : null));
}
catch (Exception ex)
{
try
{
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\ImportError.txt", ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException?.Message + "\n\n" + ex.InnerException?.StackTrace);
}
catch (Exception e)
{
MessageBox.Show("Could not write file " + AppDomain.CurrentDomain.BaseDirectory + "\\ImportError.txt");
}
DialogResult r = MessageBox.Show("Error importing " + name + ". Check " + AppDomain.CurrentDomain.BaseDirectory + "\\ImportError.txt for the exact error message.\n Do you want to continue importing the rest of your heroes?", "Importing Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (r == DialogResult.No)
{
break;
}
}
if (length == 1)
{
progress.Report(100);
Expand Down
7 changes: 3 additions & 4 deletions E7 Gear Optimizer/Hero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Hero(string ID, string name, List<Item> gear, Item artifact, int lvl, int
}
};
SkillWithSoulburn = Skills.FirstOrDefault(s => s.HasSoulburn) ?? new Skill();
Portrait = getPortrait(name);
Portrait = getPortrait(name, json);
PortraitSmall = Util.ResizeImage(Portrait, 60, 60);
stars = getStars(lvl, awakening);
currentStats = calcStats();
Expand All @@ -94,7 +94,7 @@ public int Awakening
public Dictionary<Stats, float> CurrentStats { get => currentStats; }

//Fetch the portrait of the hero from EpicSevenDB
private Image getPortrait(string name)
private Image getPortrait(string name, string json)
{
Bitmap portrait;
try
Expand All @@ -110,7 +110,6 @@ private Image getPortrait(string name)
}
else
{
string json = loadJson();
portrait = new Bitmap(Util.client.OpenRead(JObject.Parse(json)["results"][0]["assets"]["icon"].ToString()));
if (Properties.Settings.Default.UseCache)
{
Expand Down Expand Up @@ -453,7 +452,7 @@ private string loadJson()
string json = null;
if (Properties.Settings.Default.UseCache && File.Exists(cacheFileName) && System.DateTime.Now.Subtract(File.GetLastWriteTime(cacheFileName)).TotalDays <= Properties.Settings.Default.CacheTimeToLive)
{
json = File.ReadAllText(cacheFileName);
json = File.ReadAllText(cacheFileName, Encoding.UTF8);
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion E7 Gear Optimizer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,10 @@ private void Main_FormClosing(object sender, FormClosingEventArgs e)
}
}
Properties.Settings.Default.Save();

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove("ApiUrl");
config.AppSettings.Settings.Add("ApiUrl", Util.ApiUrl);
config.Save(ConfigurationSaveMode.Full);
}

private JObject createJson()
Expand Down
13 changes: 11 additions & 2 deletions E7 Gear Optimizer/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Drawing.Imaging;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand Down Expand Up @@ -91,14 +93,14 @@ public enum HeroClass
}
public static class Util
{
public static string ApiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"];
public static string ApiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"].Replace("epicsevendb-apiserver.herokuapp.com/api", "api.epicsevendb.com");
public static string GitHubUrl = System.Configuration.ConfigurationManager.AppSettings["GitHubUrl"];
public static string GitHubApiUrl = System.Configuration.ConfigurationManager.AppSettings["GitHubApiUrl"];
public static string ver = System.Configuration.ConfigurationManager.AppSettings["Version"];
public static Bitmap error = Properties.Resources.error;
public static Bitmap star = Properties.Resources.star;
public static Bitmap star_j = Properties.Resources.star_j;
public static WebClient client = new WebClient();
public static WebClient client = createClient();
public static List<string> percentageColumns = new List<string>() {"c_Ilvl", "c_Enhance", "c_Value", "c_ATKPer", "c_ATK", "c_SPD", "c_CHC", "c_CHD", "c_HPPer", "c_HP", "c_DEFPer", "c_DEF", "c_EFF", "c_RES", "c_WSS" };
public static Dictionary<ItemType, List<Stats>> rollableStats = new Dictionary<ItemType, List<Stats>>()
{
Expand All @@ -112,6 +114,13 @@ public static class Util
//Cached value of Set enum length to use in arrays' initializations instead of magic number
public static readonly int SETS_LENGTH = Enum.GetValues(typeof(Set)).Length;

private static WebClient createClient()
{
WebClient c = new WebClient();
c.Encoding = Encoding.UTF8;
return c;
}

public static Bitmap ResizeImage(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
Expand Down

0 comments on commit 1f02f16

Please sign in to comment.