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.

86 lines
3.1KB

  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. bool isAbsolutePath (const String& path);
  33. // A windows-aware version of File::getRelativePath()
  34. String getRelativePathFrom (const File& file, const File& sourceFolder);
  35. }
  36. //==============================================================================
  37. class FileModificationDetector
  38. {
  39. public:
  40. FileModificationDetector (const File& file_)
  41. : file (file_)
  42. {
  43. }
  44. const File& getFile() const { return file; }
  45. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  46. bool hasBeenModified() const
  47. {
  48. return fileModificationTime != file.getLastModificationTime()
  49. && (fileSize != file.getSize()
  50. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  51. }
  52. void updateHash()
  53. {
  54. fileModificationTime = file.getLastModificationTime();
  55. fileSize = file.getSize();
  56. fileHashCode = FileHelpers::calculateFileHashCode (file);
  57. }
  58. private:
  59. File file;
  60. Time fileModificationTime;
  61. int64 fileHashCode, fileSize;
  62. };
  63. #endif // __JUCER_FILEHELPERS_JUCEHEADER__