private static ICollection <string> GetTexturesExist(string optName, OptFile opt, List <string> distinctSkins) { var texturesExist = new SortedSet <string>(); foreach (string skin in distinctSkins) { string path = GetSkinDirectoryLocatorPath(optName, skin); if (path == null) { continue; } SortedSet <string> filesSet; using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator == null) { continue; } var filesEnum = locator.EnumerateFiles() .Select(t => Path.GetFileName(t)); filesSet = new SortedSet <string>(filesEnum, StringComparer.OrdinalIgnoreCase); } foreach (string textureName in opt.Textures.Keys) { if (TextureExists(filesSet, textureName, skin) != null) { texturesExist.Add(textureName); } } } return(texturesExist); }
public void Test1() { var temp = Path.GetTempFileName(); try { for (int pass = 0; pass < 2; pass++) { using (var zip = WritableFileLocatorFactory.CreateArchive(temp, ArchiveType.Zip, CompressionType.LZMA)) { zip.Create(Path.Combine("a", Path.GetRandomFileName())); } } using (var reader = FileLocatorFactory.Create(temp)) { Assert.Equal(2, reader.EnumerateFiles().Count()); } } finally { File.Delete(temp); } }
private static void UpdateSkins(string optName, OptFile opt, List <string> distinctSkins, List <List <string> > fgSkins) { var locatorsPath = new Dictionary <string, string>(distinctSkins.Count, StringComparer.OrdinalIgnoreCase); var filesSets = new Dictionary <string, SortedSet <string> >(distinctSkins.Count, StringComparer.OrdinalIgnoreCase); foreach (string skin in distinctSkins) { string path = GetSkinDirectoryLocatorPath(optName, skin); locatorsPath.Add(skin, path); SortedSet <string> filesSet = null; if (path != null) { using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator != null) { var filesEnum = locator.EnumerateFiles() .Select(t => Path.GetFileName(t)); filesSet = new SortedSet <string>(filesEnum, StringComparer.OrdinalIgnoreCase); } } } filesSets.Add(skin, filesSet ?? new SortedSet <string>()); } opt.Textures.AsParallel().ForAll(texture => { int position = texture.Key.IndexOf("_fg_"); if (position == -1) { return; } string textureName = texture.Key.Substring(0, position); int fgIndex = int.Parse(texture.Key.Substring(position + 4, texture.Key.IndexOf('_', position + 4) - position - 4), CultureInfo.InvariantCulture); foreach (string skin in fgSkins[fgIndex]) { string path = locatorsPath[skin]; if (path == null) { continue; } string filename = TextureExists(filesSets[skin], textureName, skin); if (filename == null) { continue; } using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator == null) { continue; } CombineTextures(texture.Value, locator, filename); } } texture.Value.GenerateMipmaps(); }); }