Skip to content

Commit

Permalink
Support Markdown Rendering & Update Changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jun 15, 2020
1 parent f2db8df commit 384eb28
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 18 deletions.
1 change: 1 addition & 0 deletions Source/Reloaded.Mod.Launcher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ResourceDictionary Source="Styles/Settings.xaml"/>
<ResourceDictionary Source="Styles/Controls.xaml"/>
<ResourceDictionary Source="Styles/Window_Settings.xaml"/>
<ResourceDictionary Source="Styles/Markdown.xaml"/>
<ResourceDictionary Source="Languages/en-GB.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
3 changes: 2 additions & 1 deletion Source/Reloaded.Mod.Launcher/Languages/en-GB.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
<sys:String x:Key="UpdateLoaderCurrentVersion">Current Version</sys:String>
<sys:String x:Key="UpdateLoaderNewVersion">New Version</sys:String>

<sys:String x:Key="UpdateLoaderChangelog">View Changelog</sys:String>
<sys:String x:Key="UpdateLoaderChangelogUnavailable">No Changelog Available</sys:String>
<sys:String x:Key="UpdateLoaderChangelog">View Changelog on Github</sys:String>
<sys:String x:Key="UpdateLoaderUpdate">Update</sys:String>

<sys:String x:Key="UpdateLoaderRunningTitle">Applications Running</sys:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:default="clr-namespace:Reloaded.WPF.Theme.Default;assembly=Reloaded.WPF.Theme.Default"
xmlns:converters="clr-namespace:Reloaded.Mod.Launcher.Converters"
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
mc:Ignorable="d"
MinHeight="10"
MinWidth="10"
Expand All @@ -14,13 +15,19 @@
WindowStartupLocation="CenterScreen"
Title="{DynamicResource UpdateLoaderTitle}"
Style="{DynamicResource ReloadedWindow}">

<Grid Margin="{DynamicResource PageMarginSmall}" DataContext="{Binding Path=ViewModel, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}">

<Grid.CommandBindings>
<CommandBinding Command="{x:Static markdig:Commands.Hyperlink}" Executed="OpenHyperlink" />
</Grid.CommandBindings>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<!-- Progress Bar -->
Expand All @@ -44,8 +51,15 @@
</DockPanel>
</Grid>

<!-- Changelog -->
<markdig:MarkdownViewer Grid.Row="3" Margin="{DynamicResource CommonItemVerticalMarginSmaller}"
MaxHeight="280" MaxWidth="650"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
Markdown="{Binding ReleaseText, FallbackValue='No Changelog Available'}" />

<!-- Final Buttons -->
<Grid Grid.Row="3" Margin="{DynamicResource CommonItemVerticalMarginSmaller}">
<Grid Grid.Row="4" Margin="{DynamicResource CommonItemVerticalMarginSmaller}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="{DynamicResource UpdateModsMenuMargin}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using Octokit;
using Onova;
using Reloaded.Mod.Launcher.Utility;
using Reloaded.Mod.Shared;
using Reloaded.WPF.MVVM;
using Reloaded.WPF.Theme.Default;
using Reloaded.WPF.Utilities;
Expand Down Expand Up @@ -36,17 +40,21 @@ private async void UpdateClick(object sender, RoutedEventArgs e)
{
await ViewModel.Update();
}

private void OpenHyperlink(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) => ProcessExtensions.OpenFileWithDefaultProgram(e.Parameter.ToString());
}

public class ModLoaderUpdateDialogViewModel : ObservableObject
{
private static XamlResource<string> _xamlUpdateLoaderRunningTitle = new XamlResource<string>("UpdateLoaderRunningTitle");
private static XamlResource<string> _xamlUpdateLoaderRunningMessage = new XamlResource<string>("UpdateLoaderRunningMessage");
private static XamlResource<string> _xamlUpdateLoaderProcessList = new XamlResource<string>("UpdateLoaderProcessList");
private static XamlResource<string> _xamlUpdateLoaderChangelogUnavailable = new XamlResource<string>("UpdateLoaderChangelogUnavailable");

public int Progress { get; set; }
public string CurrentVersion { get; set; }
public string NewVersion { get; set; }
public string ReleaseText { get; set; } = _xamlUpdateLoaderChangelogUnavailable.Get();

private UpdateManager _manager;
private Version _targetVersion;
Expand All @@ -57,7 +65,17 @@ public ModLoaderUpdateDialogViewModel(UpdateManager manager, Version targetVersi
_targetVersion = targetVersion;

CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
NewVersion = _targetVersion.ToString();
NewVersion = _targetVersion.ToString();

// Try fetch Release info.
try
{
var client = new GitHubClient(new ProductHeaderValue("Reloaded-II"));
var releases = client.Repository.Release.GetAll(SharedConstants.GitRepositoryAccount, SharedConstants.GitRepositoryName);
var release = releases.Result.First(x => x.TagName.Contains(targetVersion.ToString()));
ReleaseText = release.Body;
}
catch (Exception ex) { /* Ignored */ }
}

public async Task Update()
Expand Down
8 changes: 7 additions & 1 deletion Source/Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<AssemblyName>Reloaded-II</AssemblyName>
<RootNamespace>Reloaded.Mod.Launcher</RootNamespace>
<Version>1.5.4</Version>
<Version>1.6.0</Version>
<Copyright>Sewer56 ~ $([System.DateTime]::UtcNow.Year) | Build: $([System.DateTime]::UtcNow.ToString("s"))</Copyright>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ApplicationIcon>appicon.ico</ApplicationIcon>
Expand Down Expand Up @@ -57,6 +57,7 @@
<Page Remove="Languages\ru-RU.xaml" />
<Page Remove="Languages\tr-TR.xaml" />
<Page Remove="Styles\Controls.xaml" />
<Page Remove="Styles\Markdown.xaml" />
<Page Remove="Styles\Settings.xaml" />
<Page Remove="Styles\Window_Settings.xaml" />
</ItemGroup>
Expand Down Expand Up @@ -102,6 +103,10 @@
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Styles\Markdown.xaml">
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Styles\Settings.xaml">
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -114,6 +119,7 @@

<ItemGroup>
<PackageReference Include="gong-wpf-dragdrop" Version="2.2.0" />
<PackageReference Include="Markdig.Wpf" Version="0.3.1" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.3.0" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="Octokit" Version="0.47.0" />
Expand Down
116 changes: 116 additions & 0 deletions Source/Reloaded.Mod.Launcher/Styles/Markdown.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Reloaded.Mod.Launcher.Styles"
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
xmlns:controls="clr-namespace:Reloaded.WPF.Controls;assembly=Reloaded.WPF">

<!-- For IntelliSense: Uncomment only when editing. -->
<ResourceDictionary.MergedDictionaries>
<controls:DesignTimeResourceDictionary RunTimeSource="pack://siteoforigin:,,,/Theme/Default/Root.xaml" DesignTimeSource="pack://application:,,,/Reloaded.WPF.Theme.Default;component/Theme/Default/Root.xaml"/>
<controls:DesignTimeResourceDictionary RunTimeSource="pack://siteoforigin:,,,/Styles/Settings.xaml" DesignTimeSource="pack://application:,,,/Reloaded.Mod.Launcher;component/Styles/Settings.xaml"/>
</ResourceDictionary.MergedDictionaries>

<!-- Document styles -->
<Style TargetType="{x:Type FlowDocument}" x:Key="{x:Static markdig:Styles.DocumentStyleKey}">
<Setter Property="ScrollViewer.Visibility" Value="Hidden"/>
<Setter Property="Background" Value="{DynamicResource BackgroundColorBrush}"/>
<Setter Property="FontFamily" Value="{DynamicResource FontLight}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeSmaller}" />
<Setter Property="Foreground" Value="{StaticResource TextColorBrush}"/>
<Setter Property="LineHeight" Value="{DynamicResource FontSizeSmaller}"/>
</Style>

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading1StyleKey}">
<Setter Property="FontFamily" Value="{DynamicResource FontThin}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeLargest}" />
</Style>

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading2StyleKey}">
<Setter Property="FontFamily" Value="{DynamicResource FontThin}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeLarger}" />
</Style>

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading3StyleKey}">
<Setter Property="FontFamily" Value="{DynamicResource FontThin}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeRegular}" />
</Style>

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading4StyleKey}">
<Setter Property="FontFamily" Value="{DynamicResource FontThin}" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeSmall}" />
</Style>

<Style TargetType="{x:Type Hyperlink}" x:Key="{x:Static markdig:Styles.HyperlinkStyleKey}">
<Setter Property="Foreground" Value="{DynamicResource AccentColorLightestBrush}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource AccentColorLighterBrush}" />
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="{x:Type Image}" x:Key="{x:Static markdig:Styles.ImageStyleKey}">
<Setter Property="MaxHeight" Value="{Binding RelativeSource={RelativeSource Self}, Path=Source.(BitmapSource.PixelHeight)}" />
<Setter Property="MaxWidth" Value="{Binding RelativeSource={RelativeSource Self}, Path=Source.(BitmapSource.PixelWidth)}" />
</Style>

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.CodeBlockStyleKey}">
<Setter Property="FontFamily" Value="Consolas, Lucida Sans Typewriter, Courier New" />
<Setter Property="Background" Value="{DynamicResource BorderColorDarkBrush}"/>
</Style>

<Style TargetType="{x:Type Run}" x:Key="{x:Static markdig:Styles.CodeStyleKey}">
<Setter Property="FontFamily" Value="Consolas, Lucida Sans Typewriter, Courier New" />
</Style>

<Style TargetType="{x:Type Section}" x:Key="{x:Static markdig:Styles.QuoteBlockStyleKey}">
<Setter Property="BorderBrush" Value="{DynamicResource BorderColorBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource MarkdownBlockQuoteThickness}" />
<Setter Property="Foreground" Value="{DynamicResource MarkdownBlockQuoteTextColor}" />
<Setter Property="Padding" Value="{DynamicResource MarkdownBlockQuotePadding}" />
</Style>

<Style TargetType="{x:Type Table}" x:Key="{x:Static markdig:Styles.TableStyleKey}">
<Setter Property="CellSpacing" Value="{DynamicResource MarkdownCellPadding}"/>
</Style>

<Style TargetType="{x:Type TableCell}" x:Key="{x:Static markdig:Styles.TableCellStyleKey}"/>
<Style TargetType="{x:Type TableRow}" x:Key="{x:Static markdig:Styles.TableHeaderStyleKey}"/>

<Style TargetType="{x:Type CheckBox}" x:Key="{x:Static markdig:Styles.TaskListStyleKey}">
<Setter Property="Margin" Value="0,0,0,-2" />
</Style>

<Style TargetType="{x:Type Line}" x:Key="{x:Static markdig:Styles.ThematicBreakStyleKey}">
<Setter Property="Stretch" Value="Fill" />
<Setter Property="Stroke" Value="{DynamicResource BorderColorBrush}" />
</Style>

<Style TargetType="{x:Type Span}" x:Key="{x:Static markdig:Styles.SubscriptStyleKey}">
<Setter Property="Typography.Variants" Value="Subscript" />
</Style>

<Style TargetType="{x:Type Span}" x:Key="{x:Static markdig:Styles.SuperscriptStyleKey}">
<Setter Property="Typography.Variants" Value="Superscript" />
</Style>

<Style TargetType="{x:Type Span}" x:Key="{x:Static markdig:Styles.StrikeThroughStyleKey}">
<Setter Property="TextBlock.TextDecorations" Value="Strikethrough" />
</Style>

<Style TargetType="{x:Type Span}" x:Key="{x:Static markdig:Styles.InsertedStyleKey}">
<Setter Property="TextBlock.TextDecorations" Value="Underline" />
</Style>

<Style TargetType="markdig:MarkdownViewer">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="markdig:MarkdownViewer">
<FlowDocumentScrollViewer Document="{TemplateBinding Document}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
5 changes: 5 additions & 0 deletions Source/Reloaded.Mod.Launcher/Styles/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
<system:Int32 x:Key="RefreshApplicationsEventTickTimer">100</system:Int32> <!-- All application list refresh events are gathered in this interval and only last executed at the end of it. -->
<system:Int32 x:Key="RefreshModsEventTickTimer">100</system:Int32> <!-- All mod list refresh events are gathered in this interval and only last executed at the end of it. -->

<!-- Markdown Displayer -->
<system:Double x:Key="MarkdownCellPadding">5</system:Double>
<SolidColorBrush x:Key="MarkdownBlockQuoteTextColor">Gray</SolidColorBrush>
<Thickness x:Key="MarkdownBlockQuoteThickness">4,0,0,0</Thickness>
<Thickness x:Key="MarkdownBlockQuotePadding">16,0,0,0</Thickness>

</ResourceDictionary>
4 changes: 3 additions & 1 deletion Source/Reloaded.Mod.Launcher/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
using Reloaded.Mod.Loader.IO.Structs;
using Reloaded.Mod.Loader.Update;
using Reloaded.Mod.Loader.Update.Extractors;
using Reloaded.Mod.Loader.Update.Resolvers;
using Reloaded.Mod.Loader.Update.Utilities;
using Reloaded.Mod.Shared;
using Reloaded.WPF.Utilities;
using MessageBox = System.Windows.MessageBox;

Expand All @@ -37,7 +39,7 @@ public static async Task CheckForLoaderUpdatesAsync()
try
{
using (var manager = new UpdateManager(
new GithubPackageResolver("Reloaded-Project", "Reloaded-II", "Release.zip"),
new GithubPackageResolver(SharedConstants.GitRepositoryAccount, SharedConstants.GitRepositoryName, SharedConstants.GitRepositoryReleaseName),
new ArchiveExtractor()))
{
// Check for new version and, if available, perform full update and restart
Expand Down
13 changes: 0 additions & 13 deletions Source/Reloaded.Mod.Loader.Update/Utilities/VersionHelpers.cs

This file was deleted.

4 changes: 4 additions & 0 deletions Source/Reloaded.Mod.Shared/SharedConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ public class SharedConstants
public const string Kernel32AddressDumperMemoryMappedFileName = "Reloaded-II-GetProcAddress32";
public const string NuGetApiEndpoint = "http://167.71.128.50:5000/v3/index.json";
public const string NuGetApiWebsite = "http://167.71.128.50:5000/home";

public const string GitRepositoryAccount = "Reloaded-Project";
public const string GitRepositoryName = "Reloaded-II";
public const string GitRepositoryReleaseName = "Release.zip";
}
}

0 comments on commit 384eb28

Please sign in to comment.