Skip to content

Commit

Permalink
Use proper Markdown formatting to display release information in Upda…
Browse files Browse the repository at this point in the history
…teAvailableDialog. Resolves #222.
  • Loading branch information
RevZero committed Mar 26, 2021
1 parent 2cb82ec commit eff1293
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 32 deletions.
26 changes: 20 additions & 6 deletions xcom2-launcher/xcom2-launcher/Classes/Helper/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XCOM2Launcher.Helper {
internal static class Tools {
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(nameof(Tools));

public static void StartProcess(string fileName, string arguments = "")
{
try
Expand All @@ -32,6 +28,24 @@ public static void StartProcess(string fileName, string arguments = "")

}

public static void HandleNavigateWebBrowserControl(object sender, WebBrowserNavigatingEventArgs args)
{
string url = args.Url.ToString();

if (url.Equals("about:blank", System.StringComparison.InvariantCultureIgnoreCase))
{
return;
}

//cancel the current event
args.Cancel = true;

// open URLs in the user's default browser
//Process.Start(e.Url.ToString());
StartProcess(args.Url.ToString());
}


/// <summary>
/// Writes the text <paramref name="content"/> to the file specified in <paramref name="path"/>.
/// Used FileOptions.WriteThrough to write directly to disk.
Expand Down
24 changes: 19 additions & 5 deletions xcom2-launcher/xcom2-launcher/Classes/Mod/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using HeyRed.MarkdownSharp;
using Newtonsoft.Json;
using Steamworks;
using XCOM2Launcher.Helper;
Expand Down Expand Up @@ -428,15 +427,30 @@ public string GetReadMe()

if (File.Exists(readmePathTxt))
{
return File.ReadAllText(readmePathTxt);
string readmeText = File.ReadAllText(readmePathTxt);

if (readmeText.Contains("You created an XCOM 2 Mod Project!"))
{
return "The mod author did not provide additional information.";
}

return readmeText;
}

if (File.Exists(readmePathMd))
{
return File.ReadAllText(readmePathMd);
string readmeText = File.ReadAllText(readmePathMd);

if (readmeText.Contains("Describe specific features of your mod."))
{
return "The mod author did not provide additional information.";
}

return readmeText;
}

return "No ReadMe found."; }
return "No ReadMe found.";
}
catch (Exception ex)
{
return "Unable to access ReadMe file - " + ex.Message;
Expand Down

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

12 changes: 10 additions & 2 deletions xcom2-launcher/xcom2-launcher/Forms/UpdateAvailableDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using HeyRed.MarkdownSharp;
using Semver;
using XCOM2Launcher.GitHub;
using XCOM2Launcher.Helper;
Expand All @@ -18,6 +19,9 @@ public partial class UpdateAvailableDialog : Form
public UpdateAvailableDialog(Release release, SemVersion currentVersion, SemVersion newVersion)
{
InitializeComponent();

releaseNoteBrowser.Navigating += Tools.HandleNavigateWebBrowserControl;

CurrentVersion = currentVersion.ToString();
NewVersion = newVersion.ToString();
Release = release;
Expand All @@ -29,8 +33,12 @@ private void UpdateLabels()
{
version_current_value_label.Text = CurrentVersion;
version_new_value_label.Text = NewVersion;
changelog_textbox.AppendText(Release.name + Environment.NewLine + Environment.NewLine);
changelog_textbox.AppendText(Release.body);

Markdown markdown = new Markdown();
var body = markdown.Transform(Release.body);
changelog_label.Text = Release.name;
releaseNoteBrowser.DocumentText = body;

date_value_label.Text = Release.published_at.ToString(CultureInfo.CurrentCulture);

lBetaVersion.Visible = Release.prerelease;
Expand Down
1 change: 1 addition & 0 deletions xcom2-launcher/xcom2-launcher/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="FCTB" version="2.16.24" targetFramework="net472" />
<package id="GitVersionTask" version="3.6.5" targetFramework="net472" developmentDependency="true" />
<package id="log4net" version="2.0.8" targetFramework="net472" />
<package id="Markdown" version="2.2.1" targetFramework="net472" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net472" />
<package id="ObjectListView.Official" version="2.9.1" targetFramework="net472" />
<package id="Semver" version="2.0.6" targetFramework="net472" />
Expand Down
3 changes: 3 additions & 0 deletions xcom2-launcher/xcom2-launcher/xcom2-launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Markdown, Version=2.0.0.0, Culture=neutral, PublicKeyToken=1b320cc08ad5aa89, processorArchitecture=MSIL">
<HintPath>..\packages\Markdown.2.2.1\lib\net451\Markdown.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down

0 comments on commit eff1293

Please sign in to comment.