Exemplo n.º 1
0
        private AlephTheme LoadFromFile(string file)
        {
            if (Path.GetFileName(file)?.ToLower() == "default.xml")
            {
                var parser = new ThemeParser();
                parser.Load(file);
                parser.Parse(new Dictionary <string, string>());
                _themeDefaultValues = parser.GetProperties();

                var t = parser.Generate();

                LoggerSingleton.Inst.Debug("ThemeCache", $"Loaded (default) theme {t.Name} v{t.Version} from '{file}'", $"{string.Join("\n", parser.GetProperties().Select(p => $"{p.Key.PadRight(48, ' ')} {p.Value}"))}");

                return(t);
            }
            else
            {
                var parser = new ThemeParser();
                parser.Load(file);
                parser.Parse(GetDefaultParserProperties());
                var t = parser.Generate();

                LoggerSingleton.Inst.Debug("ThemeCache", $"Loaded theme {t.Name} v{t.Version} from '{file}'", $"{string.Join("\n", parser.GetProperties().Select(p => $"{p.Key.PadRight(48, ' ')} {p.Value}"))}");

                return(t);
            }
        }
Exemplo n.º 2
0
        private AlephTheme LoadFromFile(string file)
        {
            var parser = new ThemeParser();

            parser.Load(file);
            parser.Parse();
            var t = parser.Generate();

            LoggerSingleton.Inst.Debug("ThemeCache", $"Loaded theme {t.Name} v{t.Version} from '{file}'", $"{string.Join("\n", parser.GetProperties().Select(p => $"{p.Key.PadRight(48, ' ')} {p.Value}"))}");

            return(t);
        }
Exemplo n.º 3
0
        private AlephTheme LoadFromFile(string file)
        {
            if (file.ToLower().EndsWith(".zip"))
            {
                var parser = new ThemeParser();

                using (var zip = new ZipArchive(File.OpenRead(file), ZipArchiveMode.Read))
                {
                    using (var metadata = zip.GetEntry("metadata.xml")?.Open())
                    {
                        if (metadata == null)
                        {
                            throw new Exception("'metadata.xml' not found");
                        }
                        using (var reader = new StreamReader(metadata, Encoding.UTF8))
                        {
                            parser.LoadFromString(reader.ReadToEnd(), Path.GetFileName(file));
                        }
                    }

                    foreach (var res in zip.Entries.Where(p => p.Name.ToLower().EndsWith(".ico") || p.Name.ToLower().EndsWith(".png")))
                    {
                        using (var stream = res.Open())
                        {
                            using (var ms = new MemoryStream())
                            {
                                stream.CopyTo(ms);
                                parser.AddResource(res.Name, ms.ToArray());
                            }
                        }
                    }
                }

                parser.Parse();
                var t = parser.Generate();

                LoggerSingleton.Inst.Debug("ThemeCache", $"Loaded [zip] theme {t.Name} v{t.Version} from '{file}'", $"{string.Join("\n", parser.GetProperties().Select(p => $"{p.Key.PadRight(48, ' ')} {p.Value}"))}");

                return(t);
            }
            else
            {
                var parser = new ThemeParser();
                parser.Load(file);
                parser.Parse();
                var t = parser.Generate();

                LoggerSingleton.Inst.Debug("ThemeCache", $"Loaded [xml] theme {t.Name} v{t.Version} from '{file}'", $"{string.Join("\n", parser.GetProperties().Select(p => $"{p.Key.PadRight(48, ' ')} {p.Value}"))}");

                return(t);
            }
        }