public void TestDeletingObsoleteCaches() { // Clear out obsolete caches before testing it with a new asset. ImageCache.DeleteObsoleteCaches(); // Create a temporary image. string imageFile = "Assets/Editor/Tests/TestData/TiltBrushLogo.jpg"; var tempFileName = Path.GetTempFileName(); File.Copy(imageFile, tempFileName, true); // Create a cache from the temporary image. Texture2D texture = new Texture2D(2, 2); texture.LoadImage(File.ReadAllBytes(tempFileName)); ImageCache.SaveIconCache(texture, tempFileName, 1.0f); int cacheCountWithTempImage = Directory.GetDirectories(ImageCache.CacheBaseDirectory).Length; // Delete the temporary image and rely on DeleteObsoleteCache() do delete the cache. File.Delete(tempFileName); ImageCache.DeleteObsoleteCaches(); int cacheCountWithoutTempImage = Directory.GetDirectories(ImageCache.CacheBaseDirectory).Length; // Check counts. Assert.AreEqual(cacheCountWithTempImage - 1, cacheCountWithoutTempImage); }
void Awake() { m_Instance = this; m_RequestedLoads = new Stack <int>(); App.InitMediaLibraryPath(); App.InitReferenceImagePath(m_DefaultImages); m_ReferenceDirectory = App.ReferenceImagePath(); if (Directory.Exists(m_ReferenceDirectory)) { m_FileWatcher = new FileWatcher(m_ReferenceDirectory); m_FileWatcher.NotifyFilter = NotifyFilters.LastWrite; m_FileWatcher.FileChanged += OnChanged; m_FileWatcher.FileCreated += OnChanged; m_FileWatcher.FileDeleted += OnChanged; m_FileWatcher.EnableRaisingEvents = true; } ImageCache.DeleteObsoleteCaches(); m_Images = new List <ReferenceImage>(); ProcessReferenceDirectory(userOverlay: false); }