ActiveTextureManagement.CacheController.RebuildCache C# (CSharp) Method

RebuildCache() private static method

private static RebuildCache ( TexInfo Texture, bool compress, bool mipmaps, string hashString ) : TextureInfoWrapper
Texture TexInfo
compress bool
mipmaps bool
hashString string
return TextureInfoWrapper
        private static TextureInfoWrapper RebuildCache(TexInfo Texture, bool compress, bool mipmaps, string hashString)
        {
            Texture.loadOriginalFirst = true;
            ActiveTextureManagement.DBGLog("Loading texture...");
            TextureConverter.GetReadable(Texture, mipmaps);
            ActiveTextureManagement.DBGLog("Texture loaded.");

            TextureInfoWrapper cacheTexture = Texture.texture;
            Texture2D tex = cacheTexture.texture;

            String textureName = cacheTexture.name;
            String cacheFile = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName;

            ActiveTextureManagement.DBGLog("Rebuilding Cache... " + Texture.name);

            ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".imgcache");

            Color32[] colors = tex.GetPixels32();
            bool hasAlpha =TextureConverter.WriteTo(tex, cacheFile + ".imgcache", compress);

            String originalTextureFile = Texture.filename;
            String cacheConfigFile = cacheFile + ".tcache";
            ActiveTextureManagement.DBGLog("Created Config for" + originalTextureFile);

            ConfigNode config = new ConfigNode();
            config.AddValue("md5", hashString); ActiveTextureManagement.DBGLog("md5: " + hashString);
            config.AddValue("orig_format", Path.GetExtension(originalTextureFile)); ActiveTextureManagement.DBGLog("orig_format: " + Path.GetExtension(originalTextureFile));
            config.AddValue("orig_width", Texture.width.ToString()); ActiveTextureManagement.DBGLog("orig_width: " + Texture.width.ToString());
            config.AddValue("orig_height", Texture.height.ToString()); ActiveTextureManagement.DBGLog("orig_height: " + Texture.height.ToString());
            config.AddValue("is_normal", cacheTexture.isNormalMap.ToString()); ActiveTextureManagement.DBGLog("is_normal: " + cacheTexture.isNormalMap.ToString());
            config.AddValue("is_compressed", compress); ActiveTextureManagement.DBGLog("is_compressed: " + compress);
            config.AddValue("width", Texture.resizeWidth.ToString()); ActiveTextureManagement.DBGLog("width: " + Texture.resizeWidth.ToString());
            config.AddValue("height", Texture.resizeHeight.ToString()); ActiveTextureManagement.DBGLog("height: " + Texture.resizeHeight.ToString());
            config.AddValue("hasAlpha", hasAlpha); ActiveTextureManagement.DBGLog("hasAlpha: " + hasAlpha.ToString());
            config.AddValue("hasMipmaps", mipmaps); ActiveTextureManagement.DBGLog("hasMipmaps: " + hasAlpha.ToString());
            config.Save(cacheConfigFile);
            ActiveTextureManagement.DBGLog("Saved Config.");

            if (compress)
            {
                tex.Compress(true);
            }
            cacheTexture.isCompressed = compress;
            tex.Apply(false, Texture.makeNotReadable);

            cacheTexture.isReadable = !Texture.makeNotReadable;

            return cacheTexture;
        }