public void AddChild(SfbFileSystemEntry entry)
 {
     if (!children.Contains(entry)) {
         entry.parent = this;
         children.Add(entry);
     }
 }
Exemplo n.º 2
0
        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));
     }
 }
Exemplo n.º 4
0
        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
        }
Exemplo n.º 5
0
        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
        }
Exemplo n.º 6
0
        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--;
                    }
                }
            }
        }
Exemplo n.º 7
0
        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
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
     }
 }
Exemplo n.º 11
0
        public void AddRecentEntry(SfbFileSystemEntry fileSystemEntry)
        {
            RemoveOldestRecent();

            if (!recentList.ContainsKey(fileSystemEntry.path)) {
                recentList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Recent, fileSystemEntry));
            }
        }
 public void AddChild(SfbFileSystemEntry entry)
 {
     if (!children.Contains(entry))
     {
         entry.parent = this;
         children.Add(entry);
     }
 }
Exemplo n.º 13
0
        public void AddRecentEntry(SfbFileSystemEntry fileSystemEntry)
        {
            RemoveOldestRecent();

            if (!recentList.ContainsKey(fileSystemEntry.path))
            {
                recentList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Recent, fileSystemEntry));
            }
        }
Exemplo n.º 14
0
        public void CloseWindow()
        {
            history.Clear();
            outputMethod     = null;
            currentDirectory = null;
            window.gameObject.SetActive(false);

            SaveSavedLocations();
        }
Exemplo n.º 15
0
        public bool FileExists(SfbFileSystemEntry entry)
        {
            if (entry.type == SfbFileSystemEntryType.File)
            {
                return(false);
            }

            return(entries.ContainsKey(entry.path) && entries[entry.path] == entry);
        }
Exemplo n.º 16
0
        public bool HasValidExtension(SfbFileSystemEntry fileSystemEntry)
        {
            if (fileSystemEntry == null)
            {
                return(false);
            }

            return(fileSystemEntry.type != SfbFileSystemEntryType.File || IsValidExtension(fileSystemEntry.extension));
        }
Exemplo n.º 17
0
 public void ChangeDirectory(SfbFileSystemEntry entry)
 {
     if (entry is SfbSavedLocationEntry) {
         entry = fileSystem.GetDirectory(entry.path);
     }
     if (entry == null) {
         return;
     }
     InternalChangeDirectory(entry);
 }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 public void ChangeDirectory(SfbFileSystemEntry entry)
 {
     if (entry is SfbSavedLocationEntry)
     {
         entry = fileSystem.GetDirectory(entry.path);
     }
     if (entry == null)
     {
         return;
     }
     InternalChangeDirectory(entry);
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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, ""));
            }
        }
Exemplo n.º 22
0
        private void ListenerOpenParentDirectory()
        {
            SfbFileSystemEntry directory = fileSystem.GetParentDirectory(currentDirectory.path);

            if (directory != null)
            {
                InternalChangeDirectory(directory);
            }
            else
            {
                Debug.LogWarning("No parent directory");
            }
        }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
        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
        }
Exemplo n.º 27
0
        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
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        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
        }
Exemplo n.º 31
0
        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));
            }
        }
Exemplo n.º 32
0
        public void CloseWindow()
        {
            history.Clear();
            outputMethod = null;
            currentDirectory = null;
            window.gameObject.SetActive(false);

            SaveSavedLocations();
        }
 public void RemoveChild(SfbFileSystemEntry entry)
 {
     if (children.Contains(entry)) {
         children.Remove(entry);
     }
 }
Exemplo n.º 34
0
 public static SfbSavedLocationEntry FromFileSystemEntry(SfbSavedLocationType locationType, SfbFileSystemEntry fileSystemEntry)
 {
     return(new SfbSavedLocationEntry(locationType, fileSystemEntry.path, fileSystemEntry.hidden, fileSystemEntry.type));
 }
Exemplo n.º 35
0
        public bool HasValidExtension(SfbFileSystemEntry fileSystemEntry)
        {
            if (fileSystemEntry == null) {
                return false;
            }

            return fileSystemEntry.type != SfbFileSystemEntryType.File || IsValidExtension(fileSystemEntry.extension);
        }
Exemplo n.º 36
0
 public bool DirectoryExists(SfbFileSystemEntry entry)
 {
     return(entries.ContainsKey(entry.path) && entries[entry.path] == entry);
 }
Exemplo n.º 37
0
        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, ""));
            }
        }
Exemplo n.º 38
0
        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);
        }
Exemplo n.º 39
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);
        }
Exemplo n.º 40
0
        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--;
                    }
                }
            }
        }
 public static SfbSavedLocationEntry FromFileSystemEntry(SfbSavedLocationType locationType, SfbFileSystemEntry fileSystemEntry)
 {
     return new SfbSavedLocationEntry(locationType, fileSystemEntry.path, fileSystemEntry.hidden, fileSystemEntry.type);
 }
Exemplo n.º 42
0
 public void AddFavoriteEntry(SfbFileSystemEntry fileSystemEntry)
 {
     if (!favoriteList.ContainsKey(fileSystemEntry.path)) {
         favoriteList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Favorite, fileSystemEntry));
     }
 }