diff --git a/src/Plugin.Discord/DiscordPlugin.cs b/src/Plugin.Discord/DiscordPlugin.cs index d882ff20..0dc4fb18 100644 --- a/src/Plugin.Discord/DiscordPlugin.cs +++ b/src/Plugin.Discord/DiscordPlugin.cs @@ -63,16 +63,16 @@ namespace ServerManagerTool.Plugin.Discord { get { - var assembly = PluginHelper.Instance.GetType().Assembly; + var assembly = typeof(PluginHelper).Assembly; if (assembly != null) { var pluginHelperType = assembly.GetType(typeof(PluginHelper).FullName, false, true); if (pluginHelperType != null) { - var field = pluginHelperType.GetProperty("LanguageCode"); - if (field != null) + var property = pluginHelperType.GetProperty(nameof(LanguageCode)); + if (property != null) { - return field.GetValue(PluginHelper.Instance).ToString(); + return property.GetValue(PluginHelper.Instance).ToString(); } } } diff --git a/src/Plugin.Discord/Utils/WindowUtils.cs b/src/Plugin.Discord/Utils/WindowUtils.cs index d8f76b31..239efa66 100644 --- a/src/Plugin.Discord/Utils/WindowUtils.cs +++ b/src/Plugin.Discord/Utils/WindowUtils.cs @@ -1,4 +1,6 @@ -using System.Windows; +using ServerManagerTool.Plugin.Common; +using System.Windows; +using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; @@ -6,6 +8,40 @@ namespace ServerManagerTool.Plugin.Discord { public static class WindowUtils { + public static void UpdateResourceDictionary(Window window, string languageCode) + { + var assembly = typeof(ResourceUtils).Assembly; + if (assembly != null) + { + var resourceUtilsType = assembly.GetType(typeof(ResourceUtils).FullName, false, true); + if (resourceUtilsType != null) + { + var method = resourceUtilsType.GetMethod(nameof(UpdateResourceDictionary), new System.Type[] { typeof(Window), typeof(string) }); + if (method != null) + { + method.Invoke(null, new object[] { window, languageCode }); + } + } + } + } + + public static void UpdateResourceDictionary(UserControl control, string languageCode) + { + var assembly = typeof(ResourceUtils).Assembly; + if (assembly != null) + { + var resourceUtilsType = assembly.GetType(typeof(ResourceUtils).FullName, false, true); + if (resourceUtilsType != null) + { + var method = resourceUtilsType.GetMethod(nameof(UpdateResourceDictionary), new System.Type[] { typeof(UserControl), typeof(string) }); + if (method != null) + { + method.Invoke(null, new object[] { control, languageCode }); + } + } + } + } + /// /// Finds a parent of a given item on the visual tree. /// diff --git a/src/Plugin.Discord/Windows/ConfigProfileWindow.xaml.cs b/src/Plugin.Discord/Windows/ConfigProfileWindow.xaml.cs index 828d5d14..973f1e45 100644 --- a/src/Plugin.Discord/Windows/ConfigProfileWindow.xaml.cs +++ b/src/Plugin.Discord/Windows/ConfigProfileWindow.xaml.cs @@ -23,22 +23,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows internal ConfigProfileWindow(DiscordPlugin plugin, ConfigProfile profile) { InitializeComponent(); - try - { - ResourceUtils.UpdateResourceDictionary(this, plugin.LanguageCode); - } - catch (MissingFieldException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (MissingMethodException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (Exception) - { - // do nothing, most likely they are using an older version of a server manager - } + WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode); this.Plugin = plugin ?? new DiscordPlugin(); this.OriginalProfile = profile; diff --git a/src/Plugin.Discord/Windows/ConfigWindow.xaml.cs b/src/Plugin.Discord/Windows/ConfigWindow.xaml.cs index 263d3b4b..532b89a2 100644 --- a/src/Plugin.Discord/Windows/ConfigWindow.xaml.cs +++ b/src/Plugin.Discord/Windows/ConfigWindow.xaml.cs @@ -21,22 +21,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows internal ConfigWindow(DiscordPlugin plugin, DiscordPluginConfig pluginConfig) { InitializeComponent(); - try - { - ResourceUtils.UpdateResourceDictionary(this, plugin.LanguageCode); - } - catch (MissingFieldException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (MissingMethodException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (Exception) - { - // do nothing, most likely they are using an older version of a server manager - } + WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode); this.Plugin = plugin ?? new DiscordPlugin(); this.PluginConfig = pluginConfig ?? new DiscordPluginConfig(); diff --git a/src/Plugin.Discord/Windows/VersionFeedWindow.xaml.cs b/src/Plugin.Discord/Windows/VersionFeedWindow.xaml.cs index fb579ff7..02dd4198 100644 --- a/src/Plugin.Discord/Windows/VersionFeedWindow.xaml.cs +++ b/src/Plugin.Discord/Windows/VersionFeedWindow.xaml.cs @@ -19,22 +19,7 @@ namespace ServerManagerTool.Plugin.Discord.Windows public VersionFeedWindow(DiscordPlugin plugin, string feedUri) { InitializeComponent(); - try - { - ResourceUtils.UpdateResourceDictionary(this, plugin.LanguageCode); - } - catch (MissingFieldException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (MissingMethodException) - { - // do nothing, most likely they are using an older version of a server manager - } - catch (Exception) - { - // do nothing, most likely they are using an older version of a server manager - } + WindowUtils.UpdateResourceDictionary(this, plugin.LanguageCode); this.Plugin = plugin ?? new DiscordPlugin(); this.feedUri = feedUri;