////////////////////////////////////////////////////// // Callback interface for selected directory ////////////////////////////////////////////////////// public SimpleFileDialog(Context context, FileSelectionMode mode) { switch (mode) { case FileSelectionMode.FileOpen: _selectType = _fileOpen; break; case FileSelectionMode.FileSave: _selectType = _fileSave; break; case FileSelectionMode.FolderChoose: _selectType = _folderChoose; break; case FileSelectionMode.FileOpenRoot: _selectType = _fileOpen; _mGoToUpper = true; break; case FileSelectionMode.FileSaveRoot: _selectType = _fileSave; _mGoToUpper = true; break; case FileSelectionMode.FolderChooseRoot: _selectType = _folderChoose; _mGoToUpper = true; break; default: _selectType = _fileOpen; break; } _mContext = context; _mSdcardDirectory = Environment.ExternalStorageDirectory.AbsolutePath; try { _mSdcardDirectory = new File(_mSdcardDirectory).CanonicalPath; } catch (IOException ioe) { } }
private static HashSet <string> BuildSelector(DirectoryInfo root, string selector, FileSelectionMode mode) { var result = new HashSet <string>(); var parts = selector.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); var thisPart = parts[0]; if (thisPart == "**") { // it's a super-wildcard. if (parts.Length == 1) { // we only got the super wildcard left, match anything in this folder and it's subfolders if (mode != FileSelectionMode.Folders) { var files = root.GetFiles(); foreach (var file in files) { result.Add(file.FullName); } } if (mode != FileSelectionMode.Files) { var directories = root.GetDirectories(); foreach (var directory in directories) { result.Add(directory.FullName); } } } else { // there is something behind the super-wildcard. // try to apply the thing behind the super wildcard // to this folder result.UnionWith(BuildSelector(root, string.Join("/", parts, 1, parts.Length - 1), mode)); } // recurse into subfolders var subfolders = root.GetDirectories(); foreach (var dir in subfolders) { result.UnionWith(BuildSelector(dir, selector, mode)); } return(result); } else { // not a super wildcard. if (parts.Length == 1) { // last part, get the files that match if (mode != FileSelectionMode.Folders) { var files = root.GetFiles(thisPart); foreach (var file in files) { result.Add(file.FullName); } } if (mode != FileSelectionMode.Files) { var directories = root.GetDirectories(thisPart); foreach (var directory in directories) { result.Add(directory.FullName); } } } else { // there is something below, apply this to all matching directories var directories = root.GetDirectories(thisPart); foreach (var dir in directories) { result.UnionWith(BuildSelector(dir, string.Join("/", parts, 1, parts.Length - 1), mode)); } } } return(result); }
/// <summary> /// Calculates a file set from Application.dataPath using the given includes and excludes and mode. If includes are empty /// everything will be included. If excludes are empty nothing will be excluded. /// </summary> /// <returns> /// The calculated list of files. /// </returns> /// <param name='includes'> /// The set of includes. Must not be null. /// </param> /// <param name='excludes'> /// The set of excludes. Must not be null. /// </param> /// <param name="mode"> /// Mode, determining whether files, folders or both should be included in the file set. /// </param> public static string[] CalculateFileset(string[] includes, string[] excludes, FileSelectionMode mode) { return(CalculateFileset(Application.dataPath, includes, excludes, mode)); }
private static void AddToPaths(HashSet <string> paths, DirectoryInfo root, string selector, FileSelectionMode mode) { var selectedPaths = BuildSelector(root, selector, mode); paths.UnionWith(selectedPaths); }
private static void RemoveFromPaths(HashSet <string> paths, DirectoryInfo root, string selector, FileSelectionMode mode) { var selectedPaths = BuildSelector(root, selector, mode); paths.ExceptWith(selectedPaths); }
public FileBrowserViewModel(IViewFacade viewFacade, FileSelectionMode mode, FileInfo?preselectedFile = null) { ViewFacade = viewFacade; this.Mode = mode; this.PreSelectedFile = preselectedFile; }
/// <summary> /// Calculates a file set from the given base path using the given includes and excludes. If includes are empty /// everything will be included. If excludes are empty nothing will be excluded. /// </summary> /// <returns> /// The calculated list of files. /// </returns> /// <param name='basePath'> /// The path where to start. /// </param> /// <param name='includes'> /// The set of includes. Must not be null. /// </param> /// <param name='excludes'> /// The set of excludes. Must not be null. /// </param> /// <param name="mode"> /// Mode, determining whether files, folders or both should be included in the file set. /// </param> public static string[] CalculateFileset(string basePath, string[] includes, string[] excludes, FileSelectionMode mode) { var root = new DirectoryInfo(basePath); if (includes.Length == 0) { includes = new string[] { "**" }; } HashSet <string> paths = new HashSet <string>(); foreach (var include in includes) { AddToPaths(paths, root, include, mode); } foreach (var exclude in excludes) { RemoveFromPaths(paths, root, exclude, mode); } var result = new string[paths.Count]; int idx = 0; foreach (var path in paths) { result[idx++] = path; } NormalizeSlashes(result); return(result); }
private static void RemoveFromPaths(HashSet<string>paths, DirectoryInfo root, string selector, FileSelectionMode mode) { var selectedPaths = BuildSelector(root, selector, mode); paths.ExceptWith(selectedPaths); }
private static HashSet<string> BuildSelector(DirectoryInfo root, string selector, FileSelectionMode mode) { var result = new HashSet<string>(); var parts = selector.Split(new string[]{"/"}, StringSplitOptions.RemoveEmptyEntries); var thisPart = parts[0]; if (thisPart == "**") { // it's a super-wildcard. if (parts.Length == 1) { // we only got the super wildcard left, match anything in this folder and it's subfolders if (mode != FileSelectionMode.Folders) { var files = root.GetFiles(); foreach(var file in files) { result.Add (file.FullName); } } if (mode != FileSelectionMode.Files) { var directories = root.GetDirectories(); foreach(var directory in directories) { result.Add (directory.FullName); } } } else { // there is something behind the super-wildcard. // try to apply the thing behind the super wildcard // to this folder result.UnionWith(BuildSelector(root, string.Join("/", parts, 1, parts.Length-1), mode)); } // recurse into subfolders var subfolders = root.GetDirectories(); foreach(var dir in subfolders) { result.UnionWith(BuildSelector(dir, selector, mode)); } return result; } else { // not a super wildcard. if (parts.Length == 1) { // last part, get the files that match if (mode != FileSelectionMode.Folders) { var files = root.GetFiles(thisPart); foreach(var file in files) { result.Add(file.FullName); } } if (mode != FileSelectionMode.Files) { var directories = root.GetDirectories(thisPart); foreach(var directory in directories) { result.Add (directory.FullName); } } } else { // there is something below, apply this to all matching directories var directories = root.GetDirectories(thisPart); foreach(var dir in directories) { result.UnionWith(BuildSelector(dir, string.Join("/", parts, 1, parts.Length-1), mode)); } } } return result; }
private static void AddToPaths(HashSet<string>paths, DirectoryInfo root, string selector, FileSelectionMode mode) { var selectedPaths = BuildSelector(root, selector, mode); paths.UnionWith(selectedPaths); }
/// <summary> /// Calculates a file set from the given base path using the given includes and excludes. If includes are empty /// everything will be included. If excludes are empty nothing will be excluded. /// </summary> /// <returns> /// The calculated list of files. /// </returns> /// <param name='basePath'> /// The path where to start. /// </param> /// <param name='includes'> /// The set of includes. Must not be null. /// </param> /// <param name='excludes'> /// The set of excludes. Must not be null. /// </param> /// <param name="mode"> /// Mode, determining whether files, folders or both should be included in the file set. /// </param> public static string[] CalculateFileset(string basePath, string[] includes, string[] excludes, FileSelectionMode mode) { var root = new DirectoryInfo(basePath); if (includes.Length == 0) { includes = new string[]{"**"}; } HashSet<string> paths = new HashSet<string>(); foreach(var include in includes) { AddToPaths(paths, root, include, mode); } foreach(var exclude in excludes) { RemoveFromPaths(paths, root, exclude, mode); } var result = new string[paths.Count]; int idx = 0; foreach(var path in paths) { result[idx++] = path; } NormalizeSlashes(result); return result; }
/// <summary> /// Calculates a file set from Application.dataPath using the given includes and excludes and mode. If includes are empty /// everything will be included. If excludes are empty nothing will be excluded. /// </summary> /// <returns> /// The calculated list of files. /// </returns> /// <param name='includes'> /// The set of includes. Must not be null. /// </param> /// <param name='excludes'> /// The set of excludes. Must not be null. /// </param> /// <param name="mode"> /// Mode, determining whether files, folders or both should be included in the file set. /// </param> public static string[] CalculateFileset(string[] includes, string[] excludes, FileSelectionMode mode) { return CalculateFileset(Application.dataPath, includes, excludes, mode); }