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.

97 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCER_FILEHELPERS_H_INCLUDED
  18. #define JUCER_FILEHELPERS_H_INCLUDED
  19. //==============================================================================
  20. namespace FileHelpers
  21. {
  22. int64 calculateStreamHashCode (InputStream& stream);
  23. int64 calculateFileHashCode (const File& file);
  24. bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, size_t numBytes);
  25. bool overwriteFileWithNewDataIfDifferent (const File& file, const MemoryOutputStream& newData);
  26. bool overwriteFileWithNewDataIfDifferent (const File& file, const String& newData);
  27. bool containsAnyNonHiddenFiles (const File& folder);
  28. String unixStylePath (const String& path);
  29. String windowsStylePath (const String& path);
  30. String currentOSStylePath (const String& path);
  31. bool shouldPathsBeRelative (String path1, String path2);
  32. bool isAbsolutePath (const String& path);
  33. // A windows-aware version of File::getRelativePath()
  34. String getRelativePathFrom (const File& file, const File& sourceFolder);
  35. // removes "/../" bits from the middle of the path
  36. String simplifyPath (String::CharPointerType path);
  37. String simplifyPath (const String& path);
  38. }
  39. //==============================================================================
  40. const char* const sourceFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;asm";
  41. const char* const headerFileExtensions = "h;hpp;hxx;hh;inl";
  42. const char* const cOrCppFileExtensions = "cpp;cc;cxx;c";
  43. const char* const cppFileExtensions = "cpp;cc;cxx";
  44. const char* const objCFileExtensions = "mm;m";
  45. const char* const asmFileExtensions = "s;S;asm";
  46. const char* const sourceOrHeaderFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;S;asm;h;hpp;hxx;hh;inl";
  47. const char* const browseableFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;S;asm;h;hpp;hxx;hh;inl;txt;md;rtf";
  48. const char* const fileTypesToCompileByDefault = "cpp;mm;c;m;cc;cxx;swift;s;S;asm;r";
  49. //==============================================================================
  50. struct FileModificationDetector
  51. {
  52. FileModificationDetector (const File& f) : file (f) {}
  53. const File& getFile() const { return file; }
  54. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  55. bool hasBeenModified() const
  56. {
  57. return fileModificationTime != file.getLastModificationTime()
  58. && (fileSize != file.getSize()
  59. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  60. }
  61. void updateHash()
  62. {
  63. fileModificationTime = file.getLastModificationTime();
  64. fileSize = file.getSize();
  65. fileHashCode = FileHelpers::calculateFileHashCode (file);
  66. }
  67. private:
  68. File file;
  69. Time fileModificationTime;
  70. int64 fileHashCode, fileSize;
  71. };
  72. #endif // JUCER_FILEHELPERS_H_INCLUDED