a lot of work
This commit is contained in:
@@ -1,98 +1,71 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using System.Text;
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
using ModpackUpdater.Manager;
|
||||
using MsBox.Avalonia;
|
||||
using OfficeOpenXml;
|
||||
using Pilz.UI.WinForms.Extensions;
|
||||
using System.Text;
|
||||
using Telerik.WinControls.UI;
|
||||
using OfficeOpenXml.Table;
|
||||
using Pilz.UI.AvaloniaUI.Dialogs;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features;
|
||||
|
||||
internal static class SharedFunctions
|
||||
{
|
||||
public static bool CheckActionHealthy(IMainApi api, params GridViewRowInfo[] selectedRows)
|
||||
public static async Task<bool> CheckActionHealthy(IMainApi api, params MainWindowGridRow[] rows)
|
||||
{
|
||||
if (api.MainWindow is not MainForm mainForm
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView
|
||||
|| mainForm.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() is not RadWaitingBar rwb)
|
||||
return false;
|
||||
|
||||
rwb.StartWaiting();
|
||||
rwb.ShowText = true;
|
||||
var rowsCount = selectedRows.Length;
|
||||
rwb.Text = "0 / " + rowsCount;
|
||||
gridView.BeginUpdate();
|
||||
|
||||
var rowsCount = rows.Length;
|
||||
var failed = false;
|
||||
var msg = default(string);
|
||||
var factory = new ModpackFactory();
|
||||
|
||||
var rows = new Dictionary<GridViewRowInfo, InstallAction>();
|
||||
for (var i = 0; i < selectedRows.Length; i++)
|
||||
|
||||
for (var i = 0; i < rows.Length; i++)
|
||||
{
|
||||
var row = selectedRows[i];
|
||||
|
||||
if (row.Tag is InstallAction action)
|
||||
var row = rows[i];
|
||||
|
||||
try
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await factory.ResolveSourceUrl(action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
}
|
||||
}).Wait();
|
||||
var result = await factory.ResolveSourceUrl(row.Action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
}
|
||||
|
||||
foreach (var c in row.Cells)
|
||||
{
|
||||
c.Style.CustomizeFill = true;
|
||||
c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen;
|
||||
}
|
||||
|
||||
rwb.Text = $"{i} / {rowsCount}";
|
||||
|
||||
Application.DoEvents();
|
||||
row.IsValid = !failed;
|
||||
|
||||
// rwb.Text = $"{i} / {rowsCount}";
|
||||
}
|
||||
|
||||
gridView.EndUpdate();
|
||||
rwb.ShowText = false;
|
||||
rwb.StopWaiting();
|
||||
|
||||
|
||||
if (rowsCount == 1 && failed && !string.IsNullOrWhiteSpace(msg))
|
||||
MessageBox.Show(msg);
|
||||
|
||||
_ = MessageBoxManager.GetMessageBoxStandard(string.Empty, msg).ShowAsPopupAsync(api.MainWindow);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CollectUpdates(IMainApi api, params InstallAction[] actions)
|
||||
public static async Task<bool> CollectUpdates(IMainApi api, params InstallAction[] actions)
|
||||
{
|
||||
if (api.CurWorkspace?.UpdateInfos is null)
|
||||
if (api.Model.CurrentWorkspace?.UpdateInfos is null || api.Model.CurrentTreeNodes is null)
|
||||
return false;
|
||||
|
||||
// Collect updates
|
||||
var ucDialog = new UpdatesCollectorUi(api.CurWorkspace, actions);
|
||||
if (!ucDialog.ShowDialog(api.MainWindow).IsOk() || ucDialog.CurrentUpdates is null)
|
||||
var result = await AvaloniaFlyoutBase.Show(new UpdatesCollectorView(api.Model.CurrentWorkspace, actions), api.MainWindow);
|
||||
if (result.Result is null || result.CurrentUpdates is null)
|
||||
return false;
|
||||
|
||||
// Collect versions with changes
|
||||
var updates = new List<UpdatesCollectorUi.ModUpdateInfo>();
|
||||
foreach (var update in ucDialog.CurrentUpdates.List)
|
||||
{
|
||||
if (update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Key)
|
||||
updates.Add(update);
|
||||
}
|
||||
var updates = result.CurrentUpdates.List.Where(update => update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Key).ToList();
|
||||
|
||||
// Path install actions
|
||||
foreach (var update in updates)
|
||||
{
|
||||
update.Origin.SourceTag = update.AvailableVersions[update.NewVersion].Key;
|
||||
api.UpdateItem(update.Origin);
|
||||
var sourceTag = update.AvailableVersions[update.NewVersion].Key;
|
||||
if (api.Model.CurrentGridRows?.FirstOrDefault(n => n.Action == update.Origin) is { } row)
|
||||
row.SourceTag = sourceTag;
|
||||
else
|
||||
update.Origin.SourceTag = sourceTag;
|
||||
}
|
||||
|
||||
// Create update actions
|
||||
@@ -104,65 +77,41 @@ internal static class SharedFunctions
|
||||
InheritFrom = update.Origin.Id,
|
||||
});
|
||||
}
|
||||
api.CurWorkspace.UpdateInfos.Updates.Insert(0, updateSet);
|
||||
api.UpdateItem(updateSet);
|
||||
api.Model.CurrentWorkspace.UpdateInfos.Updates.Insert(0, updateSet);
|
||||
|
||||
// Add update to ui
|
||||
api.Model.CurrentTreeNodes[1].Nodes.Add(new ActionSetTreeNode(updateSet));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void FindNewDirectLinks(IMainApi api, params InstallAction[] actions)
|
||||
public static async Task FindNewDirectLinks(params MainWindowGridRow[] rows)
|
||||
{
|
||||
var mainForm = api.MainWindow as MainForm;
|
||||
var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView;
|
||||
var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar;
|
||||
var factory = new ModpackFactory();
|
||||
|
||||
rwb?.StartWaiting();
|
||||
gridView?.BeginUpdate();
|
||||
|
||||
foreach (var action in actions)
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (action.SourceType != SourceType.DirectLink)
|
||||
if (row.SourceType == SourceType.DirectLink)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
action.SourceUrl = await factory.ResolveSourceUrl(action);
|
||||
}).Wait();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Fail silently
|
||||
}
|
||||
api.UpdateItem(action);
|
||||
row.SourceUrl = await factory.ResolveSourceUrl(row.Action);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Fail silently
|
||||
}
|
||||
}
|
||||
|
||||
gridView?.EndUpdate();
|
||||
rwb?.StopWaiting();
|
||||
}
|
||||
|
||||
public static void ClearDirectLinks(IMainApi api, params InstallAction[] actions)
|
||||
public static void ClearDirectLinks(params MainWindowGridRow[] rows)
|
||||
{
|
||||
var mainForm = api.MainWindow as MainForm;
|
||||
var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView;
|
||||
var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar;
|
||||
|
||||
rwb?.StartWaiting();
|
||||
gridView?.BeginUpdate();
|
||||
|
||||
foreach (var action in actions)
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (action.SourceType != SourceType.DirectLink)
|
||||
{
|
||||
action.SourceUrl = null;
|
||||
api.UpdateItem(action);
|
||||
}
|
||||
if (row.SourceType != SourceType.DirectLink)
|
||||
row.SourceUrl = null;
|
||||
}
|
||||
|
||||
gridView?.EndUpdate();
|
||||
rwb?.StopWaiting();
|
||||
}
|
||||
|
||||
public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos)
|
||||
@@ -250,7 +199,7 @@ internal static class SharedFunctions
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
public static ExcelPackage? GenerateModlistAsExcel(InstallInfos installInfos)
|
||||
public static ExcelPackage GenerateModlistAsExcel(InstallInfos installInfos)
|
||||
{
|
||||
var pkg = new ExcelPackage();
|
||||
var ws = pkg.Workbook.Worksheets.Add(string.Format(GeneralLangRes.ModlistForVersionX, installInfos.Version));
|
||||
@@ -301,7 +250,7 @@ internal static class SharedFunctions
|
||||
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.TableStyle = TableStyles.Medium16;
|
||||
tableDef.ShowHeader = true;
|
||||
|
||||
return pkg;
|
||||
|
||||
Reference in New Issue
Block a user