示例#1
0
        private void UpdateIcon()
        {
            if (Locker.IsActive)
            {
                return;
            }

            var path = Model.Path.ToLower();

            if (!string.IsNullOrWhiteSpace(Model.SourceXaml))
            {
                _icons.AddIconProvider(path, new IconProviderXamlFromSource(Model.SourceXaml, path, Model.Foreground));
            }
            else if (!string.IsNullOrWhiteSpace(Model.SourceSvg))
            {
                _icons.AddIconProvider(path, new IconProviderSvgFromSource(Model.SourceSvg, path, Model.Foreground));
            }
        }
示例#2
0
        public void Load(IBootContext b)
        {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(e => !e.IsDynamic))
            {
                try
                {
                    var v = assembly.GetCustomAttribute <AssemblyCompanyAttribute>();
                    if (v?.Company == "Microsoft Corporation")
                    {
                        continue;
                    }

                    var resourceManager = new ResourceManager(assembly.GetName().Name + ".g", assembly);
                    var resources       = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                    foreach (var rkey in resources)
                    {
                        var r = ((DictionaryEntry)rkey).Key.ToString().ToLower();

                        var resourcePath = r.Replace(assembly.ManifestModule.Name.Replace(".exe", "") + ".", "");
                        if (resourcePath.EndsWith(".xaml"))
                        {
                            var n = resourcePath.Remove(resourcePath.Length - 5);
                            _icons.AddIconProvider(n, new IconProviderXamlFromResource(resourceManager, resourcePath));
                        }
                        else if (resourcePath.EndsWith(".svg"))
                        {
                            var n = resourcePath.Remove(resourcePath.Length - 4);
                            _icons.AddIconProvider(n, new IconProviderSvg(resourceManager, resourcePath));
                        }
                        else if (resourcePath.EndsWith(".baml"))
                        {
                            var n = resourcePath.Remove(resourcePath.Length - 5);
                            _icons.AddIconProvider(n, new IconProviderXamlFromUri(new Uri("/" + assembly.FullName + ";component/" + n + ".xaml", UriKind.Relative)));
                        }
                    }
                }
                catch (System.Resources.MissingManifestResourceException ex)
                {
                }
            }
        }
示例#3
0
        public async void LoadAsync()
        {
            var icons = _data.FetchAsync <Icon>().ConfigureAwait(true);

            try
            {
                await foreach (var icon in icons)
                {
                    var path = icon.Path.ToLower();

                    if (!string.IsNullOrWhiteSpace(icon.SourceXaml))
                    {
                        _icons.AddIconProvider(path, new IconProviderXamlFromSource(icon.SourceXaml, path, icon.Foreground));
                    }
                    else if (!string.IsNullOrWhiteSpace(icon.SourceSvg))
                    {
                        _icons.AddIconProvider(path, new IconProviderSvgFromSource(icon.SourceSvg, path, icon.Foreground));
                    }
                }
            }
            catch (DataException)
            {
            }
        }
示例#4
0
        public void Load(IBootContext b)
        {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(e => !e.IsDynamic))
            {
                try
                {
                    var v = assembly.GetCustomAttribute <AssemblyCompanyAttribute>();
                    if (v?.Company == "Microsoft Corporation")
                    {
                        continue;
                    }

                    var resourceManager = new ResourceManager(assembly.GetName().Name + ".g", assembly);
                    var resources       = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
                    foreach (var rkey in resources)
                    {
                        var r = ((DictionaryEntry)rkey).Key.ToString().ToLower();

                        var resourcePath = r.Replace(assembly.ManifestModule.Name.Replace(".exe", "") + ".", "");

                        resourcePath = Uri.UnescapeDataString(resourcePath);


                        if (resourcePath.EndsWith(".xaml"))
                        {
                            var resource = resourcePath.Split('/');
                            var path     = string.Join('/', resource.SkipLast(1));

                            foreach (var n in resource.Last().Split('.').SkipLast(1))
                            {
                                _icons.AddIconProvider(string.Join('/', path, n), new IconProviderXamlFromResource(resourceManager, resourcePath, Colors.Black));
                            }
                        }
                        else if (resourcePath.EndsWith(".svg"))
                        {
                            var resource = resourcePath.Split('/');
                            var path     = string.Join('/', resource.SkipLast(1));

                            foreach (var n in resource.Last().Split('.').SkipLast(1))
                            {
                                _icons.AddIconProvider(string.Join('/', path, n), new IconProviderSvg(resourceManager, resourcePath, Colors.Black));
                            }
                        }
                        else if (resourcePath.EndsWith(".baml"))
                        {
                            var resource = resourcePath.Split('/');
                            var path     = string.Join('/', resource.SkipLast(1));

                            foreach (var n in resource.Last().Split('.').SkipLast(1))
                            {
                                _icons.AddIconProvider(
                                    string.Join('/', path, n),
                                    new IconProviderXamlFromUri(new Uri($"/{assembly.FullName};component/{string.Join('.',resourcePath.Split('.').SkipLast(1))}.xaml", UriKind.Relative))
                                    );
                            }
                        }
                    }
                }
                catch (MissingManifestResourceException)
                {
                }
            }
        }