public bool NeedsDownload(string videoId, StorageFile storageFile) { if (UrlCaches.ContainsKey(videoId) && storageFile.Exists()) { var fileName = storageFile.ToString(); var urlCache = UrlCaches[videoId]; if (storageFile.Length >= urlCache.Length) { if (!VideoCaches.ContainsKey(fileName)) { SetFinished(urlCache.VideoId, fileName, false); } else if (VideoCaches[fileName].Finished) { return(false); } } foreach (var item in VideoCaches.Where(p => p.Value.FileName != fileName && p.Value.Finished && File.Exists(p.Value.FileName) && p.Value.VideoId == videoId)) { try { File.Copy(item.Value.FileName, fileName, true); } catch (IOException) { return(true); } SetFinished(urlCache.VideoId, fileName, true); return(false); } } return(true); }
public void SetUrl(string videoId, string title, long length) { if (UrlCaches.ContainsKey(videoId)) { var item = UrlCaches[videoId]; item.Length = length; item.Title = title; } else { var cache = new UrlCache { Length = length, Title = title, VideoId = videoId }; _urlCaches.Add(cache); UrlCaches.Add(cache.VideoId, cache); } }