public static void ImportSpells(this OGLContext context, bool withZips = true) { if (context == null || context.Config == null) { return; } if (withZips) { context.Spells.Clear(); context.SpellLists.Clear(); context.SpellsSimple.Clear(); } var files = SourceManager.EnumerateFiles(context, context.Config.Spells_Directory, withZips, SearchOption.TopDirectoryOnly); foreach (var f in files) { try { using (Stream reader = f.Value.GetReader()) OGLImport.ImportSpell(reader, f.Value.FullName, f.Value.Source, context); } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } } }
public static async Task ImportSpellsAsync(this OGLContext context, bool withZips = true) { if (withZips) { context.Spells.Clear(); context.SpellLists.Clear(); context.SpellsSimple.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.Spells_Directory).ConfigureAwait(false); foreach (var f in zfiles) { try { using (Stream reader = zf.GetInputStream(f.Value)) OGLImport.ImportSpell(reader, f.Key, s, context); } catch (Exception e) { ConfigManager.LogError("Error reading " + Path(f.Key), e); } } } } } var files = await PCLSourceManager.EnumerateFilesAsync(context, context.Config.Spells_Directory).ConfigureAwait(false); foreach (var f in files) { try { using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) OGLImport.ImportSpell(reader, f.Key.Path, f.Value, context); } catch (Exception e) { ConfigManager.LogError("Error reading " + Path(f.Key.Path), e); } } }