public void SetText(string s) { if (invalidCharsPath == null) { invalidCharsPath = SfbFileSystem.GetInvalidFileNameChars().ToList().Where(a => a != '/' && a != '\\').ToArray(); } if (invalidCharsFileName == null) { // Remove control characters. This way the user is only notified about characters they can remove. invalidCharsFileName = SfbFileSystem.GetInvalidFileNameChars().ToList().Where(a => !char.IsControl(a)).ToArray(); } if (inputField == null) { inputField = GetComponent <InputField>(); inputField.onEndEdit.AddListener(OnSubmit); } if (fileBrowser == null) { fileBrowser = GetComponentInParent <SfbWindow>().fileBrowser; } text = s; inputField.text = s; inputField.MoveTextEnd(true); }
public void FakeFileSystem(SfbFileSystem fileSystem) { if (!fileSystem.IsFake) { Debug.LogError("Fake fileSystem must be set as fake"); return; } this.fileSystem = fileSystem; }
public bool IsValidInput(string input) { if (type == SfbInputFieldType.Path) { return(Regex.Replace(input, "[a-zA-Z]:[/\\\\]", "").IndexOfAny(invalidCharsPath) == -1); } return(input.IndexOfAny(SfbFileSystem.GetInvalidFileNameChars()) == -1); }
public SfbFileSystemEntry(string path, bool hidden, SfbFileSystemEntryType type) { path = SfbFileSystem.GetNormalizedPath(path); this.path = path; this.type = type; this.hidden = hidden; name = SfbFileSystem.GetFileName(path); if (type == SfbFileSystemEntryType.File) { extension = SfbFileSystem.GetExtension(path); } ReadLastWriteTime(); }
public static void ParseJSONInto(JSONNode N, string parentPath, SfbFileSystem fileSystem) { if (N["contents"] == null || N["contents"].Count == 0) { return; } foreach (var child in N["contents"].Childs) { if (child["logicalDrive"] != null) { if (child["logicalDrive"]["name"] == null) { return; } var path = parentPath + child["logicalDrive"]["name"].Value + "/"; fileSystem.AddEntry(new SfbFileSystemEntry(path, false, SfbFileSystemEntryType.LogicalDrive)); ParseJSONInto(child["logicalDrive"], path, fileSystem); } if (child["folder"] != null) { if (child["folder"]["name"] == null) { return; } var path = parentPath + child["folder"]["name"].Value + "/"; var hidden = child["folder"]["hidden"] != null && child["folder"]["hidden"].AsBool; fileSystem.AddEntry(new SfbFileSystemEntry(path, hidden, SfbFileSystemEntryType.Folder)); ParseJSONInto(child["folder"], path, fileSystem); } if (child["file"] != null) { if (child["file"]["name"] == null || child["file"]["extension"] == null) { return; } var path = parentPath + child["file"]["name"].Value + "." + child["file"]["extension"].Value; var hidden = child["file"]["hidden"] != null && child["file"]["hidden"].AsBool; fileSystem.AddEntry(new SfbFileSystemEntry(path, hidden, SfbFileSystemEntryType.File)); } } }
public static SfbFileSystem CreateFromJSON(string json) { var N = JSON.Parse(json); var fileSystem = new SfbFileSystem(true); if (N["fileSystem"] != null && N["fileSystem"]["root"] != null) { ParseJSONInto(N["fileSystem"]["root"], "/", fileSystem); } else { Debug.Log("No root found: " + N.ToString("")); } return(fileSystem); }
public void FakeFileSystem(SfbFileSystem fileSystem) { SfbInternal.FakeFileSystem(fileSystem); }