update client gui

This commit is contained in:
Pilzinsel64
2024-06-24 09:04:20 +02:00
parent d0048e008d
commit ebd9fb90da
16 changed files with 606 additions and 984 deletions

View File

@@ -1,18 +1,29 @@
using Pilz.Updating.GUIBase;
using Pilz.UI.Telerik;
using Pilz.UI.Telerik.Dialogs;
using Pilz.Updating.GUIBase;
using Telerik.WinControls.UI;
namespace Pilz.Updating.Client.GUI;
internal partial class UpdatesAvailableDialog
internal partial class UpdatesAvailableDialog : RadFlyoutBase
{
public UpdatesAvailableDialog(Image appIcon, string curVersion, string curChannel, string curBuild, string newVersion, string newChannel, string newBuild, UpdateNotes updateNotes, bool installAsAdmin)
{
InitializeComponent();
ActionPanelVisible = false;
radButton_Cancel.SvgImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.software_installer, SvgImageSize.Small);
if (installAsAdmin)
radButton_Install.Image = BaseFeatures.GetUacShieldImage();
else
radButton_Install.SvgImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.software_installer, SvgImageSize.Small);
if (appIcon == null)
radPictureBox1.SvgImage = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.software_installer, SvgImageSize.Large);
else
radPictureBox1.Image = appIcon;
radPictureBox1.Image = appIcon ?? Icon.ToBitmap();
radLabel_CurrentVersion.Text = curVersion;
radLabel_CurrentVersionChannel.Text = curChannel;
radLabel_CurrentVersionBuild.Text = curBuild;
@@ -20,34 +31,85 @@ internal partial class UpdatesAvailableDialog
radLabel_AvailableVersionChannel.Text = newChannel;
radLabel_AvailableVersionBuild.Text = newBuild;
// Update Notes
Control updateNotesControl = null;
switch (updateNotes.ContentType)
SetNotes(updateNotes);
}
private void SetNotes(UpdateNotes updateNotes)
{
// Internal
if (updateNotes.Mode == UpdateNotesMode.Internal && !string.IsNullOrWhiteSpace(updateNotes.ContentUrl) && TryDownloadContent(updateNotes.ContentUrl) is string content)
{
case UpdateNotesContentType.PlainText:
var newUpdateNotesControl = new RadRichTextEditor
{
Text = updateNotes.Content
};
updateNotesControl = newUpdateNotesControl;
break;
case UpdateNotesContentType.Markdown:
updateNotesControl = new Westermo.HtmlRenderer.WinForms.HtmlPanel
{
Text = Markdig.Markdown.ToHtml(updateNotes.Content)
};
break;
case UpdateNotesContentType.HTML:
updateNotesControl = new Westermo.HtmlRenderer.WinForms.HtmlPanel
{
Text = updateNotes.Content
};
break;
switch (updateNotes.ContentType)
{
case UpdateNotesContentType.PlainText:
SetNotesControls(new RadRichTextEditor
{
Text = content
});
return;
case UpdateNotesContentType.Markdown:
SetNotesControls(new Westermo.HtmlRenderer.WinForms.HtmlPanel
{
Text = Markdig.Markdown.ToHtml(content)
});
return;
case UpdateNotesContentType.HTML:
SetNotesControls(new Westermo.HtmlRenderer.WinForms.HtmlPanel
{
Text = content
});
return;
}
}
if (updateNotesControl is not null)
// External
if (updateNotes.Mode == UpdateNotesMode.External && !string.IsNullOrWhiteSpace(updateNotes.ExternalUrl))
{
updateNotesControl.Dock = DockStyle.Fill;
panel_ChangelogPanel.Controls.Add(updateNotesControl);
var label = new RadLabel
{
AutoSize = false,
Text = string.Format(LangRes.NotesLinkToExternal, updateNotes.ExternalUrl),
TextAlignment = ContentAlignment.MiddleCenter,
};
SetNotesControls(label);
return;
}
// None or not supported or fallback
SetNotesControls(new RadLabel
{
AutoSize = false,
Text = LangRes.NotesNotAvailable,
TextAlignment = ContentAlignment.MiddleCenter,
});
return;
}
private void SetNotesControls(Control updateNotesControl)
{
updateNotesControl.Dock = DockStyle.Fill;
panel_ChangelogPanel.Controls.Add(updateNotesControl);
}
private static string TryDownloadContent(string contentUrl)
{
try
{
return new HttpClient().GetStringAsync(contentUrl).Result;
}
catch
{
}
return null;
}
private void RadButton_Install_Click(object sender, EventArgs e)
{
Close(DialogResult.OK);
}
private void RadButton_Cancel_Click(object sender, EventArgs e)
{
Close(DialogResult.Cancel);
}
}