示例#1
0
        private void removeImageFromCache(DImageCache cacheItem)
        {
            string path = PathUtil.Combine(GetSavedImagesLocation(), cacheItem.Hashname);

            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    Log.LogError(this, "Unable to delete " + cacheItem.Hashname + " from device. Message: " + ex.Message);
                    Log.LogException(this, ex);
                }
            }
            if (sessionCachedImages.ContainsKey(cacheItem.Hashname))
            {
                UnityEngine.Object.Destroy(sessionCachedImages[cacheItem.Hashname]);
                sessionCachedImages.Remove(cacheItem.Hashname);
            }
            if (manifest.Count > 0 && manifest.Contains(cacheItem))
            {
                currentCacheSize -= cacheItem.Filesize;
                manifest.Remove(cacheItem);
            }
        }
示例#2
0
 public void RemoveImage(string hashName)
 {
     if (ContainsImage(hashName))
     {
         DImageCache cacheItem = manifest.Find((DImageCache item) => item.Hashname.Equals(hashName));
         removeImageFromCache(cacheItem);
     }
 }
示例#3
0
 public void SaveTextureToCache(string hashName, Texture2D texture)
 {
     byte[] array = texture.EncodeToPNG();
     if (array.Length >= cacheSizeByteLimit)
     {
         throw new InsufficientMemoryException("Attempting to save a texture that is larger than the cache size limit.Size of limit (KB): " + cacheSizeByteLimit + ". Size of texture (Bytes): " + array.Length);
     }
     if (ContainsImage(hashName))
     {
         DImageCache dImageCache = manifest.Find((DImageCache x) => x.Hashname.Equals(hashName));
         currentCacheSize    -= dImageCache.Filesize;
         dImageCache.Filesize = array.Length;
         currentCacheSize    += dImageCache.Filesize;
         checkCacheSize();
         dImageCache.Timestamp         = DateTime.Now.GetTimeInMilliseconds();
         sessionCachedImages[hashName] = texture;
     }
     else
     {
         DImageCache dImageCache = default(DImageCache);
         dImageCache.Hashname  = hashName;
         dImageCache.Filesize  = array.Length;
         dImageCache.Timestamp = DateTime.Now.GetTimeInMilliseconds();
         manifest.Add(dImageCache);
         currentCacheSize += dImageCache.Filesize;
         checkCacheSize();
         if (!sessionCachedImages.ContainsKey(hashName))
         {
             sessionCachedImages.Add(hashName, texture);
         }
     }
     try
     {
         writeToDisk(GetSavedImagesLocation(), hashName, array);
         saveManifest();
     }
     catch (Exception ex)
     {
         Log.LogError(this, "Unable to save item to disk. Exception Message: " + ex.Message);
         Log.LogException(this, ex);
     }
 }