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.

101 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #include "../../Application/jucer_Headers.h"
  14. #include "jucer_CodeHelpers.h"
  15. //==============================================================================
  16. namespace FileHelpers
  17. {
  18. bool containsAnyNonHiddenFiles (const File& folder)
  19. {
  20. for (const auto& di : RangedDirectoryIterator (folder, false))
  21. if (! di.getFile().isHidden())
  22. return true;
  23. return false;
  24. }
  25. bool shouldPathsBeRelative (String path1, String path2)
  26. {
  27. path1 = build_tools::unixStylePath (path1);
  28. path2 = build_tools::unixStylePath (path2);
  29. const int len = jmin (path1.length(), path2.length());
  30. int commonBitLength = 0;
  31. for (int i = 0; i < len; ++i)
  32. {
  33. if (CharacterFunctions::toLowerCase (path1[i]) != CharacterFunctions::toLowerCase (path2[i]))
  34. break;
  35. ++commonBitLength;
  36. }
  37. return path1.substring (0, commonBitLength).removeCharacters ("/:").isNotEmpty();
  38. }
  39. // removes "/../" bits from the middle of the path
  40. String simplifyPath (String::CharPointerType p)
  41. {
  42. #if JUCE_WINDOWS
  43. if (CharacterFunctions::indexOf (p, CharPointer_ASCII ("/../")) >= 0
  44. || CharacterFunctions::indexOf (p, CharPointer_ASCII ("\\..\\")) >= 0)
  45. #else
  46. if (CharacterFunctions::indexOf (p, CharPointer_ASCII ("/../")) >= 0)
  47. #endif
  48. {
  49. StringArray toks;
  50. #if JUCE_WINDOWS
  51. toks.addTokens (p, "\\/", StringRef());
  52. #else
  53. toks.addTokens (p, "/", StringRef());
  54. #endif
  55. while (toks[0] == ".")
  56. toks.remove (0);
  57. for (int i = 1; i < toks.size(); ++i)
  58. {
  59. if (toks[i] == ".." && toks [i - 1] != "..")
  60. {
  61. toks.removeRange (i - 1, 2);
  62. i = jmax (0, i - 2);
  63. }
  64. }
  65. return toks.joinIntoString ("/");
  66. }
  67. return p;
  68. }
  69. String simplifyPath (const String& path)
  70. {
  71. #if JUCE_WINDOWS
  72. if (path.contains ("\\..\\") || path.contains ("/../"))
  73. #else
  74. if (path.contains ("/../"))
  75. #endif
  76. return simplifyPath (path.getCharPointer());
  77. return path;
  78. }
  79. }