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.

91 lines
3.3KB

  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. 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. class FileModificationDetector
  42. {
  43. public:
  44. FileModificationDetector (const File& f)
  45. : file (f)
  46. {
  47. }
  48. const File& getFile() const { return file; }
  49. void fileHasBeenRenamed (const File& newFile) { file = newFile; }
  50. bool hasBeenModified() const
  51. {
  52. return fileModificationTime != file.getLastModificationTime()
  53. && (fileSize != file.getSize()
  54. || FileHelpers::calculateFileHashCode (file) != fileHashCode);
  55. }
  56. void updateHash()
  57. {
  58. fileModificationTime = file.getLastModificationTime();
  59. fileSize = file.getSize();
  60. fileHashCode = FileHelpers::calculateFileHashCode (file);
  61. }
  62. private:
  63. File file;
  64. Time fileModificationTime;
  65. int64 fileHashCode, fileSize;
  66. };
  67. #endif // __JUCER_FILEHELPERS_JUCEHEADER__