コード例 #1
0
 public void AddChild(SfbFileSystemEntry entry)
 {
     if (!children.Contains(entry)) {
         entry.parent = this;
         children.Add(entry);
     }
 }
コード例 #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
        }
コード例 #3
0
 public void AddFavoriteEntry(SfbFileSystemEntry fileSystemEntry)
 {
     if (!favoriteList.ContainsKey(fileSystemEntry.path))
     {
         favoriteList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Favorite, fileSystemEntry));
     }
 }
コード例 #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
        }
コード例 #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
        }
コード例 #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--;
                    }
                }
            }
        }
コード例 #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
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #10
0
 public void RemoveChild(SfbFileSystemEntry entry)
 {
     if (children.Contains(entry))
     {
         children.Remove(entry);
     }
 }
コード例 #11
0
        public void AddRecentEntry(SfbFileSystemEntry fileSystemEntry)
        {
            RemoveOldestRecent();

            if (!recentList.ContainsKey(fileSystemEntry.path)) {
                recentList.Add(fileSystemEntry.path, SfbSavedLocationEntry.FromFileSystemEntry(SfbSavedLocationType.Recent, fileSystemEntry));
            }
        }
コード例 #12
0
 public void AddChild(SfbFileSystemEntry entry)
 {
     if (!children.Contains(entry))
     {
         entry.parent = this;
         children.Add(entry);
     }
 }
コード例 #13
0
        public void AddRecentEntry(SfbFileSystemEntry fileSystemEntry)
        {
            RemoveOldestRecent();

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

            SaveSavedLocations();
        }
コード例 #15
0
        public bool FileExists(SfbFileSystemEntry entry)
        {
            if (entry.type == SfbFileSystemEntryType.File)
            {
                return(false);
            }

            return(entries.ContainsKey(entry.path) && entries[entry.path] == entry);
        }
コード例 #16
0
        public bool HasValidExtension(SfbFileSystemEntry fileSystemEntry)
        {
            if (fileSystemEntry == null)
            {
                return(false);
            }

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

            if (directory != null)
            {
                InternalChangeDirectory(directory);
            }
            else
            {
                Debug.LogWarning("No parent directory");
            }
        }
コード例 #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);
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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
        }
コード例 #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
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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
        }
コード例 #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));
            }
        }
コード例 #32
0
        public void CloseWindow()
        {
            history.Clear();
            outputMethod = null;
            currentDirectory = null;
            window.gameObject.SetActive(false);

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

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