private async void OnSelectFileTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { var item = (sender as FrameworkElement).DataContext as FileOpenFailureItem; var f = await PickMediaFileAsync(); if (f != null) { FutureAccessListHelper.Instance.AddTempItem(new IStorageItem[] { f }); var cueFile = _failedItems[item.FullPath]; Added.AddRange( await FileOpen.HandleFileWithCue(f, await CueFile.CreateFromFileAsync(cueFile, false))); _failedItems.Remove(item.FullPath); _items.Remove((from i in _items where string.Compare(i.FullPath, item.FullPath, true) == 0 select i).First()); if (_failedItems.Count == 0) { Hide(); } } }
public static async Task <string> HandleCueFileOpen(StorageFile cueFile, List <StorageFile> files, List <MusicPlaybackItem> add) { try { var parent = await cueFile.GetParentAsync(); var cue = await CueFile.CreateFromFileAsync(cueFile, false); // Check user-opened files that are in the same directory var audioTrack = (from f in files where string.Compare(cue.FileName, f.Name, true) == 0 select f).FirstOrDefault(); StorageFile file = audioTrack; // Cannot find suitable audio track in user opened files. if (file == null) { // Check parent directory if (parent != null && !string.IsNullOrWhiteSpace(cue.FileName)) { file = await parent.TryGetItemAsync(cue.FileName) as StorageFile; } // Try opening the file else if (!string.IsNullOrWhiteSpace(cue.FileName)) { var parentPath = cueFile.Path.Substring(0, cueFile.Path.Length - Path.GetFileName(cueFile.Path).Length); var audioTrackPath = Path.Combine(parentPath, cue.FileName); file = await NativeMethods.GetStorageFileFromPathAsync(audioTrackPath) as StorageFile; } else { return(null); } } // Otherwise, remove that. else { files.Remove(audioTrack); } if (file != null) { add.AddRange(await HandleFileWithCue(file, cue)); } else { return(Path.Combine( Directory.GetParent(cueFile.Path).FullName, cue.FileName)); } } catch { } return(null); }