public static IEnumerable <string> EnumerateCategories(this OGLContext context, string type) { HashSet <string> result = new HashSet <string>(); foreach (var f in SourceManager.GetAllDirectories(context, type)) { Uri source = new Uri(f.Key.FullName); //context.ImportStandaloneFeatures(); var cats = f.Key.EnumerateDirectories("*", SearchOption.AllDirectories); foreach (DirectoryInfo d in cats) { result.Add(SourceManager.Cleanname(Uri.UnescapeDataString(source.MakeRelativeUri(new Uri(d.FullName)).ToString()), type)); } } string t = type.TrimEnd('/', '\\').ToLowerInvariant() + "/"; string tt = type.TrimEnd('/', '\\').ToLowerInvariant() + "\\"; foreach (var z in SourceManager.GetAllZips(context, type)) { foreach (ZipArchiveEntry a in z.Key.Entries) { string f = z.Value.ToLowerInvariant() + "/" + t; string ff = z.Value.ToLowerInvariant() + "\\" + tt; if (a.Length == 0) { string name = a.FullName.ToLowerInvariant(); if (a.FullName.StartsWith(t)) { result.Add(a.FullName.Substring(t.Length).TrimEnd('/', '\\')); } else if (a.FullName.StartsWith(f)) { result.Add(a.FullName.Substring(f.Length).TrimEnd('/', '\\')); } else if (a.FullName.StartsWith(tt)) { result.Add(a.FullName.Substring(tt.Length).TrimEnd('/', '\\')); } else if (a.FullName.StartsWith(ff)) { result.Add(a.FullName.Substring(ff.Length).TrimEnd('/', '\\')); } } } } return(result.OrderBy(s => s).Distinct()); }
public static void ImportZips(this OGLContext context, bool applyKeywords = false, bool cleanup = true) { if (cleanup) { context.Backgrounds.Clear(); context.BackgroundsSimple.Clear(); context.Classes.Clear(); context.ClassesSimple.Clear(); context.Conditions.Clear(); context.ConditionsSimple.Clear(); context.FeatureCollections.Clear(); context.FeatureContainers.Clear(); context.FeatureCategories.Clear(); context.Boons.Clear(); context.Features.Clear(); context.BoonsSimple.Clear(); context.Items.Clear(); context.ItemLists.Clear(); context.ItemsSimple.Clear(); context.Languages.Clear(); context.LanguagesSimple.Clear(); context.Magic.Clear(); context.MagicCategories.Clear(); context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0)); context.MagicSimple.Clear(); context.Monsters.Clear(); context.MonstersSimple.Clear(); context.Races.Clear(); context.RacesSimple.Clear(); context.Skills.Clear(); context.SkillsSimple.Clear(); context.Spells.Clear(); context.SpellLists.Clear(); context.SpellsSimple.Clear(); context.SubClasses.Clear(); context.SubClassesSimple.Clear(); context.SubRaces.Clear(); context.SubRacesSimple.Clear(); } foreach (KeyValuePair <FileInfo, string> zip in SourceManager.GetAllZips(context).AsEnumerable()) { ZipArchive archive = ZipFile.OpenRead(zip.Key.FullName); string f = zip.Value.ToLowerInvariant() + "/"; string ff = zip.Value.ToLowerInvariant() + "\\"; foreach (ZipArchiveEntry entry in archive.Entries) { string name = entry.FullName.ToLowerInvariant(); if ((name.StartsWith(f) || name.StartsWith(ff)) && name.EndsWith(".xml")) { String path = Path.Combine(SourceManager.AppPath, name); if (File.Exists(path)) { continue; } using (Stream s = entry.Open()) OGLImport.Import(s, path, zip.Value, SourceManager.AppPath, context, applyKeywords); } else if (name.EndsWith(".xml")) { String path = Path.Combine(SourceManager.AppPath, zip.Value, name); if (File.Exists(path)) { continue; } using (Stream s = entry.Open()) OGLImport.Import(s, path, zip.Value, SourceManager.AppPath, context, applyKeywords); } } } }