add generate modlist feature
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Manager;
|
||||
using OfficeOpenXml;
|
||||
using Pilz.UI.Extensions;
|
||||
using System.Text;
|
||||
using Telerik.WinControls.UI;
|
||||
@@ -209,4 +211,61 @@ internal static class SharedFunctions
|
||||
|
||||
return log.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
public static ExcelPackage? GenerateModlist(InstallInfos installInfos)
|
||||
{
|
||||
var pkg = new ExcelPackage();
|
||||
var ws = pkg.Workbook.Worksheets.Add(GeneralLangRes.Text_Modlist);
|
||||
var cr = 1;
|
||||
var cc = 1;
|
||||
|
||||
// Header
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_Name;
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcTag;
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_Side;
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcType;
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcOwner;
|
||||
ws.Cells[cr, cc++].Value = ActionsListLangRes.Col_SrcName;
|
||||
cr += 1;
|
||||
cc = 1;
|
||||
|
||||
// Rows
|
||||
foreach (var action in installInfos.Actions)
|
||||
{
|
||||
if (action.IsExtra || action.IsZip || string.IsNullOrWhiteSpace(action.Id) || !action.Id.StartsWith("mod:"))
|
||||
continue;
|
||||
|
||||
var cellName = ws.Cells[cr, cc++];
|
||||
cellName.Value = action.Name;
|
||||
if (!string.IsNullOrWhiteSpace(action.Website))
|
||||
cellName.SetHyperlink(new Uri(action.Website));
|
||||
|
||||
var cellTag = ws.Cells[cr, cc++];
|
||||
cellTag.Value = action.SourceTag;
|
||||
if (!string.IsNullOrWhiteSpace(action.SourceUrl))
|
||||
cellTag.SetHyperlink(new Uri(action.SourceUrl));
|
||||
|
||||
ws.Cells[cr, cc++].Value = action.Side.ToString();
|
||||
ws.Cells[cr, cc++].Value = action.SourceType;
|
||||
ws.Cells[cr, cc++].Value = action.SourceOwner;
|
||||
ws.Cells[cr, cc++].Value = action.SourceName;
|
||||
|
||||
cr += 1;
|
||||
cc = 1;
|
||||
}
|
||||
|
||||
// Styling
|
||||
cc = 1;
|
||||
ws.Column(cc++).Width = 30;
|
||||
ws.Column(cc++).Width = 15;
|
||||
ws.Column(cc++).Width = 10;
|
||||
ws.Column(cc++).Width = 20;
|
||||
ws.Column(cc++).Width = 20;
|
||||
ws.Column(cc++).Width = 30;
|
||||
var tableDef = ws.Tables.Add(ws.Cells[1, 1, cr - 1, cc - 1], "Table");
|
||||
tableDef.TableStyle = OfficeOpenXml.Table.TableStyles.Medium16;
|
||||
tableDef.ShowHeader = true;
|
||||
|
||||
return pkg;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using OfficeOpenXml;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Telerik.WinControls;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features.Tools;
|
||||
internal class GenerateModlistFeature : PluginFunction, IPluginFeatureProvider<GenerateModlistFeature>
|
||||
{
|
||||
public static GenerateModlistFeature Instance { get; } = new();
|
||||
|
||||
public GenerateModlistFeature() : base(FeatureTypes.Tools, "origin.genmodlist", FeatureNamesLangRes.GenerateModlistFeature)
|
||||
{
|
||||
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.list_view, Pilz.UI.Symbols.SymbolSize.Small);
|
||||
}
|
||||
|
||||
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null || p.Api.CurWorkspace?.InstallInfos is null)
|
||||
return null;
|
||||
|
||||
using var pkg = SharedFunctions.GenerateModlist(p.Api.CurWorkspace.InstallInfos);
|
||||
if (pkg is null)
|
||||
return null;
|
||||
|
||||
using var sfd = new RadSaveFileDialog
|
||||
{
|
||||
Filter = "*.xlsx|*.xlsx|*|*"
|
||||
};
|
||||
|
||||
if (sfd.ShowDialog(p.Api.MainWindow) == DialogResult.OK)
|
||||
{
|
||||
pkg.SaveAs(sfd.FileName);
|
||||
RadMessageBox.Show(p.Api.MainWindow, MsgBoxLangRes., MsgBoxLangRes., MessageBoxButtons.OK, RadMessageIcon.Info);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user