| @@ -129,7 +129,7 @@ namespace WindowsFileHelpers | |||
| File getSpecialFolderPath (int type) | |||
| { | |||
| WCHAR path [MAX_PATH + 256]; | |||
| WCHAR path[MAX_PATH + 256]; | |||
| if (SHGetSpecialFolderPath (0, path, type, FALSE)) | |||
| return File (String (path)); | |||
| @@ -139,7 +139,7 @@ namespace WindowsFileHelpers | |||
| File getModuleFileName (HINSTANCE moduleHandle) | |||
| { | |||
| WCHAR dest [MAX_PATH + 256]; | |||
| WCHAR dest[MAX_PATH + 256]; | |||
| dest[0] = 0; | |||
| GetModuleFileName (moduleHandle, dest, (DWORD) numElementsInArray (dest)); | |||
| return File (String (dest)); | |||
| @@ -147,7 +147,7 @@ namespace WindowsFileHelpers | |||
| Result getResultForLastError() | |||
| { | |||
| TCHAR messageBuffer [256] = { 0 }; | |||
| TCHAR messageBuffer[256] = { 0 }; | |||
| FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |||
| nullptr, GetLastError(), MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), | |||
| @@ -181,7 +181,7 @@ bool File::existsAsFile() const | |||
| bool File::isDirectory() const | |||
| { | |||
| const DWORD attr = WindowsFileHelpers::getAtts (fullPath); | |||
| auto attr = WindowsFileHelpers::getAtts (fullPath); | |||
| return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0 && attr != INVALID_FILE_ATTRIBUTES; | |||
| } | |||
| @@ -250,22 +250,22 @@ bool File::moveToTrash() const | |||
| bool File::copyInternal (const File& dest) const | |||
| { | |||
| return CopyFile (fullPath.toWideCharPointer(), dest.getFullPathName().toWideCharPointer(), false) != 0; | |||
| return CopyFile (fullPath.toWideCharPointer(), | |||
| dest.getFullPathName().toWideCharPointer(), false) != 0; | |||
| } | |||
| bool File::moveInternal (const File& dest) const | |||
| { | |||
| return MoveFile (fullPath.toWideCharPointer(), dest.getFullPathName().toWideCharPointer()) != 0; | |||
| return MoveFile (fullPath.toWideCharPointer(), | |||
| dest.getFullPathName().toWideCharPointer()) != 0; | |||
| } | |||
| bool File::replaceInternal (const File& dest) const | |||
| { | |||
| void* lpExclude = 0; | |||
| void* lpReserved = 0; | |||
| return ReplaceFile (dest.getFullPathName().toWideCharPointer(), fullPath.toWideCharPointer(), | |||
| 0, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, | |||
| lpExclude, lpReserved) != 0; | |||
| return ReplaceFile (dest.getFullPathName().toWideCharPointer(), | |||
| fullPath.toWideCharPointer(), | |||
| 0, REPLACEFILE_IGNORE_MERGE_ERRORS | 4 /*REPLACEFILE_IGNORE_ACL_ERRORS*/, | |||
| nullptr, nullptr) != 0; | |||
| } | |||
| Result File::createDirectoryInternal (const String& fileName) const | |||
| @@ -279,14 +279,16 @@ int64 juce_fileSetPosition (void* handle, int64 pos) | |||
| { | |||
| LARGE_INTEGER li; | |||
| li.QuadPart = pos; | |||
| li.LowPart = SetFilePointer ((HANDLE) handle, (LONG) li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails) | |||
| li.LowPart = SetFilePointer ((HANDLE) handle, (LONG) li.LowPart, | |||
| &li.HighPart, FILE_BEGIN); // (returns -1 if it fails) | |||
| return li.QuadPart; | |||
| } | |||
| void FileInputStream::openHandle() | |||
| { | |||
| HANDLE h = CreateFile (file.getFullPathName().toWideCharPointer(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, | |||
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | |||
| auto h = CreateFile (file.getFullPathName().toWideCharPointer(), | |||
| GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, | |||
| OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | |||
| if (h != INVALID_HANDLE_VALUE) | |||
| fileHandle = (void*) h; | |||
| @@ -304,6 +306,7 @@ size_t FileInputStream::readInternal (void* buffer, size_t numBytes) | |||
| if (fileHandle != 0) | |||
| { | |||
| DWORD actualNum = 0; | |||
| if (! ReadFile ((HANDLE) fileHandle, buffer, (DWORD) numBytes, &actualNum, 0)) | |||
| status = WindowsFileHelpers::getResultForLastError(); | |||
| @@ -316,8 +319,9 @@ size_t FileInputStream::readInternal (void* buffer, size_t numBytes) | |||
| //============================================================================== | |||
| void FileOutputStream::openHandle() | |||
| { | |||
| HANDLE h = CreateFile (file.getFullPathName().toWideCharPointer(), GENERIC_WRITE, FILE_SHARE_READ, 0, | |||
| OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | |||
| auto h = CreateFile (file.getFullPathName().toWideCharPointer(), | |||
| GENERIC_WRITE, FILE_SHARE_READ, 0, | |||
| OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | |||
| if (h != INVALID_HANDLE_VALUE) | |||
| { | |||
| @@ -343,16 +347,13 @@ void FileOutputStream::closeHandle() | |||
| ssize_t FileOutputStream::writeInternal (const void* bufferToWrite, size_t numBytes) | |||
| { | |||
| DWORD actualNum = 0; | |||
| if (fileHandle != nullptr) | |||
| { | |||
| DWORD actualNum = 0; | |||
| if (! WriteFile ((HANDLE) fileHandle, bufferToWrite, (DWORD) numBytes, &actualNum, 0)) | |||
| status = WindowsFileHelpers::getResultForLastError(); | |||
| return (ssize_t) actualNum; | |||
| } | |||
| return 0; | |||
| return (ssize_t) actualNum; | |||
| } | |||
| void FileOutputStream::flushInternal() | |||
| @@ -396,15 +397,17 @@ void MemoryMappedFile::openInternal (const File& file, AccessMode mode, bool exc | |||
| access = FILE_MAP_ALL_ACCESS; | |||
| } | |||
| HANDLE h = CreateFile (file.getFullPathName().toWideCharPointer(), accessMode, | |||
| exclusive ? 0 : (FILE_SHARE_READ | (mode == readWrite ? FILE_SHARE_WRITE : 0)), 0, | |||
| createType, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | |||
| auto h = CreateFile (file.getFullPathName().toWideCharPointer(), accessMode, | |||
| exclusive ? 0 : (FILE_SHARE_READ | (mode == readWrite ? FILE_SHARE_WRITE : 0)), 0, | |||
| createType, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); | |||
| if (h != INVALID_HANDLE_VALUE) | |||
| { | |||
| fileHandle = (void*) h; | |||
| HANDLE mappingHandle = CreateFileMapping (h, 0, protect, (DWORD) (range.getEnd() >> 32), (DWORD) range.getEnd(), 0); | |||
| auto mappingHandle = CreateFileMapping (h, 0, protect, | |||
| (DWORD) (range.getEnd() >> 32), | |||
| (DWORD) range.getEnd(), 0); | |||
| if (mappingHandle != 0) | |||
| { | |||
| @@ -461,8 +464,9 @@ bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 | |||
| using namespace WindowsFileHelpers; | |||
| bool ok = false; | |||
| HANDLE h = CreateFile (fullPath.toWideCharPointer(), GENERIC_WRITE, FILE_SHARE_READ, 0, | |||
| OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | |||
| auto h = CreateFile (fullPath.toWideCharPointer(), | |||
| GENERIC_WRITE, FILE_SHARE_READ, 0, | |||
| OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | |||
| if (h != INVALID_HANDLE_VALUE) | |||
| { | |||
| @@ -482,7 +486,7 @@ bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 | |||
| //============================================================================== | |||
| void File::findFileSystemRoots (Array<File>& destArray) | |||
| { | |||
| TCHAR buffer [2048] = { 0 }; | |||
| TCHAR buffer[2048] = { 0 }; | |||
| GetLogicalDriveStrings (2048, buffer); | |||
| const TCHAR* n = buffer; | |||
| @@ -499,13 +503,14 @@ void File::findFileSystemRoots (Array<File>& destArray) | |||
| roots.sort (true); | |||
| for (int i = 0; i < roots.size(); ++i) | |||
| destArray.add (roots [i]); | |||
| destArray.add (roots[i]); | |||
| } | |||
| //============================================================================== | |||
| String File::getVolumeLabel() const | |||
| { | |||
| TCHAR dest[64]; | |||
| if (! GetVolumeInformation (WindowsFileHelpers::getDriveFromPath (getFullPathName()).toWideCharPointer(), dest, | |||
| (DWORD) numElementsInArray (dest), 0, 0, 0, 0, 0)) | |||
| dest[0] = 0; | |||
| @@ -539,9 +544,9 @@ uint64 File::getFileIdentifier() const | |||
| { | |||
| uint64 result = 0; | |||
| HANDLE h = CreateFile (getFullPathName().toWideCharPointer(), | |||
| GENERIC_READ, FILE_SHARE_READ, nullptr, | |||
| OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); | |||
| auto h = CreateFile (getFullPathName().toWideCharPointer(), | |||
| GENERIC_READ, FILE_SHARE_READ, nullptr, | |||
| OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); | |||
| if (h != INVALID_HANDLE_VALUE) | |||
| { | |||
| @@ -568,7 +573,7 @@ bool File::isOnHardDisk() const | |||
| if (fullPath.isEmpty()) | |||
| return false; | |||
| const unsigned int n = WindowsFileHelpers::getWindowsDriveType (getFullPathName()); | |||
| auto n = WindowsFileHelpers::getWindowsDriveType (getFullPathName()); | |||
| if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':') | |||
| return n != DRIVE_REMOVABLE; | |||
| @@ -583,7 +588,7 @@ bool File::isOnRemovableDrive() const | |||
| if (fullPath.isEmpty()) | |||
| return false; | |||
| const unsigned int n = WindowsFileHelpers::getWindowsDriveType (getFullPathName()); | |||
| auto n = WindowsFileHelpers::getWindowsDriveType (getFullPathName()); | |||
| return n == DRIVE_CDROM | |||
| || n == DRIVE_REMOTE | |||
| @@ -612,7 +617,7 @@ File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) | |||
| case tempDirectory: | |||
| { | |||
| WCHAR dest [2048]; | |||
| WCHAR dest[2048]; | |||
| dest[0] = 0; | |||
| GetTempPath ((DWORD) numElementsInArray (dest), dest); | |||
| return File (String (dest)); | |||
| @@ -620,7 +625,7 @@ File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) | |||
| case windowsSystemDirectory: | |||
| { | |||
| WCHAR dest [2048]; | |||
| WCHAR dest[2048]; | |||
| dest[0] = 0; | |||
| GetSystemDirectoryW (dest, (UINT) numElementsInArray (dest)); | |||
| return File (String (dest)); | |||
| @@ -645,7 +650,7 @@ File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) | |||
| //============================================================================== | |||
| File File::getCurrentWorkingDirectory() | |||
| { | |||
| WCHAR dest [MAX_PATH + 256]; | |||
| WCHAR dest[MAX_PATH + 256]; | |||
| dest[0] = 0; | |||
| GetCurrentDirectory ((DWORD) numElementsInArray (dest), dest); | |||
| return File (String (dest)); | |||
| @@ -710,7 +715,7 @@ static String readWindowsLnkFile (File lnkFile, bool wantsAbsolutePath) | |||
| && (! wantsAbsolutePath || SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))) | |||
| { | |||
| WIN32_FIND_DATA winFindData; | |||
| WCHAR resolvedPath [MAX_PATH]; | |||
| WCHAR resolvedPath[MAX_PATH]; | |||
| DWORD flags = SLGP_UNCPRIORITY; | |||