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.

168 lines
6.7KB

  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. #pragma once
  24. //==============================================================================
  25. /**
  26. Represents a set of folders that make up a search path.
  27. @see File
  28. */
  29. class JUCE_API FileSearchPath
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates an empty search path. */
  34. FileSearchPath();
  35. /** Creates a search path from a string of pathnames.
  36. The path can be semicolon- or comma-separated, e.g.
  37. "/foo/bar;/foo/moose;/fish/moose"
  38. The separate folders are tokenised and added to the search path.
  39. */
  40. FileSearchPath (const String& path);
  41. /** Creates a copy of another search path. */
  42. FileSearchPath (const FileSearchPath&);
  43. /** Copies another search path. */
  44. FileSearchPath& operator= (const FileSearchPath&);
  45. /** Destructor. */
  46. ~FileSearchPath();
  47. /** Uses a string containing a list of pathnames to re-initialise this list.
  48. This search path is cleared and the semicolon- or comma-separated folders
  49. in this string are added instead. e.g. "/foo/bar;/foo/moose;/fish/moose"
  50. */
  51. FileSearchPath& operator= (const String& path);
  52. //==============================================================================
  53. /** Returns the number of folders in this search path.
  54. @see operator[]
  55. */
  56. int getNumPaths() const;
  57. /** Returns one of the folders in this search path.
  58. The file returned isn't guaranteed to actually be a valid directory.
  59. @see getNumPaths
  60. */
  61. File operator[] (int index) const;
  62. /** Returns the search path as a semicolon-separated list of directories. */
  63. String toString() const;
  64. //==============================================================================
  65. /** Adds a new directory to the search path.
  66. The new directory is added to the end of the list if the insertIndex parameter is
  67. less than zero, otherwise it is inserted at the given index.
  68. */
  69. void add (const File& directoryToAdd,
  70. int insertIndex = -1);
  71. /** Adds a new directory to the search path if it's not already in there.
  72. @return true if the directory has been added, false otherwise.
  73. */
  74. bool addIfNotAlreadyThere (const File& directoryToAdd);
  75. /** Removes a directory from the search path. */
  76. void remove (int indexToRemove);
  77. /** Merges another search path into this one.
  78. This will remove any duplicate directories.
  79. */
  80. void addPath (const FileSearchPath&);
  81. /** Removes any directories that are actually subdirectories of one of the other directories in the search path.
  82. If the search is intended to be recursive, there's no point having nested folders in the search
  83. path, because they'll just get searched twice and you'll get duplicate results.
  84. e.g. if the path is "c:\abc\de;c:\abc", this method will simplify it to "c:\abc"
  85. */
  86. void removeRedundantPaths();
  87. /** Removes any directories that don't actually exist. */
  88. void removeNonExistentPaths();
  89. //==============================================================================
  90. /** Searches the path for a wildcard.
  91. This will search all the directories in the search path in order, adding any
  92. matching files to the results array.
  93. @param results an array to append the results to
  94. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying whether to
  95. return files, directories, or both.
  96. @param searchRecursively whether to recursively search the subdirectories too
  97. @param wildCardPattern a pattern to match against the filenames
  98. @returns the number of files added to the array
  99. @see File::findChildFiles
  100. */
  101. int findChildFiles (Array<File>& results,
  102. int whatToLookFor,
  103. bool searchRecursively,
  104. const String& wildCardPattern = "*") const;
  105. //==============================================================================
  106. /** Finds out whether a file is inside one of the path's directories.
  107. This will return true if the specified file is a child of one of the
  108. directories specified by this path. Note that this doesn't actually do any
  109. searching or check that the files exist - it just looks at the pathnames
  110. to work out whether the file would be inside a directory.
  111. @param fileToCheck the file to look for
  112. @param checkRecursively if true, then this will return true if the file is inside a
  113. subfolder of one of the path's directories (at any depth). If false
  114. it will only return true if the file is actually a direct child
  115. of one of the directories.
  116. @see File::isAChildOf
  117. */
  118. bool isFileInPath (const File& fileToCheck,
  119. bool checkRecursively) const;
  120. private:
  121. //==============================================================================
  122. StringArray directories;
  123. void init (const String&);
  124. JUCE_LEAK_DETECTOR (FileSearchPath)
  125. };