PowerToys/Wox.Core/Resource/ResourceMerger.cs

47 lines
1.6 KiB
C#
Raw Normal View History

2015-01-02 23:07:49 +08:00
using System;
using System.IO;
using System.Linq;
2015-01-02 23:07:49 +08:00
using System.Windows;
using Wox.Core.Plugin;
2015-01-06 18:28:23 +08:00
using Wox.Plugin;
2015-01-02 23:07:49 +08:00
namespace Wox.Core.Resource
2015-01-02 23:07:49 +08:00
{
public static class ResourceMerger
2015-01-02 23:07:49 +08:00
{
private static void RemoveResource(string directoryName)
2015-01-06 18:28:23 +08:00
{
directoryName = $"{Path.DirectorySeparatorChar}{directoryName}";
var dictionaries = Application.Current.Resources.MergedDictionaries;
foreach (var resource in dictionaries)
{
string currentDirectoryName = Path.GetDirectoryName(resource.Source.AbsolutePath);
if (currentDirectoryName == directoryName)
{
dictionaries.Remove(resource);
break;
}
}
}
public static void UpdateResource<T>(T t) where T : Core.Resource.Resource
{
RemoveResource(t.DirectoryName);
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
}
internal static void UpdatePluginLanguages()
2015-01-06 18:28:23 +08:00
{
RemoveResource(PluginManager.DirectoryName);
foreach (var languageFile in PluginManager.GetPluginsForInterface<IPluginI18n>().
2015-11-03 02:52:34 +08:00
Select(plugin => InternationalizationManager.Instance.GetLanguageFile(((IPluginI18n)plugin.Plugin).GetLanguagesFolder())).
2015-11-03 06:15:06 +08:00
Where(file => !string.IsNullOrEmpty(file)))
2015-01-06 18:28:23 +08:00
{
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
2015-01-06 18:28:23 +08:00
{
Source = new Uri(languageFile, UriKind.Absolute)
});
2015-01-06 18:28:23 +08:00
}
}
2015-01-02 23:07:49 +08:00
}
2015-01-06 18:28:23 +08:00
}