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.

108 lines
3.2KB

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