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);
                        }
                    }
                }
            }
        }
Пример #2
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);
             }
         }
     }
 }