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.

82 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_FILEHELPERS_JUCEHEADER__
  19. #define __JUCER_FILEHELPERS_JUCEHEADER__
  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, int 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. bool shouldPathsBeRelative (String path1, String path2);
  32. }
  33. //==============================================================================
  34. class FileModificationDetector
  35. {
  36. public:
  37. FileModificationDetector (const File& file_)
  38. : file (file_)
  39. {
  40. }
  41. const File& getFile() const { return file; }
  42. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  43. bool hasBeenModified() const
  44. {
  45. return fileModificationTime != file.getLastModificationTime()
  46. && (fileSize != file.getSize()
  47. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  48. }
  49. void updateHash()
  50. {
  51. fileModificationTime = file.getLastModificationTime();
  52. fileSize = file.getSize();
  53. fileHashCode = FileHelpers::calculateFileHashCode (file);
  54. }
  55. private:
  56. File file;
  57. Time fileModificationTime;
  58. int64 fileHashCode, fileSize;
  59. };
  60. #endif // __JUCER_FILEHELPERS_JUCEHEADER__