public string GetMediaCachePath(Media media, bool recacheIfFileNotFound)
{
// Looks the file up in the registered sounds.
// If not found, gets the theoretical value instead.
string filename;
if (!_soundFiles.TryGetValue(media.MediaId, out filename))
{
filename = GetCachePathCore(media);
}
// Recreates the file if it doesn't exist.
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.FileExists(filename))
{
// Makes sure the directory exists.
isf.CreateDirectory(System.IO.Path.GetDirectoryName(filename));
// Writes the contents of the media.
using (IsolatedStorageFileStream fs = isf.OpenFile(filename, FileMode.Create, FileAccess.Write))
{
fs.Write(media.Data, 0, media.Data.Length);
}
}
}
// Updates the path in the sounds dictionary.
_soundFiles[media.MediaId] = filename;
return filename;
}