Skip to content

Commit

Permalink
Added silent to news properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviuz committed Oct 27, 2019
1 parent 47aab88 commit f4f816a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 14 deletions.
Binary file modified Assemblies/PrisonLabor.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion Source/Core/Meta/VersionUtility.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PrisonLabor.Core.Other;
using PrisonLabor.Core.Windows;

namespace PrisonLabor.Core.Meta
Expand Down Expand Up @@ -27,7 +28,7 @@ public static void CheckVersion()
{
// Show version news
NewsWindow.LastVersionString = GetVersionString(PrisonLaborPrefs.LastVersion);
NewsWindow.AutoShow = true;
NewsWindow.AutoShow = NewsProvider.ShouldAutoShowChangelog(NewsWindow.LastVersionString);

// Dev version fix, it can be removed in future
// There is no changelog for 0.10 so it will skip it, and display all changes
Expand Down
96 changes: 83 additions & 13 deletions Source/Core/Other/NewsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static class NewsProvider
public struct VersionNotes
{
public string version;
public bool? silent;
public string title;
public string[] entries;
}

Expand All @@ -31,7 +33,7 @@ static NewsProvider()

if (iterator < allVersionNotes.Length)
{
allVersionNotes[iterator] = notes;
allVersionNotes[iterator] = Combine(allVersionNotes[iterator], notes);
}
else
{
Expand All @@ -46,6 +48,18 @@ static NewsProvider()
}
}

public static bool ShouldAutoShowChangelog(string lastVersion)
{
for (int i = 0; i < allVersionNotes.Length; i++)
{
if (allVersionNotes[i].version == lastVersion)
return false;
else if (allVersionNotes[i].silent == false)
return true;
}
return false;
}

public static IEnumerable<VersionNotes> NewsAfterVersion(string versionString)
{
bool stop = false;
Expand Down Expand Up @@ -82,8 +96,13 @@ private static IEnumerable<VersionNotes> GetVersionNotesFromChangelog(string tex
{
if (currentPatchNotes.Count > 0)
{
currentPatchNotes.Insert(0, $"[title]Prison Labor v{currentPatch}");
yield return new VersionNotes() { version = currentPatch, entries = currentPatchNotes.ToArray() };
yield return new VersionNotes()
{
version = currentPatch,
silent = true,
title= $"[title]Prison Labor v{currentPatch}",
entries = currentPatchNotes.ToArray()
};
}
currentPatch = line;
currentPatchNotes = new List<string>();
Expand All @@ -93,8 +112,13 @@ private static IEnumerable<VersionNotes> GetVersionNotesFromChangelog(string tex
// Last iteration
if (currentPatchNotes.Count > 0)
{
currentPatchNotes.Insert(0, $"[title]Prison Labor v{currentPatch}");
yield return new VersionNotes() { version = currentPatch, entries = currentPatchNotes.ToArray() };
yield return new VersionNotes()
{
version = currentPatch,
silent = true,
title = $"[title]Prison Labor v{currentPatch}",
entries = currentPatchNotes.ToArray()
};
}
}

Expand All @@ -106,17 +130,63 @@ private static IEnumerable<VersionNotes> GetVersionNotesFromNewsFeed(string xml)
{
if (patch.Name == "patch")
{
var entries = new List<string>();
entries.Add($"[title]{patch["title"].InnerXml}");
foreach (XmlNode item in patch["items"].ChildNodes)
entries.Add(item.InnerXml);
yield return new VersionNotes()
var versionNotes = new VersionNotes();

if(patch.Attributes["version"] != null)
{
versionNotes.version = patch.Attributes["version"].Value;
}
else
{
continue;
}

if (patch["title"] != null)
{
versionNotes.title = $"[title]{patch["title"].InnerXml}";
}
else
{
versionNotes.title = null;
}

if(patch.Attributes["silent"] != null)
{
versionNotes.silent = bool.Parse(patch.Attributes["silent"].Value);
}
else
{
version = patch.Attributes["version"].Value,
entries = entries.ToArray(),
};
versionNotes.silent = null;
}

if (patch["items"] != null)
{
var entries = new List<string>();
foreach (XmlNode item in patch["items"].ChildNodes)
entries.Add(item.InnerXml);
versionNotes.entries = entries.ToArray();
}

yield return versionNotes;
}
}
}

private static VersionNotes Combine(VersionNotes orginal, VersionNotes target)
{
if (target.version != orginal.version)
throw new Exception("Bad news version");

if (target.title != null)
orginal.title = target.title;

if (target.silent != null)
orginal.silent = target.silent;

if (target.entries != null)
orginal.entries = target.entries;

return orginal;
}
}
}
2 changes: 2 additions & 0 deletions Source/Core/Windows/NewsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public void Init()
{
foreach (var patch in NewsProvider.allVersionNotes)
{
entriesList.Add(patch.title);
entriesList.AddRange(patch.entries);
}
}
else
{
foreach (var patch in NewsProvider.NewsAfterVersion(LastVersionString))
{
entriesList.Add(patch.title);
entriesList.AddRange(patch.entries);
}
}
Expand Down

0 comments on commit f4f816a

Please sign in to comment.