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.

90 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_JUCEHEADER__
  18. #define __JUCER_FILEHELPERS_JUCEHEADER__
  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. class FileModificationDetector
  41. {
  42. public:
  43. FileModificationDetector (const File& f)
  44. : file (f)
  45. {
  46. }
  47. const File& getFile() const { return file; }
  48. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  49. bool hasBeenModified() const
  50. {
  51. return fileModificationTime != file.getLastModificationTime()
  52. && (fileSize != file.getSize()
  53. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  54. }
  55. void updateHash()
  56. {
  57. fileModificationTime = file.getLastModificationTime();
  58. fileSize = file.getSize();
  59. fileHashCode = FileHelpers::calculateFileHashCode (file);
  60. }
  61. private:
  62. File file;
  63. Time fileModificationTime;
  64. int64 fileHashCode, fileSize;
  65. };
  66. #endif // __JUCER_FILEHELPERS_JUCEHEADER__