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); } } }
public static async Task ImportMagicAsync(this OGLContext context, bool withZips = true) { String basepath = PCLSourceManager.Data.Path; if (withZips) { context.Magic.Clear(); context.MagicCategories.Clear(); context.MagicCategories.Add("Magic", new MagicCategory("Magic", "Magic", 0)); context.MagicSimple.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.Magic_Directory).ConfigureAwait(false); foreach (var f in zfiles) { try { using (Stream reader = zf.GetInputStream(f.Value)) OGLImport.ImportMagicItem(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.Magic_Directory, true).ConfigureAwait(false); foreach (var f in files) { try { using (Stream reader = await f.Key.OpenAsync(FileAccess.Read).ConfigureAwait(false)) OGLImport.ImportMagicItem(reader, f.Key.Path, f.Value, context, OGLImport.GetPath(f.Key.Path, basepath, f.Value)); } catch (Exception e) { ConfigManager.LogError("Error reading " + f.ToString(), e); } } }