Geowigo.Models.CartridgeTag.GetMediaCachePath C# (CSharp) Method

GetMediaCachePath() public method

Gets the path to the cached version of a media.
public GetMediaCachePath ( WF.Player.Core.Media media, bool recacheIfFileNotFound ) : string
media WF.Player.Core.Media
recacheIfFileNotFound bool If true, the cache for this media /// is recreated if its theoretical file path was not found. If false, /// null is returned if
return string
		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;
		}