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;
|
2016-02-17 23:49:55 +08:00
|
|
|
|
using System.Reflection;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using System.Windows;
|
2015-11-02 10:49:38 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2015-01-06 18:28:23 +08:00
|
|
|
|
using Wox.Plugin;
|
2016-02-17 23:49:55 +08:00
|
|
|
|
using Wox.Infrastructure.Exception;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
|
2016-01-08 04:04:37 +08:00
|
|
|
|
namespace Wox.Core.Resource
|
2015-01-02 23:07:49 +08:00
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-08 04:04:37 +08:00
|
|
|
|
public static void UpdateResource<T>(T t) where T : Core.Resource.Resource
|
2015-11-02 10:49:38 +08:00
|
|
|
|
{
|
2016-01-07 12:47:28 +08:00
|
|
|
|
RemoveResource(t.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
|
|
|
|
internal static void UpdatePluginLanguages()
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2016-05-19 02:38:43 +08:00
|
|
|
|
RemoveResource(Infrastructure.Constant.Plugins);
|
2016-02-17 23:49:55 +08:00
|
|
|
|
foreach (var plugin in PluginManager.GetPluginsForInterface<IPluginI18n>())
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2016-02-17 23:49:55 +08:00
|
|
|
|
var location = Assembly.GetAssembly(plugin.Plugin.GetType()).Location;
|
|
|
|
|
var directoryName = Path.GetDirectoryName(location);
|
|
|
|
|
if (directoryName != null)
|
2015-01-06 18:28:23 +08:00
|
|
|
|
{
|
2016-02-17 23:49:55 +08:00
|
|
|
|
var internationalization = InternationalizationManager.Instance;
|
|
|
|
|
var folder = Path.Combine(directoryName, internationalization.DirectoryName);
|
|
|
|
|
var file = internationalization.GetLanguageFile(folder);
|
|
|
|
|
if (!string.IsNullOrEmpty(file))
|
|
|
|
|
{
|
|
|
|
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
|
|
|
|
|
{
|
|
|
|
|
Source = new Uri(file, UriKind.Absolute)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new WoxPluginException(plugin.Metadata.Name, "Can't find plugin location.");
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 18:28:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-02 23:07:49 +08:00
|
|
|
|
}
|
2015-01-06 18:28:23 +08:00
|
|
|
|
}
|