Esempio n. 1
0
        public static async Task ImportBackgroundsAsync(this OGLContext context)
        {
            context.Backgrounds.Clear();
            context.BackgroundsSimple.Clear();
            var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Backgrounds_Directory).ConfigureAwait(false);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false))
                    {
                        Background s = (Background)Background.Serializer.Deserialize(reader);
                        s.Source = f.Value;
                        foreach (Feature fea in s.Features)
                        {
                            fea.Source = f.Value;
                        }
                        s.Register(context, f.Key.Path);
                    }
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + Path(f.Key.Path), e);
                }
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        public static async Task <IEnumerable <string> > EnumerateCategories(this OGLContext context, string type)
        {
            HashSet <string> result = new HashSet <string>();

            foreach (var f in await PCLSourceManager.GetAllDirectoriesAsync(context, type))
            {
                result.UnionWith(await GetSubDirectoriesAsync(f.Key, type).ConfigureAwait(false));
            }
            return(from s in result orderby s select s);
        }
        public static async Task ImportStandaloneFeaturesAsync(this OGLContext context, bool withZips = true)
        {
            String basepath = PCLSourceManager.Data.Path;

            if (withZips)
            {
                context.FeatureCollections.Clear();
                context.FeatureContainers.Clear();
                context.FeatureCategories.Clear();
                context.Boons.Clear();
                context.Features.Clear();
                context.BoonsSimple.Clear();
                foreach (IFile z in PCLSourceManager.Zips)
                {
                    String s = System.IO.Path.ChangeExtension(z.Name, null);
                    if (context.ExcludedSources.Contains(s, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    using (ZipFile zf = new ZipFile(await z.OpenAsync(FileAccess.Read)))
                    {
                        var zfiles = await PCLSourceManager.EnumerateZipFilesAsync(zf, s, context.Config.Features_Directory).ConfigureAwait(false);

                        foreach (var f in zfiles)
                        {
                            try { using (Stream reader = zf.GetInputStream(f.Value)) OGLImport.ImportFeatureContainer(reader, f.Key, s, context, OGLImport.GetPath(f.Key, basepath, s)); }
                            catch (Exception e) { ConfigManager.LogError("Error reading " + Path(f.Key), e); }
                        }
                    }
                }
            }
            var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Features_Directory, true).ConfigureAwait(false);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) OGLImport.ImportFeatureContainer(reader, f.Key.Path, f.Value, context, OGLImport.GetPath(f.Key.Path, basepath, f.Value));
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + Path(f.Key.Path), e);
                }
            }
        }
        public static async Task <IEnumerable <string> > EnumerateCategories(this OGLContext context, string type)
        {
            HashSet <string> result = new HashSet <string>();

            foreach (var f in await PCLSourceManager.GetAllDirectoriesAsync(context, type))
            {
                result.UnionWith(await GetSubDirectoriesAsync(f.Key, type).ConfigureAwait(false));
            }
            string t  = type.TrimEnd('/', '\\').ToLowerInvariant() + "/";
            string tt = type.TrimEnd('/', '\\').ToLowerInvariant() + "\\";

            foreach (IFile z in PCLSourceManager.Zips)
            {
                String s = System.IO.Path.ChangeExtension(z.Name, null);
                using (ZipFile zf = new ZipFile(await z.OpenAsync(FileAccess.Read)))
                {
                    string f  = s.ToLowerInvariant() + "/" + t;
                    string ff = s.ToLowerInvariant() + "\\" + tt;
                    zf.IsStreamOwner = true;
                    foreach (ZipEntry entry in zf)
                    {
                        String name = entry.IsFile ? System.IO.Path.GetFileName(entry.Name) : entry.Name;
                        String n    = name.ToLowerInvariant();
                        if (n.StartsWith(t))
                        {
                            result.Add(name.Substring(t.Length));
                        }
                        else if (n.StartsWith(tt))
                        {
                            result.Add(name.Substring(tt.Length));
                        }
                        else if (n.StartsWith(f))
                        {
                            result.Add(name.Substring(f.Length));
                        }
                        else if (n.StartsWith(ff))
                        {
                            result.Add(name.Substring(ff.Length));
                        }
                    }
                }
            }
            return(from s in result orderby s select s);
        }
Esempio n. 6
0
        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]);
        }
Esempio n. 7
0
        public async static Task ImportSubRacesAsync(this OGLContext context)
        {
            context.SubRaces.Clear();
            context.SubRacesSimple.Clear();
            var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.SubRaces_Directory).ConfigureAwait(false);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false))
                    {
                        SubRace s = (SubRace)SubRace.Serializer.Deserialize(reader);
                        s.Source = f.Value;
                        s.Register(context, f.Key.Path);
                    }
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + Path(f.Key.Path), e);
                }
            }
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
                }
            }
        }