private void RegisterMessages() { MessengerInstance.Register <Message>(this, NAME, msg => { switch (msg.Key) { case "Activated": OnActivated(); RaisePropertyChanged("GeneralSetting"); break; case "BackPressed": msg.GetValue <BackPressedEventArgs>().Handled = true; if (SelectionMode != ListViewSelectionMode.None) { //선택 모드 변경 SelectionMode = ListViewSelectionMode.None; ButtonGroupVisible = true; } else { DateTime now = DateTime.Now; if (GeneralSetting.HardwareBackButtonAction == HardwareBackButtonAction.MoveToUpperFolder.ToString() && ExplorerFolderSource.Any(x => x.Type == FolderType.Upper) && (lastBackKeyDttm == null || now.Subtract((DateTime)lastBackKeyDttm).TotalMilliseconds > 300)) { //완벽할 수는 없으나... 입력시간을 기간 300ms 안에 들어오는것은 버림으로 UI와 ItemSource 동기화 시간을 조금이나마 번다. //상위 폴더로 이동 ToUpperFolder(msg.GetValue <BackPressedEventArgs>()); lastBackKeyDttm = now; } else { //종료 확인 MessengerInstance.Send <Message>(new Message("ConfirmTermination", null), MainViewModel.NAME); } } break; case "ShowErrorFile": if (ExplorerFileSource.Any()) { var kv = msg.GetValue <KeyValuePair <string, MediaInfo> >(); var mi = ExplorerFileSource.FirstOrDefault(f => f.Path == kv.Value.Path); if (mi != null) { mi.OccuredError = kv.Key + "\n"; } } break; } }); }
private async Task AddExplorerList(IEnumerable <StorageFile> storageFile, List <StorageFile> subtitleList, FolderInfo parentFolder, CancellationToken token) { var prevFolderName = string.Empty; //재생목록 로드 List <MediaInfo> playlist = null; foreach (var item in storageFile) { var mi = new MediaInfo(item); if (subtitleList != null) { //비동기 모드로 파일의 기본 정보(사이즈, 생성일자) 로드 var asyncAction = ThreadPool.RunAsync((handler) => { if (playlist == null) { playlist = new List <MediaInfo>(); fileDAO.LoadPlayList(playlist, 100, 0, false); } //재생목록 존재여부 체크 mi.IsAddedPlaylist = playlist.Any(x => x.Path == mi.Path); var pathName = mi.Path.Remove(mi.Path.Length - Path.GetExtension(mi.Path).Length); //자막 검색 foreach (var ext in CCPlayerConstant.SUBTITLE_FILE_SUFFIX) { StorageFile subtitleFile = null; try { subtitleFile = new List <StorageFile>(subtitleList).FirstOrDefault(x => Path.GetExtension(x.Path).ToUpper() == ext.ToUpper() && x.Path.Length > ext.Length && x.Path.Remove(x.Path.Length - ext.Length).ToUpper().Contains(pathName.ToUpper())); } catch (Exception) { } if (subtitleFile != null) { subtitleList.Remove(subtitleFile); //자막을 미디어 파일에 연결 mi.AddSubtitle(new SubtitleInfo(subtitleFile)); } } }, WorkItemPriority.Low); } else { if (prevFolderName == item.Name) { mi.Name = string.Format("{0} ({1})", mi.Name, Path.GetPathRoot(mi.Path)); } prevFolderName = item.Name; } token.ThrowIfCancellationRequested(); await DispatcherHelper.RunAsync(() => { //if (token == cancelTokenSource.Token) if (currentFolderInfo.Path == mi.ParentFolderPath) { ExplorerFileSource.Add(mi); } }); } }
private async void LoadChildFolder(FolderInfo folder) { cancelTokenSource = new CancellationTokenSource(); await Task.Run(async() => { await DispatcherHelper.RunAsync(() => { CheckListButtonEnable = false; }); StorageFolder stFolder = null; //현재 폴더가 저장되지 않았거나, 위로 버튼을 눌러 이동하다 최 상위가 된 경우 if (folder == null || folder.Level == 0) { LoadRootFolders(); return; } else { try { stFolder = await folder.GetStorageFolder(false); } catch (Exception) { //현재 폴더 삭제 DB 물리적 삭제 if (folder.Type == FolderType.Last) { var asyncAction = folderDAO.Delete(folder); //문제가 발생한 경우 루트 폴더를 로드 LoadRootFolders(); } return; } } await DispatcherHelper.RunAsync(() => { if (ExplorerFolderSource.Count > 0) { ExplorerFolderSource.Clear(); } if (ExplorerFileSource.Count > 0) { ExplorerFileSource.Clear(); } ExplorerFolderSource.Add(new FolderInfo() { Level = folder.Level - 1, Name = string.Format(".. ({0})", ResourceLoader.GetForCurrentView().GetString("ToUpper")), Path = folder.ParentFolderPath, Type = FolderType.Upper, }); }); try { var folderList = (await stFolder.GetFoldersAsync()).OrderBy(x => x.Name); if (folderList != null && folderList.Any()) { await LoadFolderList(folderList, folder, cancelTokenSource.Token); } var fileStorageList = (await stFolder.GetFilesAsync()).OrderBy(x => x.Name); var fileList = fileStorageList.Where(x => x.IsVideoFile()); if (fileList != null && fileList.Any()) { await AddExplorerList(fileList, fileStorageList.Where(x => x.IsSubtitleFile()).ToList(), folder, cancelTokenSource.Token); await DispatcherHelper.RunAsync(() => { CheckListButtonEnable = true; }); } } catch (OperationCanceledException ex) { //DispatcherHelper.CheckBeginInvokeOnUI(() => { ExplorerFolderSource.Clear(); }); System.Diagnostics.Debug.WriteLine("폴더 네비게이션 취소됨 : " + ex.CancellationToken.GetHashCode()); } }, cancelTokenSource.Token); }
private async void LoadRootFolders() { try { //폴더 추가 버튼 await DispatcherHelper.RunAsync(async() => { if (ExplorerFolderSource.Count > 0) { ExplorerFolderSource.Clear(); } if (ExplorerFileSource.Count > 0) { ExplorerFileSource.Clear(); } //탐색기 루트를 로드 folderDAO.LoadRootFolderList(ExplorerFolderSource, LockFolderCommand, RemoveFolderCommand, true); ExplorerFolderSource.Add(new FolderInfo() { Name = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("AddFolder"), Glyph1 = "\xE109", // Type = FolderType.Picker, IsHighlight = ExplorerFolderSource.Count == 0, Level = 1 }); ///////////////////////////// 윈10 10549 버그 Workaround////////////////////////////////// if (VersionHelper.WindowsVersion == 10 && !ExplorerFolderSource.Any(x => x.Type != FolderType.Picker)) { List <StorageFolder> folders = new List <StorageFolder>(); folders.Add(KnownFolders.VideosLibrary); var external = await KnownFolders.RemovableDevices.GetFoldersAsync(); if (external != null && external.Any()) { folders.AddRange(external); } foreach (var folder in folders) { bool found = false; //중복된 폴더는 추가하지 않음 foreach (var added in ExplorerFolderSource) { var sf = await added.GetStorageFolder(true); if (sf != null && sf.FolderRelativeId == folder.FolderRelativeId) { found = true; break; } } if (!found) { //전체 비디오에 반영 var folderInfo = new FolderInfo(folder) { Level = 1, Type = FolderType.Root, ButtonTappedCommand1 = LockFolderCommand, ButtonTappedCommand2 = RemoveFolderCommand, Passcode = string.Empty }; //선택한 폴더 DB등록 folderDAO.Insert(folderInfo); var addFolder = ExplorerFolderSource.FirstOrDefault(x => x.Type == FolderType.Picker); addFolder.IsHighlight = false; var index = ExplorerFolderSource.IndexOf(addFolder); ExplorerFolderSource.Insert(index, folderInfo); //전체 비디오에 반영 MessengerInstance.Send <Message>(new Message("FolderAdded", folderInfo), AllVideoViewModel.NAME); } } } ////////////////////////////////////////////////////////////////////////////////////////// }); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }