예제 #1
0
        public static void ImportBackgrounds(this OGLContext context, bool withZips = true)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            if (withZips)
            {
                context.Backgrounds.Clear();
                context.BackgroundsSimple.Clear();
            }
            var files = SourceManager.EnumerateFiles(context, context.Config.Backgrounds_Directory, withZips, SearchOption.TopDirectoryOnly);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = f.Value.GetReader()) OGLImport.ImportBackground(reader, f.Value.FullName, f.Value.Source, context);
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }
            }
        }
예제 #2
0
        public static void ImportMagic(this OGLContext context, bool withZips = true)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            if (withZips)
            {
                context.Magic.Clear();
                context.MagicCategories.Clear();
                context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0));
                context.MagicSimple.Clear();
            }
            var files = SourceManager.EnumerateFiles(context, context.Config.Magic_Directory, withZips, SearchOption.AllDirectories);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = f.Value.GetReader()) OGLImport.ImportMagicItem(reader, f.Value.FullName, f.Value.Source, context, OGLImport.GetPath(f.Value.FullName, SourceManager.AppPath, f.Value.Source));
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }
            }
        }
예제 #3
0
        public static void ImportItems(this OGLContext context, bool withZips = true)
        {
            if (context == null || context.Config == null)
            {
                return;
            }
            if (withZips)
            {
                context.Items.Clear();
                context.ItemLists.Clear();
                context.ItemsSimple.Clear();
            }
            var files = SourceManager.EnumerateFiles(context, context.Config.Items_Directory, withZips);

            foreach (var f in files)
            {
                try
                {
                    using (Stream reader = f.Value.GetReader()) OGLImport.ImportItem(reader, f.Value.FullName, f.Value.Source, context, OGLImport.GetPath(f.Value.FullName, SourceManager.AppPath, f.Value.Source));
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error reading " + f.ToString(), e);
                }
            }
        }
        public static async Task ImportZips(this OGLContext context, bool applyKeywords = false, bool cleanup = true)
        {
            if (cleanup)
            {
                context.CleanUp();
            }
            String basepath = PCLSourceManager.Data.Path;

            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)))
                {
                    string f          = s.ToLowerInvariant() + "/";
                    string ff         = s.ToLowerInvariant() + "\\";
                    String basesource = PCLSourceManager.Sources.Select(ss => ss.Name).FirstOrDefault(ss => StringComparer.OrdinalIgnoreCase.Equals(ss, s));
                    bool   overridden = basesource != null;
                    foreach (ZipEntry entry in zf)
                    {
                        if (!entry.IsFile)
                        {
                            continue;
                        }
                        string name = entry.Name.ToLowerInvariant();
                        if ((name.StartsWith(f) || name.StartsWith(ff)) && name.EndsWith(".xml"))
                        {
                            String path = System.IO.Path.Combine(basepath, entry.Name).Replace("\\", "/");
                            if (overridden && (await FileSystem.Current.GetFileFromPathAsync(path)) != null)
                            {
                                continue;
                            }
                            using (Stream st = zf.GetInputStream(entry)) OGLImport.Import(st, path, s, basepath, context, applyKeywords);
                        }
                        else if (name.EndsWith(".xml"))
                        {
                            String path = System.IO.Path.Combine(basepath, basesource, entry.Name).Replace("\\", "/");
                            if (overridden && (await FileSystem.Current.GetFileFromPathAsync(path)) != null)
                            {
                                continue;
                            }
                            using (Stream st = zf.GetInputStream(entry)) OGLImport.Import(st, path, s, basepath, context, applyKeywords);
                        }
                    }
                }
            }
        }
        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);
                }
            }
        }
예제 #6
0
 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);
             }
         }
     }
 }