The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_FILESEARCHPATH_JUCEHEADER__
  19. #define __JUCE_FILESEARCHPATH_JUCEHEADER__
  20. #include "juce_File.h"
  21. #include "../text/juce_StringArray.h"
  22. //==============================================================================
  23. /**
  24. Encapsulates a set of folders that make up a search path.
  25. @see File
  26. */
  27. class JUCE_API FileSearchPath
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates an empty search path. */
  32. FileSearchPath();
  33. /** Creates a search path from a string of pathnames.
  34. The path can be semicolon- or comma-separated, e.g.
  35. "/foo/bar;/foo/moose;/fish/moose"
  36. The separate folders are tokenised and added to the search path.
  37. */
  38. FileSearchPath (const String& path);
  39. /** Creates a copy of another search path. */
  40. FileSearchPath (const FileSearchPath& other);
  41. /** Destructor. */
  42. ~FileSearchPath();
  43. /** Uses a string containing a list of pathnames to re-initialise this list.
  44. This search path is cleared and the semicolon- or comma-separated folders
  45. in this string are added instead. e.g. "/foo/bar;/foo/moose;/fish/moose"
  46. */
  47. FileSearchPath& operator= (const String& path);
  48. //==============================================================================
  49. /** Returns the number of folders in this search path.
  50. @see operator[]
  51. */
  52. int getNumPaths() const;
  53. /** Returns one of the folders in this search path.
  54. The file returned isn't guaranteed to actually be a valid directory.
  55. @see getNumPaths
  56. */
  57. File operator[] (int index) const;
  58. /** Returns the search path as a semicolon-separated list of directories. */
  59. String toString() const;
  60. //==============================================================================
  61. /** Adds a new directory to the search path.
  62. The new directory is added to the end of the list if the insertIndex parameter is
  63. less than zero, otherwise it is inserted at the given index.
  64. */
  65. void add (const File& directoryToAdd,
  66. int insertIndex = -1);
  67. /** Adds a new directory to the search path if it's not already in there. */
  68. void addIfNotAlreadyThere (const File& directoryToAdd);
  69. /** Removes a directory from the search path. */
  70. void remove (int indexToRemove);
  71. /** Merges another search path into this one.
  72. This will remove any duplicate directories.
  73. */
  74. void addPath (const FileSearchPath& other);
  75. /** Removes any directories that are actually subdirectories of one of the other directories in the search path.
  76. If the search is intended to be recursive, there's no point having nested folders in the search
  77. path, because they'll just get searched twice and you'll get duplicate results.
  78. e.g. if the path is "c:\abc\de;c:\abc", this method will simplify it to "c:\abc"
  79. */
  80. void removeRedundantPaths();
  81. /** Removes any directories that don't actually exist. */
  82. void removeNonExistentPaths();
  83. //==============================================================================
  84. /** Searches the path for a wildcard.
  85. This will search all the directories in the search path in order, adding any
  86. matching files to the results array.
  87. @param results an array to append the results to
  88. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying whether to
  89. return files, directories, or both.
  90. @param searchRecursively whether to recursively search the subdirectories too
  91. @param wildCardPattern a pattern to match against the filenames
  92. @returns the number of files added to the array
  93. @see File::findChildFiles
  94. */
  95. int findChildFiles (Array<File>& results,
  96. int whatToLookFor,
  97. bool searchRecursively,
  98. const String& wildCardPattern = "*") const;
  99. //==============================================================================
  100. /** Finds out whether a file is inside one of the path's directories.
  101. This will return true if the specified file is a child of one of the
  102. directories specified by this path. Note that this doesn't actually do any
  103. searching or check that the files exist - it just looks at the pathnames
  104. to work out whether the file would be inside a directory.
  105. @param fileToCheck the file to look for
  106. @param checkRecursively if true, then this will return true if the file is inside a
  107. subfolder of one of the path's directories (at any depth). If false
  108. it will only return true if the file is actually a direct child
  109. of one of the directories.
  110. @see File::isAChildOf
  111. */
  112. bool isFileInPath (const File& fileToCheck,
  113. bool checkRecursively) const;
  114. private:
  115. //==============================================================================
  116. StringArray directories;
  117. void init (const String& path);
  118. JUCE_LEAK_DETECTOR (FileSearchPath);
  119. };
  120. #endif // __JUCE_FILESEARCHPATH_JUCEHEADER__