public string ChangeDir(string path) { // Take data from a path // if problem occured, fill values empty if (path == null || path == "" || !Directory.Exists(path)) { loaded = false; cangoback = false; currentpath = ""; subfiles = new string[0]; subdirs = new string[0]; stringlist = null; } else { try { cangoback = Directory.GetParent(path) != null; currentpath = FileBrowser.ChangeDirectory(path); subfiles = FileBrowser.GetFiles(path); subdirs = FileBrowser.GetDirectories(path); stringlist = BuildStringArray(); loaded = true; } catch (Exception) { ChangeDir(null); } } return(currentpath); }
public void GetFiles_ValidPath_ReturnArrayWithElements() { string dirPath = "C:\\testfiles"; FileBrowser testBrowser = new FileBrowser(); testBrowser.SetDrivePath(dirPath); FileInfo[] resultArray = testBrowser.GetFiles(); int result = resultArray.Length; Assert.IsTrue(result > 0); }
public void GetFiles_InvalidPath_ReturnEmptyArray() { string dirPath = ""; FileBrowser testBrowser = new FileBrowser(); testBrowser.SetDrivePath(dirPath); FileInfo[] resultArray = testBrowser.GetFiles(); int expected = 0; int result = resultArray.Length; Assert.AreEqual(expected, result); }
IEnumerator LoadFileAndFolder(DirectoryInfo[] foloderList, DirectoryInfo currentDic) // 加载文件和文件夹 { for (int i = 0; i < foloderList.Length; i++) { if (foloderList[i].Parent != null) { AddMiddleButton(foloderList[i], MiddleButtonType.Folder); // 有父文件夹的是文件夹 } else { AddMiddleButton(foloderList[i], MiddleButtonType.Drive); // 没有的就是磁盘啊 } yield return(0); } if (!isOnlyShowFolder) { FileInfo[] files = mFileBrowser.GetFiles(); // 获得所有文件 foreach (FileInfo fileInfo in files) { if (MyFilterUtil.IsAudio(fileInfo)) { AddMiddleButton(fileInfo, MiddleButtonType.Music); } else { Transform t = AddMiddleButton(fileInfo, MiddleButtonType.File); if (MyFilterUtil.IsTu(fileInfo)) // 是图片那就加载图片 { InitMoBan_Tu(t, fileInfo); } } yield return(new WaitForEndOfFrame()); } } if (null == currentDic) { AddMiddleButton(null, MiddleButtonType.ZhuoMain); // 桌面 } }
public string TryChangeDir(string path) { // Take data from a path // if problem occured, keep the previous state if (path != null && path != "" || !Directory.Exists(path)) { try { bool tryCGB = Directory.GetParent(path) != null; string tryCP = FileBrowser.ChangeDirectory(path); string[] trySF = FileBrowser.GetFiles(path); string[] trySD = FileBrowser.GetDirectories(path); //If a problem accured, the values won't be assigned cangoback = tryCGB; currentpath = tryCP; subdirs = trySD; subfiles = trySF; loaded = true; stringlist = BuildStringArray(); } catch (Exception) {} } return(currentpath); }
// Core public void RefreshButtons() { CancelCurrentThumbnails(); MainPanel.sizeDelta = Vector2.zero; // Destroy previous buttons for (int i = 0; i < Buttons.Count; i++) { Buttons[i].gameObject.SetActive(false); DestroyImmediate(Buttons[i].gameObject); } // Clear List Buttons.Clear(); DirectoryInfo Dir = _FB.GetCurrentDirectory(); if (Dir != null) { CurrentAdress.text = Dir.FullName; } else { CurrentAdress.text = string.Empty; } /* * bool isFavorite = false; * for (int i = 0; i < Favorites.Count; i++) * { * RectTransform _CurrentRect = Favorites[i].gameObject.GetComponent<RectTransform>(); * * if (_CurrentRect.FindChild("Name").gameObject.GetComponent<Text>().text == CurrentAdress.text) * { * isFavorite = true; * break; * } * } * * if (isFavorite) * { * FavoriteImage.color = new Color(1, 1, 0, 1); * } * else * { * FavoriteImage.color = new Color(1, 1, 1, 1); * } */ // Retrieve sub directories DirectoryInfo[] _childs = _FB.GetChildDirectories(); // Add a button for each folder for (int i = 0; i < _childs.Length; i++) { // Dissociate folders from drives if (_childs[i].Parent != null) { AddButton(_childs[i].Name, ButtonType.Folder); } else { AddButton(_childs[i].Name, ButtonType.Drive); } } if (!FolderOnly.isOn) { // Retrieve files FileInfo[] _files = _FB.GetFiles(); // Add a button for each file for (int i = 0; i < _files.Length; i++) { AddButton(_files[i].Name, ButtonType.File); } lock (_ThumbnailsFiles) { _ThumbnailsFiles = _files; } GenerateNewThumbnails = true; StartCoroutine(WaitForThumbnails()); } CheckButtonsVisibility(); }