| @@ -219,6 +219,11 @@ bool File::setReadOnly (const bool shouldBeReadOnly, | |||||
| return setFileReadOnlyInternal (shouldBeReadOnly) && worked; | return setFileReadOnlyInternal (shouldBeReadOnly) && worked; | ||||
| } | } | ||||
| bool File::setExecutePermission (bool shouldBeExecutable) const | |||||
| { | |||||
| return setFileExecutableInternal (shouldBeExecutable); | |||||
| } | |||||
| bool File::deleteRecursively() const | bool File::deleteRecursively() const | ||||
| { | { | ||||
| bool worked = true; | bool worked = true; | ||||
| @@ -348,6 +348,13 @@ public: | |||||
| bool setReadOnly (bool shouldBeReadOnly, | bool setReadOnly (bool shouldBeReadOnly, | ||||
| bool applyRecursively = false) const; | bool applyRecursively = false) const; | ||||
| /** Changes the execute-permissions of a file. | |||||
| @param shouldBeExecutable whether to add or remove execute-permission | |||||
| @returns true if it manages to change the file's permissions. | |||||
| */ | |||||
| bool setExecutePermission (bool shouldBeExecutable) const; | |||||
| /** Returns true if this file is a hidden or system file. | /** Returns true if this file is a hidden or system file. | ||||
| The criteria for deciding whether a file is hidden are platform-dependent. | The criteria for deciding whether a file is hidden are platform-dependent. | ||||
| */ | */ | ||||
| @@ -968,6 +975,7 @@ private: | |||||
| bool setFileTimesInternal (int64 m, int64 a, int64 c) const; | bool setFileTimesInternal (int64 m, int64 a, int64 c) const; | ||||
| void getFileTimesInternal (int64& m, int64& a, int64& c) const; | void getFileTimesInternal (int64& m, int64& a, int64& c) const; | ||||
| bool setFileReadOnlyInternal (bool) const; | bool setFileReadOnlyInternal (bool) const; | ||||
| bool setFileExecutableInternal (bool) const; | |||||
| }; | }; | ||||
| #endif // JUCE_FILE_H_INCLUDED | #endif // JUCE_FILE_H_INCLUDED | ||||
| @@ -304,23 +304,33 @@ bool File::hasWriteAccess() const | |||||
| return false; | return false; | ||||
| } | } | ||||
| bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const | |||||
| static bool setFileModeFlags (const String& fullPath, mode_t flags, bool shouldSet) noexcept | |||||
| { | { | ||||
| juce_statStruct info; | juce_statStruct info; | ||||
| if (! juce_stat (fullPath, info)) | if (! juce_stat (fullPath, info)) | ||||
| return false; | return false; | ||||
| info.st_mode &= 0777; // Just permissions | |||||
| info.st_mode &= 0777; | |||||
| if (shouldBeReadOnly) | |||||
| info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); | |||||
| if (shouldSet) | |||||
| info.st_mode |= flags; | |||||
| else | else | ||||
| // Give everybody write permission? | |||||
| info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; | |||||
| info.st_mode &= ~flags; | |||||
| return chmod (fullPath.toUTF8(), info.st_mode) == 0; | return chmod (fullPath.toUTF8(), info.st_mode) == 0; | ||||
| } | } | ||||
| bool File::setFileReadOnlyInternal (bool shouldBeReadOnly) const | |||||
| { | |||||
| // Hmm.. should we give global write permission or just the current user? | |||||
| return setFileModeFlags (fullPath, S_IWUSR | S_IWGRP | S_IWOTH, ! shouldBeReadOnly); | |||||
| } | |||||
| bool File::setFileExecutableInternal (bool shouldBeExecutable) const | |||||
| { | |||||
| return setFileModeFlags (fullPath, S_IXUSR | S_IXGRP | S_IXOTH, shouldBeExecutable); | |||||
| } | |||||
| void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const | void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const | ||||
| { | { | ||||
| modificationTime = 0; | modificationTime = 0; | ||||
| @@ -328,11 +338,12 @@ void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int | |||||
| creationTime = 0; | creationTime = 0; | ||||
| juce_statStruct info; | juce_statStruct info; | ||||
| if (juce_stat (fullPath, info)) | if (juce_stat (fullPath, info)) | ||||
| { | { | ||||
| modificationTime = (int64) info.st_mtime * 1000; | |||||
| accessTime = (int64) info.st_atime * 1000; | |||||
| creationTime = (int64) info.st_ctime * 1000; | |||||
| modificationTime = (int64) info.st_mtime * 1000; | |||||
| accessTime = (int64) info.st_atime * 1000; | |||||
| creationTime = (int64) info.st_ctime * 1000; | |||||
| } | } | ||||
| } | } | ||||
| @@ -163,6 +163,12 @@ bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const | |||||
| || SetFileAttributes (fullPath.toWideCharPointer(), newAtts) != FALSE; | || SetFileAttributes (fullPath.toWideCharPointer(), newAtts) != FALSE; | ||||
| } | } | ||||
| bool File::setFileExecutableInternal (bool shouldBeExecutable) | |||||
| { | |||||
| // XXX is this possible? | |||||
| return false; | |||||
| } | |||||
| bool File::isHidden() const | bool File::isHidden() const | ||||
| { | { | ||||
| return (WindowsFileHelpers::getAtts (fullPath) & FILE_ATTRIBUTE_HIDDEN) != 0; | return (WindowsFileHelpers::getAtts (fullPath) & FILE_ATTRIBUTE_HIDDEN) != 0; | ||||