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.

95 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. namespace FileHelpers
  22. {
  23. int64 calculateStreamHashCode (InputStream& stream);
  24. int64 calculateFileHashCode (const File& file);
  25. bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, size_t numBytes);
  26. bool overwriteFileWithNewDataIfDifferent (const File& file, const MemoryOutputStream& newData);
  27. bool overwriteFileWithNewDataIfDifferent (const File& file, const String& newData);
  28. bool containsAnyNonHiddenFiles (const File& folder);
  29. String unixStylePath (const String& path);
  30. String windowsStylePath (const String& path);
  31. String currentOSStylePath (const String& path);
  32. bool shouldPathsBeRelative (String path1, String path2);
  33. bool isAbsolutePath (const String& path);
  34. // A windows-aware version of File::getRelativePath()
  35. String getRelativePathFrom (const File& file, const File& sourceFolder);
  36. // removes "/../" bits from the middle of the path
  37. String simplifyPath (String::CharPointerType path);
  38. String simplifyPath (const String& path);
  39. }
  40. //==============================================================================
  41. const char* const sourceFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;asm;r";
  42. const char* const headerFileExtensions = "h;hpp;hxx;hh;inl";
  43. const char* const cOrCppFileExtensions = "cpp;cc;cxx;c";
  44. const char* const cppFileExtensions = "cpp;cc;cxx";
  45. const char* const objCFileExtensions = "mm;m";
  46. const char* const asmFileExtensions = "s;S;asm";
  47. const char* const sourceOrHeaderFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;S;asm;h;hpp;hxx;hh;inl";
  48. const char* const browseableFileExtensions = "cpp;mm;m;c;cc;cxx;swift;s;S;asm;h;hpp;hxx;hh;inl;txt;md;rtf";
  49. const char* const fileTypesToCompileByDefault = "cpp;mm;c;m;cc;cxx;swift;s;S;asm;r";
  50. //==============================================================================
  51. struct FileModificationDetector
  52. {
  53. FileModificationDetector (const File& f) : file (f) {}
  54. const File& getFile() const { return file; }
  55. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  56. bool hasBeenModified() const
  57. {
  58. return fileModificationTime != file.getLastModificationTime()
  59. && (fileSize != file.getSize()
  60. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  61. }
  62. void updateHash()
  63. {
  64. fileModificationTime = file.getLastModificationTime();
  65. fileSize = file.getSize();
  66. fileHashCode = FileHelpers::calculateFileHashCode (file);
  67. }
  68. private:
  69. File file;
  70. Time fileModificationTime;
  71. int64 fileHashCode, fileSize;
  72. };