Skip to content

Commit

Permalink
Added: Support for Readme inside Publish Output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Aug 1, 2022
1 parent 88f8072 commit 556a76e
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public class PublishModDialogViewModel : ObservableObject
/// </summary>
public bool AutomaticDelta { get; set; }

/// <summary>
/// Path to the changelog file.
/// </summary>
public string? ChangelogPath { get; set; }

/// <summary>
/// Path to the readme for the file.
/// </summary>
public string? ReadmePath { get; set; }

/// <summary/>
public PublishModDialogViewModel(PathTuple<ModConfig> modTuple)
{
Expand Down Expand Up @@ -146,7 +156,9 @@ await PublishAsync(new PublishArgs()
CompressionMethod = CompressionMethod,
OlderVersionFolders = OlderVersionFolders.Select(x => x.Value).ToList(),
PackageName = PackageName,
MetadataFileName = _modTuple.Config.ReleaseMetadataFileName
MetadataFileName = _modTuple.Config.ReleaseMetadataFileName,
ChangelogPath = ChangelogPath,
ReadmePath = ReadmePath
});
});

Expand Down Expand Up @@ -264,6 +276,16 @@ public void SetOutputFolder()
/// </summary>
public void ShowPublishTutorial() => ProcessExtensions.OpenFileWithDefaultProgram("https://reloaded-project.github.io/Reloaded-II/AddingUpdateSupport");

/// <summary>
/// Lets the user select a new changelog path.
/// </summary>
public void SetChangelogPath() => ChangelogPath = SelectMarkdownFile();

/// <summary>
/// Lets the user select a new readme path.
/// </summary>
public void SetReadmePath() => ReadmePath = SelectMarkdownFile();

private string GetModFolder() => Path.GetDirectoryName(_modTuple.Path)!;

private string SelectConfigFile()
Expand All @@ -278,6 +300,17 @@ private string SelectConfigFile()
return "";
}

private string SelectMarkdownFile()
{
var dialog = new VistaOpenFileDialog();
dialog.Title = Resources.PublishSelectMarkdownTitle.Get();
dialog.Filter = $"{Resources.PublishSelectMarkdownTypeName.Get()}|*.md";
if ((bool)dialog.ShowDialog()!)
return dialog.FileName;

return "";
}

private void RemoveSelectedOrLastItem(StringWrapper? item, ObservableCollection<StringWrapper> allItems)
{
if (item != null)
Expand Down
4 changes: 4 additions & 0 deletions source/Reloaded.Mod.Launcher.Lib/Static/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,8 @@ public static void Init(IDictionaryResourceProvider provider)

public static IDictionaryResource<string> AddAppRepoTestJsonSelectTitle { get; set; }
public static IDictionaryResource<string> AddAppRepoTestJsonSelectFilter { get; set; }

// Update 1.20.0: Extended Publish Menu
public static IDictionaryResource<string> PublishSelectMarkdownTitle { get; set; }
public static IDictionaryResource<string> PublishSelectMarkdownTypeName { get; set; }
}
10 changes: 9 additions & 1 deletion source/Reloaded.Mod.Launcher/Assets/Languages/en-GB.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
<sys:String x:Key="ReloadedProcessNoticeNew">Requires 'Reloaded II Server' Mod to be Enabled w/ LiteNetLib Host.&#x0a;Download it from 'Download Mods' menu.</sys:String>
<sys:String x:Key="ReloadedProcessState">State</sys:String> <!-- Is the mod running or paused? -->

<!-- Update 1.20.0: New Run Dialog -->
<!-- Update 1.20.0: New Wine Run Dialog -->
<sys:String x:Key="WineCompatibilityNoticeTitleNew">Launching from Wine</sys:String>
<sys:String x:Key="WineCompatibilityNoticeHeader_1">You are running Reloaded inside Wine, please note the following:</sys:String>

Expand All @@ -531,4 +531,12 @@

<sys:String x:Key="WineCompatibilityNoticeOkNew">Start Application</sys:String>

<!-- Update 1.20.0: Extended Publish Options -->
<sys:String x:Key="PublishModReadmeSectionTitle">Readme &amp; Changelog</sys:String>
<sys:String x:Key="PublishModReadmeSet">Set Readme File</sys:String>
<sys:String x:Key="PublishModChangelogSet">Set Changelog File</sys:String>

<sys:String x:Key="PublishSelectMarkdownTitle">Select a Markdown File (*.md).</sys:String>
<sys:String x:Key="PublishSelectMarkdownTypeName">Markdown File</sys:String>

</ResourceDictionary>
58 changes: 58 additions & 0 deletions source/Reloaded.Mod.Launcher/Pages/Dialogs/PublishModDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,64 @@

</controls:PopupLabel>

<!-- Readme -->
<controls:PopupLabel ButtonText="{DynamicResource PublishModReadmeSectionTitle}" IsOpen="False" HiddenVisibilityType="Collapsed"
FontSize="{DynamicResource FontSizeRegular}"
Margin="{DynamicResource CommonItemVerticalMarginSmaller}"
FontFamily="{DynamicResource FontLight}">
<controls:PopupLabel.HiddenContent>
<Grid HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

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

<!-- Left Side -->
<TextBlock Text="{Binding ChangelogPath}"
Margin="{DynamicResource CommonItemCombinedMarginSmaller}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Style="{DynamicResource DefaultTextBlock}"
Grid.Column="0"
Grid.Row="0"/>

<TextBlock Text="{Binding ReadmePath}"
Margin="{DynamicResource CommonItemCombinedMarginSmaller}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Style="{DynamicResource DefaultTextBlock}"
Grid.Column="0"
Grid.Row="1"/>

<!-- Right Side -->
<Button Content="{DynamicResource PublishModChangelogSet}"
Click="SetChangelogPath_Click"
Margin="{DynamicResource CommonItemCombinedMarginSmaller}"
Style="{DynamicResource DefaultButton}"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Grid.Column="1"
Grid.Row="0"/>

<Button Content="{DynamicResource PublishModReadmeSet}"
Click="SetReadmePath_Click"
Margin="{DynamicResource CommonItemCombinedMarginSmaller}"
Style="{DynamicResource DefaultButton}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Grid.Column="1"
Grid.Row="1"/>

</Grid>
</controls:PopupLabel.HiddenContent>

</controls:PopupLabel>

<!-- Progress -->
<TextBox Text="{Binding PackageName, UpdateSourceTrigger=PropertyChanged}"
Margin="{DynamicResource CommonItemVerticalMarginSmaller}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ private async void Publish_Click(object sender, System.Windows.RoutedEventArgs e
private void SetOutputFolder_Click(object sender, System.Windows.RoutedEventArgs e) => ViewModel.SetOutputFolder();

private void PublishTutorial_Click(object sender, System.Windows.RoutedEventArgs e) => ViewModel.ShowPublishTutorial();

private void SetChangelogPath_Click(object sender, RoutedEventArgs e) => ViewModel.SetChangelogPath();

private void SetReadmePath_Click(object sender, RoutedEventArgs e) => ViewModel.SetReadmePath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public class ReleaseMetadataExtraData
/// Reserved for future use.
/// </summary>
public string? Changelog { get; set; }

/// <summary>
/// Contains the readme for the package, encoded as markdown.
/// </summary>
public string? Readme { get; set; }
}
8 changes: 8 additions & 0 deletions source/Reloaded.Mod.Loader.Update.Packaging/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public static async Task<ReleaseMetadata> PublishAsync(PublishArgs args)
if (!string.IsNullOrEmpty(args.ChangelogPath))
extraData.Changelog = await File.ReadAllTextAsync(args.ChangelogPath);

if (!string.IsNullOrEmpty(args.ReadmePath))
extraData.Readme = await File.ReadAllTextAsync(args.ReadmePath);

var buildArgs = new BuildArgs()
{
FileName = fileName,
Expand Down Expand Up @@ -209,6 +212,11 @@ public class PublishArgs
/// Path to the changelog to use for this release.
/// </summary>
public string? ChangelogPath { get; set; } = null;

/// <summary>
/// Path to the readme to use for this release.
/// </summary>
public string? ReadmePath { get; set; } = null;
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions source/Tools/Reloaded.Publisher/Options/PublishModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ internal class PublishModOptions

[Option(Required = false, HelpText = "File path to the file containing the changelog for the package, in Markdown format.")]
public string? ChangelogPath { get; set; } = null;

[Option(Required = false, HelpText = "File path to the file containing the readme for the package, in Markdown format. The readme is displayed in the download mods page.")]
public string? ReadmePath { get; set; } = null;
}
}
1 change: 1 addition & 0 deletions source/Tools/Reloaded.Publisher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ await Mod.Loader.Update.Packaging.Publisher.PublishAsync(new Mod.Loader.Update.P
PackageName = options.PackageName,
PublishTarget = options.PublishTarget,
ChangelogPath = options.ChangelogPath,
ReadmePath = options.ReadmePath,
MetadataFileName = config.ReleaseMetadataFileName
});
}
Expand Down

0 comments on commit 556a76e

Please sign in to comment.