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 + ")"); } } } }
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); }
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); }