Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
            }
        }