Skip to content

Commit

Permalink
don't crash when reading invalid json + clean up + again, release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
msarilar committed Nov 6, 2016
1 parent 4b531b4 commit d5e70fd
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 52 deletions.
2 changes: 1 addition & 1 deletion EDEngineer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<value>True</value>
</setting>
<setting name="Version" serializeAs="String">
<value>1.0.0.12</value>
<value>1.0.0.13</value>
</setting>
<setting name="WindowWidth" serializeAs="String">
<value>0</value>
Expand Down
1 change: 0 additions & 1 deletion EDEngineer/Converters/AllFiltersToHeaderConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text;
using System.Windows.Data;
using EDEngineer.Filters;
using EDEngineer.Models;

namespace EDEngineer.Converters
{
Expand Down
2 changes: 2 additions & 0 deletions EDEngineer/EDEngineer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<Compile Include="Filters\IgnoredFavoriteFilter.cs" />
<Compile Include="Filters\IngredientFilter.cs" />
<Compile Include="Models\EntryData.cs" />
<Compile Include="Models\ReleaseNote.cs" />
<Compile Include="ReleaseNotesWindow.xaml.cs">
<DependentUpon>ReleaseNotesWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -234,6 +235,7 @@
</None>
<AppDesigner Include="Properties\" />
<EmbeddedResource Include="Resources\Data\entryData.json" />
<EmbeddedResource Include="Resources\Data\releaseNotes.json" />
<Resource Include="Resources\Fonts\telegrama.otf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
Expand Down
6 changes: 5 additions & 1 deletion EDEngineer/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ internal void LoadState(bool forcePickFolder = false)

private void ApplyEventsToSate(IEnumerable<string> allLogs)
{
var entries = allLogs.Select(l => JsonConvert.DeserializeObject<JournalEntry>(l, journalEntryConverter))
var entries = allLogs.Select(l => JsonConvert.DeserializeObject<JournalEntry>(l, new JsonSerializerSettings()
{
Converters = new List<JsonConverter>() { journalEntryConverter },
Error = (o, e) => e.ErrorContext.Handled = true
}))
.Where(e => e?.Relevant == true)
.OrderBy(e => e.TimeStamp)
.ToList();
Expand Down
4 changes: 1 addition & 3 deletions EDEngineer/Models/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using EDEngineer.Properties;
using EDEngineer.Utils;
Expand Down
2 changes: 2 additions & 0 deletions EDEngineer/Models/JournalEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace EDEngineer.Models
public enum JournalEvent
{
ManualUserChange,
CrewAssign,
CrewHire,
Fileheader,
LoadGame,
Rank,
Expand Down
8 changes: 8 additions & 0 deletions EDEngineer/Models/ReleaseNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EDEngineer.Models
{
public class ReleaseNote
{
public string Version { get; set; }
public string Content { get; set; }
}
}
1 change: 0 additions & 1 deletion EDEngineer/Models/State.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EDEngineer.Utils;
using EDEngineer.Utils.Collections;

namespace EDEngineer.Models
Expand Down
2 changes: 1 addition & 1 deletion EDEngineer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion EDEngineer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Version" Type="System.String" Scope="User">
<Value Profile="(Default)">1.0.0.12</Value>
<Value Profile="(Default)">1.0.0.13</Value>
</Setting>
<Setting Name="WindowWidth" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
Expand Down
4 changes: 2 additions & 2 deletions EDEngineer/ReleaseNotesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
Grid.Row="0">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Item1}" />
<TextBlock Text="{Binding Version}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<!-- this is the body of the TabItem template-->
<DataTemplate>
<Grid Background="AliceBlue">
<TextBlock Text="{Binding Item2}"
<TextBlock Text="{Binding Content}"
Margin="10"
FontSize="14" />
</Grid>
Expand Down
7 changes: 3 additions & 4 deletions EDEngineer/ReleaseNotesWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows;
using MahApps.Metro.Controls;
using EDEngineer.Models;

namespace EDEngineer
{
Expand All @@ -10,7 +9,7 @@ namespace EDEngineer
/// </summary>
public partial class ReleaseNotesWindow
{
public ReleaseNotesWindow(IEnumerable<Tuple<string, string>> list, string title)
public ReleaseNotesWindow(IEnumerable<ReleaseNote> list, string title)
{
InitializeComponent();
Title = title;
Expand Down
51 changes: 51 additions & 0 deletions EDEngineer/Resources/Data/releaseNotes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"Version": "1.0.0.13",
"Content": "Fixed issue which would make the application crash when it would read invalid json outputted by the game"
},
{
"Version": "1.0.0.12",
"Content": "Fixed issue with release notes not showing up"
},
{
"Version": "1.0.0.11",
"Content": "* Working release notes (don't panic if you see \"current version 1.0.0.0\", that's only the first time)\r\n* Favorited blueprints have their ingredients display a little star in your cargo list\r\n* New craftable filter for when only commodities are missing\r\n* Autoselect text when overriding cargo's count (protip: use TAB key to change currently editing entry)\r\n* New filter for ingredients (tick an ingredient to only see blueprints that require it)\r\n* Handle Material Discovery events (issue in Elite Dangerous itself, but I tried to handle it here as best as I could)"
},
{
"Version": "1.0.0.10",
"Content": "Fixed a bug in the monitoring of file with a temporary solution until I find what's wrong with .NET's FileSystemWatcher"
},
{
"Version": "1.0.0.9",
"Content": "* Improve the refresh rate of the data\r\n* Fixed a bug where if you had the zero as hidden, the acquisition of a material would make the application crash"
},
{
"Version": "1.0.0.8",
"Content": "Fix an issue which could make some blueprints not visible in the list"
},
{
"Version": "1.0.0.7",
"Content": "Take synthesis logs into account (they were not before, so if you do synthesis please check your materials)"
},
{
"Version": "1.0.0.6",
"Content": "Added new release notes popup when an update has been installed."
},
{
"Version": "1.0.0.5",
"Content": "* Fixed crash when parsing logs for entries that report material collection without size reported (probably old logs)\r\n* Unlocking the window now make it like a real \"normal\" window (minimize, maximize, appears in taskbar, etc...)\r\n\r\nUnknown materials added:\r\n* uncutfocuscrystals\r\n* fedcorecomposites\r\n* unknownenergysource"
},
{
"Version": "1.0.0.4",
"Content": "* Move/Resize window\r\n* Editable counters"
},
{
"Version": "1.0.0.3",
"Content": "Added missing data:\r\n* Pattern Alpha Obelisk Data\r\n* Pattern Beta Obelisk Data\r\n* Pattern Epsilon Obelisk Data\r\n* Pattern Gamma Obelisk Data\r\n* Pattern Delta Obelisk Data\r\n\r\nAdded missing material:\r\n* Proprietary Composites"
},
{
"Version": "1.0.0.2",
"Content": "2.2 blueprints added"
}
]

29 changes: 22 additions & 7 deletions EDEngineer/Utils/JournalEntryConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -34,28 +33,44 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
JsonSerializer serializer)
{
reader.DateParseHandling = DateParseHandling.None;
var data = JObject.Load(reader);

JObject data;

try
{
data = JObject.Load(reader);
}
catch(JsonReaderException)
{
// malformed json outputted by the game, nothing we can do here
return new JournalEntry();
}

var entry = new JournalEntry
{
TimeStamp = InstantPattern.GeneralPattern.Parse((string)data["timestamp"]).Value,
OriginalJson = data.ToString()
};

JournalEvent journalEvent;
JournalEvent? journalEvent;

try
{
journalEvent = data["event"].ToObject<JournalEvent>(serializer);
journalEvent = data["event"]?.ToObject<JournalEvent>(serializer);
}
catch (JsonSerializationException)
catch (Exception)
{
return entry;
}

if (!journalEvent.HasValue)
{
return entry;
}

try
{
entry.JournalOperation = ExtractOperation(data, journalEvent);
entry.JournalOperation = ExtractOperation(data, journalEvent.Value);
}
catch (Exception e)
{
Expand All @@ -67,7 +82,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

if (entry.JournalOperation != null)
{
entry.JournalOperation.JournalEvent = journalEvent;
entry.JournalOperation.JournalEvent = journalEvent.Value;
}

return entry;
Expand Down
10 changes: 10 additions & 0 deletions EDEngineer/Utils/System/IOManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var file in

public static string RetrieveLogDirectory(bool forcePickFolder, string currentLogDirectory)
{
return @"C:\Users\Max\Documents\download";
string logDirectory = null;

if (!forcePickFolder)
Expand Down Expand Up @@ -214,6 +215,15 @@ public static string GetBlueprintsJson()
}
}

public static string GetReleaseNotesJson()
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EDEngineer.Resources.Data.releaseNotes.json"))
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}

public static string GetEntryDatasJson()
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EDEngineer.Resources.Data.entryData.json"))
Expand Down
32 changes: 2 additions & 30 deletions EDEngineer/Utils/System/ReleaseNotesManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Windows.Forms;
using EDEngineer.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace EDEngineer.Utils.System
{
Expand All @@ -22,31 +18,7 @@ public static void ShowReleaseNotes(string oldVersionString, string newVersionSt

var newVersion = Version.Parse(newVersionString);

string releasesJson = null;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "EDEngineer");
var response = client.GetAsync("https://api.github.com/repos/msarilar/EDEngineer/releases").Result;

if (response.StatusCode == HttpStatusCode.OK)
{
releasesJson = response.Content.ReadAsStringAsync().Result;
}
}

if (releasesJson == null)
{
return;
}

var releases = (JArray)JsonConvert.DeserializeObject(releasesJson);

var releaseNotes =
from release in releases
let releaseVersionString = (string)release["tag_name"]
let releaseVersion = Version.Parse(releaseVersionString)
orderby releaseVersion descending
select Tuple.Create(releaseVersionString, (string) release["body"]);
var releaseNotes = JsonConvert.DeserializeObject<List<ReleaseNote>>(IOManager.GetReleaseNotesJson());

var list = releaseNotes.ToList();
if (list.Any())
Expand Down

0 comments on commit d5e70fd

Please sign in to comment.