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.

174 lines
4.7KB

  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. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. FileSearchPath::FileSearchPath()
  21. {
  22. }
  23. FileSearchPath::FileSearchPath (const String& path)
  24. {
  25. init (path);
  26. }
  27. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  28. : directories (other.directories)
  29. {
  30. }
  31. FileSearchPath::~FileSearchPath()
  32. {
  33. }
  34. FileSearchPath& FileSearchPath::operator= (const String& path)
  35. {
  36. init (path);
  37. return *this;
  38. }
  39. void FileSearchPath::init (const String& path)
  40. {
  41. directories.clear();
  42. directories.addTokens (path, ";", "\"");
  43. directories.trim();
  44. directories.removeEmptyStrings();
  45. for (int i = directories.size(); --i >= 0;)
  46. directories.set (i, directories[i].unquoted());
  47. }
  48. int FileSearchPath::getNumPaths() const
  49. {
  50. return directories.size();
  51. }
  52. File FileSearchPath::operator[] (const int index) const
  53. {
  54. return File (directories [index]);
  55. }
  56. String FileSearchPath::toString() const
  57. {
  58. StringArray directories2 (directories);
  59. for (int i = directories2.size(); --i >= 0;)
  60. if (directories2[i].containsChar (';'))
  61. directories2.set (i, directories2[i].quoted());
  62. return directories2.joinIntoString (";");
  63. }
  64. void FileSearchPath::add (const File& dir, const int insertIndex)
  65. {
  66. directories.insert (insertIndex, dir.getFullPathName());
  67. }
  68. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  69. {
  70. for (int i = 0; i < directories.size(); ++i)
  71. if (File (directories[i]) == dir)
  72. return;
  73. add (dir);
  74. }
  75. void FileSearchPath::remove (const int index)
  76. {
  77. directories.remove (index);
  78. }
  79. void FileSearchPath::addPath (const FileSearchPath& other)
  80. {
  81. for (int i = 0; i < other.getNumPaths(); ++i)
  82. addIfNotAlreadyThere (other[i]);
  83. }
  84. void FileSearchPath::removeRedundantPaths()
  85. {
  86. for (int i = directories.size(); --i >= 0;)
  87. {
  88. const File d1 (directories[i]);
  89. for (int j = directories.size(); --j >= 0;)
  90. {
  91. const File d2 (directories[j]);
  92. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  93. {
  94. directories.remove (i);
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. void FileSearchPath::removeNonExistentPaths()
  101. {
  102. for (int i = directories.size(); --i >= 0;)
  103. if (! File (directories[i]).isDirectory())
  104. directories.remove (i);
  105. }
  106. int FileSearchPath::findChildFiles (Array<File>& results,
  107. const int whatToLookFor,
  108. const bool searchRecursively,
  109. const String& wildCardPattern) const
  110. {
  111. int total = 0;
  112. for (int i = 0; i < directories.size(); ++i)
  113. total += operator[] (i).findChildFiles (results,
  114. whatToLookFor,
  115. searchRecursively,
  116. wildCardPattern);
  117. return total;
  118. }
  119. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  120. const bool checkRecursively) const
  121. {
  122. for (int i = directories.size(); --i >= 0;)
  123. {
  124. const File d (directories[i]);
  125. if (checkRecursively)
  126. {
  127. if (fileToCheck.isAChildOf (d))
  128. return true;
  129. }
  130. else
  131. {
  132. if (fileToCheck.getParentDirectory() == d)
  133. return true;
  134. }
  135. }
  136. return false;
  137. }
  138. END_JUCE_NAMESPACE