public void AddChild(SfbFileSystemEntry entry) { if (!children.Contains(entry)) { entry.parent = this; children.Add(entry); } }
private SfbFileSystemEntry ReadFile(string path) { #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (IsFake) { return(null); } string normalizedPath = GetNormalizedPath(path); if (!File.Exists(normalizedPath)) { return(null); } SfbFileSystemEntry entry; if (!entries.ContainsKey(normalizedPath)) { bool hidden = (File.GetAttributes(normalizedPath) & FileAttributes.Hidden) != 0; entry = new SfbFileSystemEntry(normalizedPath, hidden, SfbFileSystemEntryType.File); AddEntry(entry); } else { entry = entries[normalizedPath]; } return(entry); #else return(null); #endif }
public void AddFavoriteEntry(SfbFileSystemEntry fileSystemEntry) { if (!favoriteList.ContainsKey(fileSystemEntry.path)) { favoriteList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Favorite, fileSystemEntry)); } }
public void ReadFileOrBackupFromDisk(SfbFileSystemEntry fileSystemEntry, string backupExtension) { #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (string.IsNullOrEmpty(backupExtension)) { Debug.LogError("Cannot read backup file bacause no backup extension was set."); return; } if (fileSystemEntry.type != SfbFileSystemEntryType.File) { return; } if (!backupExtension.StartsWith(".")) { backupExtension = "." + backupExtension; } if (!File.Exists(fileSystemEntry.path)) { if (File.Exists(fileSystemEntry.path + backupExtension)) { fileSystemEntry.SetContents(File.ReadAllBytes(fileSystemEntry.path + backupExtension)); } return; } fileSystemEntry.ReadContentsFromDisk(); #endif }
public void DeleteEntryOnDiskAndRemove(SfbFileSystemEntry entry) { #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (IsFake) { return; } if (!File.Exists(entry.path) && !Directory.Exists(entry.path)) { return; } FileAttributes attr = File.GetAttributes(entry.path); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { Directory.Delete(entry.path, true); } else { File.Delete(entry.path); } RemoveEntry(entry); #endif }
public void ReportInvalidEntry(SfbFileSystemEntry entry) { for (int i = 0; i < history.Count; i++) { if (history[i] == entry) { history.RemoveAt(i); if (history.Count == 0) { currentIndex = -1; break; } if (i == currentIndex && i >= history.Count) { currentIndex = -1; break; } if (i < currentIndex) { currentIndex--; } } } }
private SfbFileSystemEntry ReadDirectory(string path) { #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (IsFake) { return(null); } string normalizedPath = GetNormalizedPath(path); SfbFileSystemEntry entry; if (!entries.ContainsKey(normalizedPath)) { bool hidden = (new DirectoryInfo(normalizedPath).Attributes & FileAttributes.Hidden) != 0; entry = new SfbFileSystemEntry(normalizedPath, hidden, SfbFileSystemEntryType.Folder); AddEntry(entry); } else { entry = entries[normalizedPath]; } return(entry); #else return(null); #endif }
public SfbFileSystemEntry CreateNewFileAndAddEntry(string path) { if (entries.ContainsKey(path)) { Debug.LogWarning("File already exists"); return(null); } SfbFileSystemEntry entry = new SfbFileSystemEntry(path, false, SfbFileSystemEntryType.File); #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (!IsFake) { try { File.Create(path); } catch (Exception e) { Debug.LogException(e); Debug.LogError("Could not create file"); return(null); } } #endif AddEntry(entry); return(entry); }
public void AddEntry(SfbFileSystemEntry entry) { if (entry.parent == null) { if (entry.type == SfbFileSystemEntryType.LogicalDrive) { entry.parent = root; root.AddChild(entry); } else { string s = GetParentPath(entry.path); if (entries.ContainsKey(s)) { entry.parent = entries[s]; entries[s].AddChild(entry); } } } var children = entries.Where(a => GetParentPath(a.Key) == entry.path).Select(b => b.Value); foreach (var child in children) { entry.AddChild(child); } if (!entries.ContainsKey(entry.path)) { entries.Add(entry.path, entry); } }
public void RemoveChild(SfbFileSystemEntry entry) { if (children.Contains(entry)) { children.Remove(entry); } }
public void AddRecentEntry(SfbFileSystemEntry fileSystemEntry) { RemoveOldestRecent(); if (!recentList.ContainsKey(fileSystemEntry.path)) { recentList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Recent, fileSystemEntry)); } }
public void CloseWindow() { history.Clear(); outputMethod = null; currentDirectory = null; window.gameObject.SetActive(false); SaveSavedLocations(); }
public bool FileExists(SfbFileSystemEntry entry) { if (entry.type == SfbFileSystemEntryType.File) { return(false); } return(entries.ContainsKey(entry.path) && entries[entry.path] == entry); }
public bool HasValidExtension(SfbFileSystemEntry fileSystemEntry) { if (fileSystemEntry == null) { return(false); } return(fileSystemEntry.type != SfbFileSystemEntryType.File || IsValidExtension(fileSystemEntry.extension)); }
public void ChangeDirectory(SfbFileSystemEntry entry) { if (entry is SfbSavedLocationEntry) { entry = fileSystem.GetDirectory(entry.path); } if (entry == null) { return; } InternalChangeDirectory(entry); }
public List <SfbFileSystemEntry> GetDirectoryContents(SfbFileSystemEntry entry, SfbFileSortingOrder sortingOrder) { switch (sortingOrder) { case SfbFileSortingOrder.FolderThenFileThenName: return(GetDirectoryContents(entry).OrderByDescending(a => a.type).ThenBy(b => b.name).ToList()); } return(null); }
public void Add(SfbFileSystemEntry entry) { if (entry == Current()) { return; } if (currentIndex != -1) { history.RemoveRange(currentIndex + 1, history.Count - (currentIndex + 1)); currentIndex = -1; } history.Add(entry); }
public void SelectedEntry(SfbFileSystemEntry entry) { if (mode == SfbMode.Save && entry.type == SfbFileSystemEntryType.File) { var inputFields = window.GetComponentsInChildren <SfbInputField>().Where(a => a.type == SfbInputFieldType.FileName); if (!inputFields.Any()) { return; } inputFields.First().SetText(entry.name.Replace(entry.extension, "")); } }
private void ListenerOpenParentDirectory() { SfbFileSystemEntry directory = fileSystem.GetParentDirectory(currentDirectory.path); if (directory != null) { InternalChangeDirectory(directory); } else { Debug.LogWarning("No parent directory"); } }
public void RemoveEntry(SfbFileSystemEntry entry) { entry.children.RemoveAll(a => a == entry); if (entry.parent != null) { entry.parent.RemoveChild(entry); } else { string s = GetParentPath(entry.path); Debug.Log(entries.ContainsKey(s)); } entries.Remove(entry.path); }
private void InternalChangeDirectory(SfbFileSystemEntry entry) { currentDirectory = entry; fileBrowserKeepScroll = false; StartCoroutine(RepopulateFileBrowserPanel()); var inputFields = window.GetComponentsInChildren <SfbInputField>(true).Where(a => a.type == SfbInputFieldType.Path); foreach (var field in inputFields) { field.SetText(currentDirectory.path); } history.Add(currentDirectory); }
public SfbFileSystem(bool isFake) { IsFake = isFake; entries.Add("/", new SfbFileSystemEntry("/", false, SfbFileSystemEntryType.Root)); root = entries["/"]; if (isFake == false) { ReadLogicalDrives(); } #if !UNITY_WEBGL && !UNITY_WEBPLAYER thread = new SfbFileSystemThread(); #endif }
private void ReadLogicalDrives() { #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (IsFake) { return; } var drives = new List <string>(); foreach (string drive in Environment.GetLogicalDrives()) { bool accessible = true; try { Directory.GetFileSystemEntries(drive); } catch (Exception) { accessible = false; } if (accessible) { string normalizedPath = drive.Replace('\\', '/'); drives.Add(normalizedPath); } } var remove = root.children.Select(a => a.path).Except(drives); foreach (var s in remove) { RemoveEntry(entries[s]); } foreach (var drive in drives) { if (entries.ContainsKey(drive)) { continue; } var entry = new SfbFileSystemEntry(drive, false, SfbFileSystemEntryType.LogicalDrive); AddEntry(entry); } root.readContents = true; #endif }
public void ShowTooltip(SfbFileSystemEntry entry, PointerEventData eventData) { if (tooltip == null) { tooltip = Instantiate(prefabTooltip); tooltip.name = "Tooltip"; tooltip.transform.SetParent(window.transform, false); } tooltip.SetActive(true); tooltip.GetComponentInChildren <Text>().text = entry.name; var rt = tooltip.transform as RectTransform; Vector2 point; RectTransformUtility.ScreenPointToLocalPointInRectangle(window.transform as RectTransform, Input.mousePosition, eventData.enterEventCamera, out point); rt.anchoredPosition = point + new Vector2(10, 0); }
public List <SfbFileSystemEntry> GetDirectoryContents(SfbFileSystemEntry entry) { if (!entries.ContainsKey(entry.path)) { return(new List <SfbFileSystemEntry>()); } if (entry.type == SfbFileSystemEntryType.Root) { if (root.children.Count == 0) { ReadLogicalDrives(); } return(root.children); } return(entry.children); }
public void AsyncUpdateDirectoryContents(SfbFileSystemEntry fileSystemEntry) { if (IsFake) { fileSystemEntry.readContents = true; return; } #if !UNITY_WEBGL && !UNITY_WEBPLAYER if (fileSystemEntry.readContents || IsUpdatingDirectoryContents) { return; } if (fileSystemEntry.type == SfbFileSystemEntryType.Root) { ReadLogicalDrives(); return; } thread.AsyncReadDirectoryContents(fileSystemEntry.path, AsyncRecieveDirectoryContents); IsUpdatingDirectoryContents = true; #endif }
public void LoadSavedLocations() { if (settings.SaveSettingsToPlayerPrefs) { if (!PlayerPrefs.HasKey(settings.SettingsSaveFileName)) { Debug.Log("No saved settings found"); } savedLocations.ParseSavedData(PlayerPrefs.GetString(settings.SettingsSaveFileName)); // Only one save setting should be used if (settings.SaveSettingsToDisk) { Debug.LogWarning("Both save settings are enabled, loading using PlayerPrefs."); } } else if (settings.SaveSettingsToDisk && settings.SettingsSaveFolder != "") { if (settings.SettingsSaveFolder == "") { Debug.LogError("File browser save path not set"); return; } var path = settings.SettingsSaveFolder + "/" + settings.SettingsSaveFileName; SfbFileSystemEntry settingsEntry = fileSystem.GetFile(path); if (settingsEntry == null) { return; } fileSystem.ReadFileOrBackupFromDisk(settingsEntry, ".bak"); savedLocations.ParseSavedData(Encoding.Unicode.GetString(settingsEntry.FileContents)); } }
public static SfbSavedLocationEntry FromFileSystemEntry(SfbSavedLocationType locationType, SfbFileSystemEntry fileSystemEntry) { return(new SfbSavedLocationEntry(locationType, fileSystemEntry.path, fileSystemEntry.hidden, fileSystemEntry.type)); }
public bool HasValidExtension(SfbFileSystemEntry fileSystemEntry) { if (fileSystemEntry == null) { return false; } return fileSystemEntry.type != SfbFileSystemEntryType.File || IsValidExtension(fileSystemEntry.extension); }
public bool DirectoryExists(SfbFileSystemEntry entry) { return(entries.ContainsKey(entry.path) && entries[entry.path] == entry); }
public void SelectedEntry(SfbFileSystemEntry entry) { if (mode == SfbMode.Save && entry.type == SfbFileSystemEntryType.File) { var inputFields = window.GetComponentsInChildren<SfbInputField>().Where(a => a.type == SfbInputFieldType.FileName); if (!inputFields.Any()) { return; } inputFields.First().SetText(entry.name.Replace(entry.extension, "")); } }
public void ShowTooltip(SfbFileSystemEntry entry, PointerEventData eventData) { if (tooltip == null) { tooltip = Instantiate(prefabTooltip); tooltip.name = "Tooltip"; tooltip.transform.SetParent(window.transform, false); } tooltip.SetActive(true); tooltip.GetComponentInChildren<Text>().text = entry.name; var rt = tooltip.transform as RectTransform; Vector2 point; RectTransformUtility.ScreenPointToLocalPointInRectangle(window.transform as RectTransform, Input.mousePosition, eventData.enterEventCamera, out point); rt.anchoredPosition = point + new Vector2(10, 0); }
private void InternalChangeDirectory(SfbFileSystemEntry entry) { currentDirectory = entry; fileBrowserKeepScroll = false; StartCoroutine(RepopulateFileBrowserPanel()); var inputFields = window.GetComponentsInChildren<SfbInputField>(true).Where(a => a.type == SfbInputFieldType.Path); foreach (var field in inputFields) { field.SetText(currentDirectory.path); } history.Add(currentDirectory); }
public static SfbSavedLocationEntry FromFileSystemEntry(SfbSavedLocationType locationType, SfbFileSystemEntry fileSystemEntry) { return new SfbSavedLocationEntry(locationType, fileSystemEntry.path, fileSystemEntry.hidden, fileSystemEntry.type); }