Beispiel #1
0
        /// <summary>
        /// Write the files from a file locator.
        /// </summary>
        /// <param name="locator">A file locator.</param>
        /// <param name="root">The root path.</param>
        public void WriteAll(IFileLocator locator, string root)
        {
            if (locator == null)
            {
                throw new ArgumentNullException("locator");
            }

            foreach (var file in locator.EnumerateFiles(root))
            {
                using (var stream = locator.Open(file))
                {
                    this.Write(file, stream);
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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();
            });
        }