public static async Task ImportItemsAsync(this OGLContext context) { context.Items.Clear(); context.ItemLists.Clear(); context.ItemsSimple.Clear(); var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Items_Directory, true).ConfigureAwait(false); foreach (var f in files) { try { Uri source = new Uri(PCLSourceManager.GetDirectory(f.Value, context.Config.Items_Directory)); Uri target = new Uri(PCLSourceManager.Parent(f.Key)); using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { Item s = (Item)Item.Serializer.Deserialize(reader); s.Category = Make(context, source.MakeRelativeUri(target)); s.Source = f.Value; s.Register(context, f.Key.Path); } } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } } }
public static Category Make(this OGLContext context, String path) { String p = path; if (!p.StartsWith(context.Config.Items_Directory)) { p = PortablePath.Combine(context.Config.Items_Directory, path); } p = p.Replace(PortablePath.DirectorySeparatorChar, '/'); if (!Category.Categories.ContainsKey(p)) { Category.Categories.Add(p.ToString(), new Category(p, path.Split(new[] { PortablePath.DirectorySeparatorChar }).ToList())); } String parent = PCLSourceManager.Parent(p); if (parent.StartsWith(context.Config.Items_Directory) && !parent.Equals(context.Config.Items_Directory)) { Make(context, parent); } return(Category.Categories[p]); }
public static async Task ImportMagicAsync(this OGLContext context) { context.Magic.Clear(); context.MagicCategories.Clear(); context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0)); context.MagicSimple.Clear(); var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Magic_Directory, true).ConfigureAwait(false); foreach (var f in files) { try { Uri source = new Uri(PCLSourceManager.GetDirectory(f.Value, context.Config.Magic_Directory)); Uri target = new Uri(PCLSourceManager.Parent(f.Key)); string cat = MagicPropertyCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString())); if (!context.MagicCategories.ContainsKey(cat)) { context.MagicCategories.Add(cat, MakeMagicCategory(cat)); } String parent = PCLSourceManager.Parent(cat); while (parent.StartsWith(context.Config.Magic_Directory) && !context.MagicCategories.ContainsKey(parent)) { context.MagicCategories.Add(parent, MakeMagicCategory(parent)); parent = PCLSourceManager.Parent(parent); } using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) { MagicProperty mp = ((MagicProperty)MagicProperty.Serializer.Deserialize(reader)); mp.Filename = f.Key.Path; mp.Source = f.Value; foreach (Feature fea in mp.AttunementFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.CarryFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.OnUseFeatures) { fea.Source = f.Value; } foreach (Feature fea in mp.EquipFeatures) { fea.Source = f.Value; } mp.Category = cat; context.MagicCategories[cat].Contents.Add(mp); if (context.Magic.ContainsKey(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source)) { throw new Exception("Duplicate Magic Property: " + mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source); } if (context.MagicSimple.ContainsKey(mp.Name)) { context.MagicSimple[mp.Name].ShowSource = true; mp.ShowSource = true; } context.Magic.Add(mp.Name + " " + ConfigManager.SourceSeperator + " " + mp.Source, mp); context.MagicSimple[mp.Name] = mp; } } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } //Collections[].AddRange(feats); } }
public static async Task ImportStandaloneFeaturesAsync(this OGLContext context) { context.FeatureCollections.Clear(); context.FeatureContainers.Clear(); context.FeatureCategories.Clear(); context.Boons.Clear(); context.Features.Clear(); context.BoonsSimple.Clear(); var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Features_Directory, true).ConfigureAwait(false); foreach (var f in files) { try { Uri source = new Uri(PCLSourceManager.GetDirectory(f.Value, context.Config.Features_Directory)); Uri target = new Uri(PCLSourceManager.Parent(f.Key)); FeatureContainer cont = await LoadFeatureContainerAsync(f.Key); List <Feature> feats = cont.Features; string cat = FeatureCleanname(context, Uri.UnescapeDataString(source.MakeRelativeUri(target).ToString())); if (!context.FeatureContainers.ContainsKey(cat)) { context.FeatureContainers.Add(cat, new List <FeatureContainer>()); } cont.filename = f.Key.Path; cont.category = cat; cont.Name = f.Key.Name; int i = cont.Name.LastIndexOf('.'); if (i > 0) { cont.Name = cont.Name.Substring(0, i); } cont.Source = f.Value; context.FeatureContainers[cat].Add(cont); foreach (Feature feat in feats) { feat.Source = cont.Source; foreach (Keyword kw in feat.Keywords) { kw.check(); } feat.Category = cat; if (!context.FeatureCategories.ContainsKey(cat)) { context.FeatureCategories.Add(cat, new List <Feature>()); } Feature other = context.FeatureCategories[cat].Where(ff => string.Equals(ff.Name, feat.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (other != null) { other.ShowSource = true; feat.ShowSource = true; } context.FeatureCategories[cat].Add(feat); if (cat.Equals("Feats/Boons", StringComparison.OrdinalIgnoreCase)) { if (context.BoonsSimple.ContainsKey(feat.Name)) { context.BoonsSimple[feat.Name].ShowSource = true; feat.ShowSource = true; } else { context.BoonsSimple.Add(feat.Name, feat); } if (context.Boons.ContainsKey(feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source)) { ConfigManager.LogError("Duplicate Boon: " + feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source); } else { context.Boons[feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source] = feat; } } } foreach (Feature feat in feats) { context.Features.Add(feat); } } catch (Exception e) { ConfigManager.LogError("Error reading " + Path(f.Key.Path), e); } } }