2015-01-02 23:07:49 +08:00
|
|
|
|
using System;
|
2015-11-29 14:29:32 +08:00
|
|
|
|
using System.IO;
|
2015-11-02 10:49:38 +08:00
|
|
|
|
using System.Linq;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using Wox.Core.i18n;
|
2015-11-02 10:49:38 +08:00
|
|
|
|
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.UI
|
|
|
|
|
{
|
2015-11-02 10:49:38 +08:00
|
|
|
|
public static class ResourceMerger
|
2015-01-02 23:07:49 +08:00
|
|
|
|
{
|
2015-11-29 14:29:32 +08:00
|
|
|
|
private static void RemoveResource(string directoryName)
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2015-11-29 14:29:32 +08:00
|
|
|
|
directoryName = $"{Path.DirectorySeparatorChar}{directoryName}";
|
|
|
|
|
var dictionaries = Application.Current.Resources.MergedDictionaries;
|
|
|
|
|
foreach (var resource in dictionaries)
|
2015-11-02 10:49:38 +08:00
|
|
|
|
{
|
2015-11-29 14:29:32 +08:00
|
|
|
|
string currentDirectoryName = Path.GetDirectoryName(resource.Source.AbsolutePath);
|
|
|
|
|
if (currentDirectoryName == directoryName)
|
2015-11-02 10:49:38 +08:00
|
|
|
|
{
|
2015-11-29 14:29:32 +08:00
|
|
|
|
dictionaries.Remove(resource);
|
2015-11-02 10:49:38 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-29 14:29:32 +08:00
|
|
|
|
public static void UpdateResource(Theme.Theme t)
|
2015-11-02 10:49:38 +08:00
|
|
|
|
{
|
|
|
|
|
RemoveResource(Theme.Theme.DirectoryName);
|
2015-11-02 21:42:52 +08:00
|
|
|
|
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
|
2015-11-02 10:49:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-29 14:29:32 +08:00
|
|
|
|
public static void UpdateResources(Internationalization i)
|
2015-11-02 10:49:38 +08:00
|
|
|
|
{
|
|
|
|
|
RemoveResource(Internationalization.DirectoryName);
|
2015-11-02 21:42:52 +08:00
|
|
|
|
Application.Current.Resources.MergedDictionaries.Add(i.GetResourceDictionary());
|
2015-01-02 23:07:49 +08:00
|
|
|
|
}
|
2015-01-06 18:28:23 +08:00
|
|
|
|
|
2015-11-29 14:29:32 +08:00
|
|
|
|
internal static void UpdatePluginLanguages()
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2015-11-02 10:49:38 +08:00
|
|
|
|
RemoveResource(PluginManager.DirectoryName);
|
2015-11-06 04:44:14 +08:00
|
|
|
|
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
|
|
|
|
{
|
2015-11-02 21:42:52 +08:00
|
|
|
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2015-11-02 21:42:52 +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
|
|
|
|
}
|