Skip to content

Commit

Permalink
fix(UpdatePrompt): unnecessary pagination
Browse files Browse the repository at this point in the history
The Update Prompt unnecessarily added another page even if the
remaining changelog text fits in the last page. The fix is to only
try to find and break at the last newline in case a new page is
actually needed.
  • Loading branch information
Christopher-Marcel Böddecker committed Jul 6, 2017
1 parent ba3930e commit 5113b19
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Assets/VRTK/Editor/VRTK_UpdatePrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,26 @@ public static LatestRelease CreateFromJSON(string json)
const int textLengthLimit = 65536 / 4 - 100;
latestRelease.changelogPages = new List<string>((int)Mathf.Ceil(changelog.Length / (float)textLengthLimit));

while (changelog.Length > 0)
while (true)
{
int lastIndexOf = changelog.LastIndexOf("\n", Math.Min(changelog.Length, textLengthLimit), StringComparison.Ordinal);
if (lastIndexOf == -1)
if (changelog.Length > textLengthLimit)
{
lastIndexOf = changelog.Length;
}
int startIndex = Math.Min(changelog.Length, textLengthLimit);
int lastIndexOf = changelog.LastIndexOf("\n", startIndex, StringComparison.Ordinal);

if (lastIndexOf == -1)
{
lastIndexOf = startIndex;
}

latestRelease.changelogPages.Add(changelog.Substring(0, lastIndexOf));
changelog = changelog.Substring(lastIndexOf).TrimStart('\n', '\r');
latestRelease.changelogPages.Add(changelog.Substring(0, lastIndexOf));
changelog = changelog.Substring(lastIndexOf).TrimStart('\n', '\r');
}
else
{
latestRelease.changelogPages.Add(changelog);
break;
}
}

return latestRelease;
Expand Down

0 comments on commit 5113b19

Please sign in to comment.