Ejemplo n.º 1
0
        public static void Add(string ID, Texture2D texture, string directory = "", SAVE_TYPES saveType = SAVE_TYPES.PNG)
        {
            if (!texture)
            {
                return;
            }
            byte[] bytes = texture.EncodeToPNG();

            ID        = TextureVault.GenerateIdentifier(ID);
            directory = TextureVault.GetDirectory(directory);
            string fileName = TextureVault.GetFilename(directory, ID);

            if (File.Exists(fileName))
            {
                //Debug.LogFormat("[{0}] {1}", "TextureVault", "File exists in vault, halting " + fileName);
                return;
            }

            if (!TextureVault.DirectoryExists(directory))
            {
                //Debug.LogFormat("[{0}] {1} {2}", "TextureVault", "Directory does not exists create", directory);
                Directory.CreateDirectory(directory);
            }

            //Debug.LogFormat("[{0}] {1} {2} {3}", "TextureVault", "Saving to vault", fileName, texture);
            File.WriteAllBytes(fileName, bytes);
        }
Ejemplo n.º 2
0
        public static void Clean()
        {
            string baseDirectory = TextureVault.GetDirectory();

            if (!TextureVault.DirectoryExists(baseDirectory))
            {
                return;
            }

            string[] directories = Directory.GetDirectories(baseDirectory);
            foreach (string directory in directories)
            {
                //Debug.LogFormat("[{0}] {1}", "TextureVault", "Directory:" + directory);
                string[] files = Directory.GetFiles(directory);
                foreach (string file in files)
                {
                    // Everything a day old.
                    System.DateTime expiredTime = System.DateTime.Now;
                    expiredTime = expiredTime.AddDays(-7.0);

                    System.DateTime lastAccessTime = File.GetLastAccessTime(file);
                    if (expiredTime > lastAccessTime)
                    {
                        File.Delete(file);
                        Debug.LogFormat("[{0}] {1}", "TextureVault", "File is expired " + file + " (" + expiredTime + "/" + lastAccessTime + ")");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void LoadTextureItem(string ID, SuccessHandler onSuccess, ErrorHandler onError, string directory = "")
        {
            if (TextureVault.Get(ID, directory))
            {
                ID        = TextureVault.GenerateIdentifier(ID);
                directory = TextureVault.GetDirectory(directory);

                string fileName = TextureVault.GetFilename(directory, ID);


                if (textureCache.ContainsKey(fileName))
                {
                    Touch(fileName);
                    Debug.Log("From Cache " + fileName + " " + textureCache.Count);
                    onSuccess(textureCache[fileName].texture);
                    return;
                }

                byte[] data = File.ReadAllBytes(fileName);

                Texture2D texture2D = new Texture2D(2, 2);
                if (texture2D.LoadImage(data, true))
                {
                    textureCache.Add(fileName, new TextureVaultHistory(fileName, texture2D));
                    CleanupCache();
                    onSuccess(texture2D);
                    return;
                }
            }
            onError();
        }
Ejemplo n.º 4
0
        public static bool Get(string ID, string directory = "")
        {
            ID        = TextureVault.GenerateIdentifier(ID);
            directory = TextureVault.GetDirectory(directory);

            string fileName = TextureVault.GetFilename(directory, ID);

            if (textureCache.ContainsKey(fileName))
            {
                return(true);
            }

            if (TextureVault.DirectoryExists(directory))
            {
                return(File.Exists(fileName));
            }
            return(false);
        }