mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-06 04:00:08 +00:00
Major overhaul of the String class, to rely more heavily on the CharPointer_UTF classes. On win32, the juce_wchar type is now a typedef for a 32-bit int, rather than the 16-bit wchar_t. The String class now has toUTF8(), toUTF16() and toUTF32() methods to retrieve the string in different formats.
This commit is contained in:
parent
1b05a7d46d
commit
e235912ae5
79 changed files with 2765 additions and 2028 deletions
|
|
@ -56,14 +56,12 @@ namespace WindowsFileHelpers
|
|||
reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
|
||||
}
|
||||
|
||||
const String getDriveFromPath (const String& path)
|
||||
const String getDriveFromPath (String path)
|
||||
{
|
||||
const int length = path.length();
|
||||
HeapBlock <WCHAR> stringCopy (length + 1);
|
||||
path.copyToUnicode (stringCopy, length);
|
||||
WCHAR* p = const_cast <WCHAR*> (path.toUTF16().getAddress());
|
||||
|
||||
if (PathStripToRoot (stringCopy))
|
||||
return String (stringCopy);
|
||||
if (PathStripToRoot (p))
|
||||
return String ((const WCHAR*) p);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
@ -72,7 +70,7 @@ namespace WindowsFileHelpers
|
|||
{
|
||||
ULARGE_INTEGER spc, tot, totFree;
|
||||
|
||||
if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
|
||||
if (GetDiskFreeSpaceEx (getDriveFromPath (path).toUTF16(), &spc, &tot, &totFree))
|
||||
return total ? (int64) tot.QuadPart
|
||||
: (int64) spc.QuadPart;
|
||||
|
||||
|
|
@ -81,7 +79,7 @@ namespace WindowsFileHelpers
|
|||
|
||||
unsigned int getWindowsDriveType (const String& path)
|
||||
{
|
||||
return GetDriveType (getDriveFromPath (path));
|
||||
return GetDriveType (getDriveFromPath (path).toUTF16());
|
||||
}
|
||||
|
||||
const File getSpecialFolderPath (int type)
|
||||
|
|
@ -104,25 +102,25 @@ const String File::separatorString ("\\");
|
|||
bool File::exists() const
|
||||
{
|
||||
return fullPath.isNotEmpty()
|
||||
&& GetFileAttributes (fullPath) != INVALID_FILE_ATTRIBUTES;
|
||||
&& GetFileAttributes (fullPath.toUTF16()) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
bool File::existsAsFile() const
|
||||
{
|
||||
return fullPath.isNotEmpty()
|
||||
&& (GetFileAttributes (fullPath) & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
||||
&& (GetFileAttributes (fullPath.toUTF16()) & FILE_ATTRIBUTE_DIRECTORY) == 0;
|
||||
}
|
||||
|
||||
bool File::isDirectory() const
|
||||
{
|
||||
const DWORD attr = GetFileAttributes (fullPath);
|
||||
const DWORD attr = GetFileAttributes (fullPath.toUTF16());
|
||||
return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
|
||||
}
|
||||
|
||||
bool File::hasWriteAccess() const
|
||||
{
|
||||
if (exists())
|
||||
return (GetFileAttributes (fullPath) & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
return (GetFileAttributes (fullPath.toUTF16()) & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
|
||||
// on windows, it seems that even read-only directories can still be written into,
|
||||
// so checking the parent directory's permissions would return the wrong result..
|
||||
|
|
@ -131,7 +129,7 @@ bool File::hasWriteAccess() const
|
|||
|
||||
bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const
|
||||
{
|
||||
DWORD attr = GetFileAttributes (fullPath);
|
||||
DWORD attr = GetFileAttributes (fullPath.toUTF16());
|
||||
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
|
|
@ -144,12 +142,12 @@ bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const
|
|||
else
|
||||
attr &= ~FILE_ATTRIBUTE_READONLY;
|
||||
|
||||
return SetFileAttributes (fullPath, attr) != FALSE;
|
||||
return SetFileAttributes (fullPath.toUTF16(), attr) != FALSE;
|
||||
}
|
||||
|
||||
bool File::isHidden() const
|
||||
{
|
||||
return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||
return (GetFileAttributes (getFullPathName().toUTF16()) & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -158,9 +156,9 @@ bool File::deleteFile() const
|
|||
if (! exists())
|
||||
return true;
|
||||
else if (isDirectory())
|
||||
return RemoveDirectory (fullPath) != 0;
|
||||
return RemoveDirectory (fullPath.toUTF16()) != 0;
|
||||
else
|
||||
return DeleteFile (fullPath) != 0;
|
||||
return DeleteFile (fullPath.toUTF16()) != 0;
|
||||
}
|
||||
|
||||
bool File::moveToTrash() const
|
||||
|
|
@ -173,7 +171,7 @@ bool File::moveToTrash() const
|
|||
|
||||
// The string we pass in must be double null terminated..
|
||||
String doubleNullTermPath (getFullPathName() + " ");
|
||||
TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
|
||||
WCHAR* const p = const_cast <WCHAR*> (doubleNullTermPath.toUTF16().getAddress());
|
||||
p [getFullPathName().length()] = 0;
|
||||
|
||||
fos.wFunc = FO_DELETE;
|
||||
|
|
@ -186,17 +184,17 @@ bool File::moveToTrash() const
|
|||
|
||||
bool File::copyInternal (const File& dest) const
|
||||
{
|
||||
return CopyFile (fullPath, dest.getFullPathName(), false) != 0;
|
||||
return CopyFile (fullPath.toUTF16(), dest.getFullPathName().toUTF16(), false) != 0;
|
||||
}
|
||||
|
||||
bool File::moveInternal (const File& dest) const
|
||||
{
|
||||
return MoveFile (fullPath, dest.getFullPathName()) != 0;
|
||||
return MoveFile (fullPath.toUTF16(), dest.getFullPathName().toUTF16()) != 0;
|
||||
}
|
||||
|
||||
void File::createDirectoryInternal (const String& fileName) const
|
||||
{
|
||||
CreateDirectory (fileName, 0);
|
||||
CreateDirectory (fileName.toUTF16(), 0);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -212,7 +210,7 @@ void FileInputStream::openHandle()
|
|||
{
|
||||
totalSize = file.getSize();
|
||||
|
||||
HANDLE h = CreateFile (file.getFullPathName(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
HANDLE h = CreateFile (file.getFullPathName().toUTF16(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
|
||||
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
|
|
@ -239,7 +237,7 @@ size_t FileInputStream::readInternal (void* buffer, size_t numBytes)
|
|||
//==============================================================================
|
||||
void FileOutputStream::openHandle()
|
||||
{
|
||||
HANDLE h = CreateFile (file.getFullPathName(), GENERIC_WRITE, FILE_SHARE_READ, 0,
|
||||
HANDLE h = CreateFile (file.getFullPathName().toUTF16(), GENERIC_WRITE, FILE_SHARE_READ, 0,
|
||||
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
|
|
@ -284,7 +282,7 @@ int64 File::getSize() const
|
|||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA attributes;
|
||||
|
||||
if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes))
|
||||
if (GetFileAttributesEx (fullPath.toUTF16(), GetFileExInfoStandard, &attributes))
|
||||
return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
|
||||
|
||||
return 0;
|
||||
|
|
@ -295,7 +293,7 @@ void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int
|
|||
using namespace WindowsFileHelpers;
|
||||
WIN32_FILE_ATTRIBUTE_DATA attributes;
|
||||
|
||||
if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes))
|
||||
if (GetFileAttributesEx (fullPath.toUTF16(), GetFileExInfoStandard, &attributes))
|
||||
{
|
||||
modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
|
||||
creationTime = fileTimeToTime (&attributes.ftCreationTime);
|
||||
|
|
@ -312,7 +310,7 @@ bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64
|
|||
using namespace WindowsFileHelpers;
|
||||
|
||||
bool ok = false;
|
||||
HANDLE h = CreateFile (fullPath, GENERIC_WRITE, FILE_SHARE_READ, 0,
|
||||
HANDLE h = CreateFile (fullPath.toUTF16(), GENERIC_WRITE, FILE_SHARE_READ, 0,
|
||||
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
|
|
@ -362,7 +360,7 @@ void File::findFileSystemRoots (Array<File>& destArray)
|
|||
const String File::getVolumeLabel() const
|
||||
{
|
||||
TCHAR dest[64];
|
||||
if (! GetVolumeInformation (WindowsFileHelpers::getDriveFromPath (getFullPathName()), dest,
|
||||
if (! GetVolumeInformation (WindowsFileHelpers::getDriveFromPath (getFullPathName()).toUTF16(), dest,
|
||||
numElementsInArray (dest), 0, 0, 0, 0, 0))
|
||||
dest[0] = 0;
|
||||
|
||||
|
|
@ -374,7 +372,7 @@ int File::getVolumeSerialNumber() const
|
|||
TCHAR dest[64];
|
||||
DWORD serialNum;
|
||||
|
||||
if (! GetVolumeInformation (WindowsFileHelpers::getDriveFromPath (getFullPathName()), dest,
|
||||
if (! GetVolumeInformation (WindowsFileHelpers::getDriveFromPath (getFullPathName()).toUTF16(), dest,
|
||||
numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
|
||||
return 0;
|
||||
|
||||
|
|
@ -486,7 +484,7 @@ const File File::getCurrentWorkingDirectory()
|
|||
|
||||
bool File::setAsCurrentWorkingDirectory() const
|
||||
{
|
||||
return SetCurrentDirectory (getFullPathName()) != FALSE;
|
||||
return SetCurrentDirectory (getFullPathName().toUTF16()) != FALSE;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -495,11 +493,11 @@ const String File::getVersion() const
|
|||
String result;
|
||||
|
||||
DWORD handle = 0;
|
||||
DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
|
||||
DWORD bufferSize = GetFileVersionInfoSize (getFullPathName().toUTF16(), &handle);
|
||||
HeapBlock<char> buffer;
|
||||
buffer.calloc (bufferSize);
|
||||
|
||||
if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
|
||||
if (GetFileVersionInfo (getFullPathName().toUTF16(), 0, bufferSize, buffer))
|
||||
{
|
||||
VS_FIXEDFILEINFO* vffi;
|
||||
UINT len = 0;
|
||||
|
|
@ -533,7 +531,7 @@ const File File::getLinkedTarget() const
|
|||
ComSmartPtr <IPersistFile> persistFile;
|
||||
if (SUCCEEDED (shellLink.QueryInterface (IID_IPersistFile, persistFile)))
|
||||
{
|
||||
if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
|
||||
if (SUCCEEDED (persistFile->Load (p.toUTF16(), STGM_READ))
|
||||
&& SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
|
||||
{
|
||||
WIN32_FIND_DATA winFindData;
|
||||
|
|
@ -574,7 +572,7 @@ public:
|
|||
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
handle = FindFirstFile (directoryWithWildCard, &findData);
|
||||
handle = FindFirstFile (directoryWithWildCard.toUTF16(), &findData);
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
|
@ -628,7 +626,7 @@ bool PlatformUtilities::openDocument (const String& fileName, const String& para
|
|||
|
||||
JUCE_TRY
|
||||
{
|
||||
hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
|
||||
hInstance = ShellExecute (0, 0, fileName.toUTF16(), parameters.toUTF16(), 0, SW_SHOWDEFAULT);
|
||||
}
|
||||
JUCE_CATCH_ALL
|
||||
|
||||
|
|
@ -655,9 +653,9 @@ public:
|
|||
{
|
||||
cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
|
||||
|
||||
pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
|
||||
pipeH = isPipe ? CreateNamedPipe (file.toUTF16(), PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
|
||||
PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
|
||||
: CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
|
||||
: CreateFile (file.toUTF16(), GENERIC_READ | GENERIC_WRITE, 0, 0,
|
||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue