diff --git a/package/AgentWindowsManaged/Program.cs b/package/AgentWindowsManaged/Program.cs index febd3f055..8b2c5e26d 100644 --- a/package/AgentWindowsManaged/Program.cs +++ b/package/AgentWindowsManaged/Program.cs @@ -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; @@ -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 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) {