Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions package/AgentWindowsManaged/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
using System.IO.Compression;
using System.Linq;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;

using WixSharp;
using WixSharp.CommonTasks;
Expand Down Expand Up @@ -427,33 +425,16 @@ private static void Project_UIInitialized(SetupEventArgs e)
string lcid = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "fr" ? frFR.Key : enUS.Key;

using Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"DevolutionsAgent.Resources.{Languages[lcid]}");
.GetManifestResourceStream($"DevolutionsAgent.Resources.{Languages[lcid]}")
?? throw new FileNotFoundException($"Missing localization resource: {Languages[lcid]}");
using MemoryStream memory = new();
stream.CopyTo(memory);

XmlDocument xml = new();
xml.Load(stream);
InstallerRuntime runtime = e.ManagedUI.Shell.RuntimeContext as InstallerRuntime
?? throw new InvalidOperationException("Managed UI runtime is not available");
runtime.UIText.InitFromWxl(memory.ToArray(), true);

Dictionary<string, string> strings = new();

foreach (XmlNode s in xml.GetElementsByTagName("String"))
{
strings.Add(s.Attributes["Id"].Value, s.InnerText);
}

string I18n(string key)
{
if (!strings.TryGetValue(key, out string result))
{
return key;
}

return Regex.Replace(result, @"\[(.*?)]", (match) =>
{
string property = match.Groups[1].Value;
string value = e.Session[property];

return string.IsNullOrEmpty(value) ? property : value;
});
}
string I18n(string key) => $"[{key}]".LocalizeWith(runtime.Localize);

if (!Environment.Is64BitOperatingSystem)
{
Expand Down
Loading