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.

171 lines
6.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_FILESEARCHPATH_H_INCLUDED
  24. #define JUCE_FILESEARCHPATH_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. Represents a set of folders that make up a search path.
  28. @see File
  29. */
  30. class JUCE_API FileSearchPath
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an empty search path. */
  35. FileSearchPath();
  36. /** Creates a search path from a string of pathnames.
  37. The path can be semicolon- or comma-separated, e.g.
  38. "/foo/bar;/foo/moose;/fish/moose"
  39. The separate folders are tokenised and added to the search path.
  40. */
  41. FileSearchPath (const String& path);
  42. /** Creates a copy of another search path. */
  43. FileSearchPath (const FileSearchPath&);
  44. /** Copies another search path. */
  45. FileSearchPath& operator= (const FileSearchPath&);
  46. /** Destructor. */
  47. ~FileSearchPath();
  48. /** Uses a string containing a list of pathnames to re-initialise this list.
  49. This search path is cleared and the semicolon- or comma-separated folders
  50. in this string are added instead. e.g. "/foo/bar;/foo/moose;/fish/moose"
  51. */
  52. FileSearchPath& operator= (const String& path);
  53. //==============================================================================
  54. /** Returns the number of folders in this search path.
  55. @see operator[]
  56. */
  57. int getNumPaths() const;
  58. /** Returns one of the folders in this search path.
  59. The file returned isn't guaranteed to actually be a valid directory.
  60. @see getNumPaths
  61. */
  62. File operator[] (int index) const;
  63. /** Returns the search path as a semicolon-separated list of directories. */
  64. String toString() const;
  65. //==============================================================================
  66. /** Adds a new directory to the search path.
  67. The new directory is added to the end of the list if the insertIndex parameter is
  68. less than zero, otherwise it is inserted at the given index.
  69. */
  70. void add (const File& directoryToAdd,
  71. int insertIndex = -1);
  72. /** Adds a new directory to the search path if it's not already in there.
  73. @return true if the directory has been added, false otherwise.
  74. */
  75. bool addIfNotAlreadyThere (const File& directoryToAdd);
  76. /** Removes a directory from the search path. */
  77. void remove (int indexToRemove);
  78. /** Merges another search path into this one.
  79. This will remove any duplicate directories.
  80. */
  81. void addPath (const FileSearchPath&);
  82. /** Removes any directories that are actually subdirectories of one of the other directories in the search path.
  83. If the search is intended to be recursive, there's no point having nested folders in the search
  84. path, because they'll just get searched twice and you'll get duplicate results.
  85. e.g. if the path is "c:\abc\de;c:\abc", this method will simplify it to "c:\abc"
  86. */
  87. void removeRedundantPaths();
  88. /** Removes any directories that don't actually exist. */
  89. void removeNonExistentPaths();
  90. //==============================================================================
  91. /** Searches the path for a wildcard.
  92. This will search all the directories in the search path in order, adding any
  93. matching files to the results array.
  94. @param results an array to append the results to
  95. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying whether to
  96. return files, directories, or both.
  97. @param searchRecursively whether to recursively search the subdirectories too
  98. @param wildCardPattern a pattern to match against the filenames
  99. @returns the number of files added to the array
  100. @see File::findChildFiles
  101. */
  102. int findChildFiles (Array<File>& results,
  103. int whatToLookFor,
  104. bool searchRecursively,
  105. const String& wildCardPattern = "*") const;
  106. //==============================================================================
  107. /** Finds out whether a file is inside one of the path's directories.
  108. This will return true if the specified file is a child of one of the
  109. directories specified by this path. Note that this doesn't actually do any
  110. searching or check that the files exist - it just looks at the pathnames
  111. to work out whether the file would be inside a directory.
  112. @param fileToCheck the file to look for
  113. @param checkRecursively if true, then this will return true if the file is inside a
  114. subfolder of one of the path's directories (at any depth). If false
  115. it will only return true if the file is actually a direct child
  116. of one of the directories.
  117. @see File::isAChildOf
  118. */
  119. bool isFileInPath (const File& fileToCheck,
  120. bool checkRecursively) const;
  121. private:
  122. //==============================================================================
  123. StringArray directories;
  124. void init (const String&);
  125. JUCE_LEAK_DETECTOR (FileSearchPath)
  126. };
  127. #endif // JUCE_FILESEARCHPATH_H_INCLUDED