private void StoreToFileCache(AMeshKey key, Mesh mesh) { Stream stream = null; bool ok = false; // Make sure the target cache directory exists string dir = String.Empty; string filename = String.Empty; FileNames(key, out dir, out filename); lock (diskLock) { try { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } stream = File.Open(filename, FileMode.Create); ok = mesh.ToStream(stream); } catch (IOException e) { m_log.ErrorFormat( "[MESH CACHE]: Failed to write file {0}. Exception {1} {2}.", filename, e.Message, e.StackTrace); ok = false; } if (stream != null) stream.Close(); if (File.Exists(filename)) { if (ok) File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); else File.Delete(filename); } } }