diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index c5179d4df5..eaec33c9aa 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -476,6 +476,29 @@ public: T* p; }; +template +class ComBaseClassHelper : public ComClass +{ +public: + ComBaseClassHelper() : refCount (1) {} + virtual ~ComBaseClassHelper() {} + + HRESULT __stdcall QueryInterface (REFIID refId, void __RPC_FAR* __RPC_FAR* result) + { + if (refId == __uuidof (ComClass)) { AddRef(); *result = dynamic_cast (this); return S_OK; } + if (refId == IID_IUnknown) { AddRef(); *result = dynamic_cast (this); return S_OK; } + + *result = 0; + return E_NOINTERFACE; + } + + ULONG __stdcall AddRef() { return ++refCount; } + ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + +protected: + int refCount; +}; + #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__ /*** End of inlined file: juce_win32_NativeIncludes.h ***/ @@ -5410,20 +5433,19 @@ void OutputStream::writeText (const String& text, const bool asUnicode, } } -int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite) +int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWrite) { if (numBytesToWrite < 0) - numBytesToWrite = 0x7fffffff; + numBytesToWrite = std::numeric_limits::max(); int numWritten = 0; while (numBytesToWrite > 0 && ! source.isExhausted()) { char buffer [8192]; + const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer))); - const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer))); - - if (num == 0) + if (num <= 0) break; write (buffer, num); @@ -5457,6 +5479,22 @@ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const return stream; } +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data) +{ + stream.write (data.getData(), (int) data.getSize()); + return stream; +} + +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead) +{ + const ScopedPointer in (fileToRead.createInputStream()); + + if (in != 0) + stream.writeFromInputStream (*in, -1); + + return stream; +} + END_JUCE_NAMESPACE /*** End of inlined file: juce_OutputStream.cpp ***/ @@ -5582,16 +5620,6 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE -bool juce_canWriteToFile (const String& fileName); -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly); -void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime); -bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime); -bool juce_copyFile (const String& source, const String& dest); -bool juce_moveFile (const String& source, const String& dest); -bool juce_launchFile (const String& fileName, const String& parameters); - -const File File::nonexistent; - File::File (const String& fullPathName) : fullPath (parseAbsolutePath (fullPathName)) { @@ -5624,6 +5652,8 @@ File& File::operator= (const File& other) return *this; } +const File File::nonexistent; + const String File::parseAbsolutePath (const String& p) { if (p.isEmpty()) @@ -5753,24 +5783,6 @@ bool File::operator> (const File& other) const #endif } -bool File::hasWriteAccess() const -{ - if (exists()) - return juce_canWriteToFile (fullPath); - -#if ! JUCE_WINDOWS - else if ((! isDirectory()) && fullPath.containsChar (separator)) - return getParentDirectory().hasWriteAccess(); - else - return false; -#else - // 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.. - else - return true; -#endif -} - bool File::setReadOnly (const bool shouldBeReadOnly, const bool applyRecursively) const { @@ -5785,7 +5797,7 @@ bool File::setReadOnly (const bool shouldBeReadOnly, worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked; } - return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked; + return setFileReadOnlyInternal (shouldBeReadOnly) && worked; } bool File::deleteRecursively() const @@ -5815,18 +5827,13 @@ bool File::moveFileTo (const File& newFile) const if (! newFile.deleteFile()) return false; - return juce_moveFile (fullPath, newFile.fullPath); + return moveInternal (newFile); } bool File::copyFileTo (const File& newFile) const { - if (*this == newFile) - return true; - - if (! newFile.deleteFile()) - return false; - - return juce_copyFile (fullPath, newFile.fullPath); + return (*this == newFile) + || (exists() && newFile.deleteFile() && copyInternal (newFile)); } bool File::copyDirectoryTo (const File& newDirectory) const @@ -6048,38 +6055,27 @@ bool File::createDirectory() const const Time File::getCreationTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (c); } -bool File::setCreationTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds()); -} - const Time File::getLastModificationTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (m); } -bool File::setLastModificationTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0); -} - const Time File::getLastAccessTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (a); } -bool File::setLastAccessTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0); -} +bool File::setLastModificationTime (const Time& t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); } +bool File::setLastAccessTime (const Time& t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); } +bool File::setCreationTime (const Time& t) const { return setFileTimesInternal (0, 0, t.toMilliseconds()); } bool File::loadFileAsData (MemoryBlock& destBlock) const { @@ -6317,7 +6313,7 @@ const File File::withFileExtension (const String& newExtension) const bool File::startAsProcess (const String& parameters) const { - return exists() && juce_launchFile (fullPath, parameters); + return exists() && PlatformUtilities::openDocument (fullPath, parameters); } FileInputStream* File::createInputStream() const @@ -7796,20 +7792,10 @@ public: juce_closeInternetFile (handle); } - bool isError() const - { - return handle == 0; - } - - int64 getTotalLength() - { - return juce_getInternetFileContentLength (handle); - } - - bool isExhausted() - { - return finished; - } + bool isError() const { return handle == 0; } + int64 getTotalLength() { return juce_getInternetFileContentLength (handle); } + bool isExhausted() { return finished; } + int64 getPosition() { return position; } int read (void* dest, int bytes) { @@ -7829,11 +7815,6 @@ public: } } - int64 getPosition() - { - return position; - } - bool setPosition (int64 wantedPos) { if (wantedPos != position) @@ -7882,64 +7863,52 @@ private: void createHeadersAndPostData (const URL& url) { + MemoryOutputStream data (256, 256, &postData); + if (url.getFilesToUpload().size() > 0) { // need to upload some files, so do it as multi-part... - String boundary (String::toHexString (Random::getSystemRandom().nextInt64())); + const String boundary (String::toHexString (Random::getSystemRandom().nextInt64())); headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n"; - appendUTF8ToPostData ("--" + boundary); + data << "--" << boundary; int i; for (i = 0; i < url.getParameters().size(); ++i) { - String s; - s << "\r\nContent-Disposition: form-data; name=\"" - << url.getParameters().getAllKeys() [i] - << "\"\r\n\r\n" - << url.getParameters().getAllValues() [i] - << "\r\n--" - << boundary; - - appendUTF8ToPostData (s); + data << "\r\nContent-Disposition: form-data; name=\"" + << url.getParameters().getAllKeys() [i] + << "\"\r\n\r\n" + << url.getParameters().getAllValues() [i] + << "\r\n--" + << boundary; } for (i = 0; i < url.getFilesToUpload().size(); ++i) { - const File f (url.getFilesToUpload().getAllValues() [i]); + const File file (url.getFilesToUpload().getAllValues() [i]); const String paramName (url.getFilesToUpload().getAllKeys() [i]); - String s; - s << "\r\nContent-Disposition: form-data; name=\"" - << paramName - << "\"; filename=\"" - << f.getFileName() - << "\"\r\n"; + data << "\r\nContent-Disposition: form-data; name=\"" << paramName + << "\"; filename=\"" << file.getFileName() << "\"\r\n"; const String mimeType (url.getMimeTypesOfUploadFiles() .getValue (paramName, String::empty)); if (mimeType.isNotEmpty()) - s << "Content-Type: " << mimeType << "\r\n"; + data << "Content-Type: " << mimeType << "\r\n"; - s << "Content-Transfer-Encoding: binary\r\n\r\n"; - - appendUTF8ToPostData (s); - - f.loadFileAsData (postData); - - s = "\r\n--" + boundary; - - appendUTF8ToPostData (s); + data << "Content-Transfer-Encoding: binary\r\n\r\n" + << file << "\r\n--" << boundary; } - appendUTF8ToPostData ("--\r\n"); + data << "--\r\n"; } else { - appendUTF8ToPostData (getMangledParameters (url.getParameters())); - appendUTF8ToPostData (url.getPostData()); + data << getMangledParameters (url.getParameters()) + << url.getPostData(); // just a short text attachment, so use simple url encoding.. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: " @@ -7948,12 +7917,6 @@ private: } } - void appendUTF8ToPostData (const String& text) - { - postData.append (text.toUTF8(), - (int) strlen (text.toUTF8())); - } - WebInputStream (const WebInputStream&); WebInputStream& operator= (const WebInputStream&); }; @@ -8091,8 +8054,6 @@ const String URL::addEscapeChars (const String& s, const bool isParameter) return result; } -extern bool juce_launchFile (const String& fileName, const String& parameters); - bool URL::launchInDefaultBrowser() const { String u (toString (true)); @@ -8100,7 +8061,7 @@ bool URL::launchInDefaultBrowser() const if (u.containsChar ('@') && ! u.containsChar (':')) u = "mailto:" + u; - return juce_launchFile (u, String::empty); + return PlatformUtilities::openDocument (u, String::empty); } END_JUCE_NAMESPACE @@ -20014,7 +19975,7 @@ void AudioFormatManager::registerFormat (AudioFormat* newFormat, #endif if (makeThisTheDefaultFormat) - defaultFormatIndex = knownFormats.size(); + defaultFormatIndex = getNumKnownFormats(); knownFormats.add (newFormat); } @@ -20041,9 +20002,6 @@ void AudioFormatManager::registerBasicFormats() void AudioFormatManager::clearFormats() { - for (int i = getNumKnownFormats(); --i >= 0;) - delete getKnownFormat(i); - knownFormats.clear(); defaultFormatIndex = 0; } @@ -20055,7 +20013,7 @@ int AudioFormatManager::getNumKnownFormats() const AudioFormat* AudioFormatManager::getKnownFormat (const int index) const { - return (AudioFormat*) knownFormats [index]; + return knownFormats [index]; } AudioFormat* AudioFormatManager::getDefaultFormat() const @@ -20108,7 +20066,7 @@ AudioFormatReader* AudioFormatManager::createReaderFor (const File& file) { // you need to actually register some formats before the manager can // use them to open a file! - jassert (knownFormats.size() > 0); + jassert (getNumKnownFormats() > 0); for (int i = 0; i < getNumKnownFormats(); ++i) { @@ -20135,7 +20093,7 @@ AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileSt { // you need to actually register some formats before the manager can // use them to open a file! - jassert (knownFormats.size() > 0); + jassert (getNumKnownFormats() > 0); ScopedPointer in (audioFileStream); @@ -54536,7 +54494,6 @@ public: for (int i = rowComponentItems.size(); --i >= 0;) { Component* const comp = rowComponents.getUnchecked(i); - bool keep = false; if (isParentOf (comp)) @@ -211841,28 +211798,32 @@ bool File::isDirectory() const return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES); } -bool juce_canWriteToFile (const String& fileName) +bool File::hasWriteAccess() const { - const DWORD attr = GetFileAttributes (fileName); - return (attr & FILE_ATTRIBUTE_READONLY) == 0; + if (exists()) + return (GetFileAttributes (fullPath) & 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.. + return true; } -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly) +bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const { - DWORD attr = GetFileAttributes (fileName); + DWORD attr = GetFileAttributes (fullPath); if (attr == INVALID_FILE_ATTRIBUTES) return false; - if (isReadOnly != juce_canWriteToFile (fileName)) + if (shouldBeReadOnly == ((attr & FILE_ATTRIBUTE_READONLY) != 0)) return true; - if (isReadOnly) + if (shouldBeReadOnly) attr |= FILE_ATTRIBUTE_READONLY; else attr &= ~FILE_ATTRIBUTE_READONLY; - return SetFileAttributes (fileName, attr) != FALSE; + return SetFileAttributes (fullPath, attr) != FALSE; } bool File::isHidden() const @@ -211901,14 +211862,14 @@ bool File::moveToTrash() const return SHFileOperation (&fos) == 0; } -bool juce_moveFile (const String& source, const String& dest) +bool File::copyInternal (const File& dest) const { - return MoveFile (source, dest) != 0; + return CopyFile (fullPath, dest.getFullPathName(), false) != 0; } -bool juce_copyFile (const String& source, const String& dest) +bool File::moveInternal (const File& dest) const { - return CopyFile (source, dest, false) != 0; + return MoveFile (fullPath, dest.getFullPathName()) != 0; } void File::createDirectoryInternal (const String& fileName) const @@ -212009,14 +211970,11 @@ static void timeToFileTime (const int64 time, FILETIME* const ft) reinterpret_cast (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000); } -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) +void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const { WIN32_FILE_ATTRIBUTE_DATA attributes; - if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes)) + if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes)) { modificationTime = fileTimeToTime (&attributes.ftLastWriteTime); creationTime = fileTimeToTime (&attributes.ftCreationTime); @@ -212028,12 +211986,9 @@ void juce_getFileTimes (const String& fileName, } } -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) +bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const { - void* const h = juce_fileOpen (fileName, true); + void* const h = juce_fileOpen (fullPath, true); bool ok = false; if (h != 0) @@ -212361,7 +212316,7 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly); } -bool juce_launchFile (const String& fileName, const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { HINSTANCE hInstance = 0; @@ -212624,14 +212579,6 @@ void NamedPipe::cancelPendingReads() #define INTERNET_OPTION_DISABLE_AUTODIAL 70 #endif -bool juce_isOnLine() -{ - DWORD connectionType; - - return InternetGetConnectedState (&connectionType, 0) != 0 - || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0; -} - struct ConnectionAndRequestStruct { HINTERNET connection, request; @@ -212880,10 +212827,9 @@ void juce_closeInternetFile (void* handle) { if (handle != 0) { - ConnectionAndRequestStruct* const crs = static_cast (handle); + ScopedPointer crs (static_cast (handle)); InternetCloseHandle (crs->request); InternetCloseHandle (crs->connection); - delete crs; } } @@ -214339,25 +214285,15 @@ private: { public: - TemporaryImage() - : image (0) - { - } - - ~TemporaryImage() - { - delete image; - } + TemporaryImage() {} + ~TemporaryImage() {} WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw() { const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB; if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format) - { - delete image; image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false); - } startTimer (3000); return image; @@ -214366,11 +214302,11 @@ private: void timerCallback() { stopTimer(); - deleteAndZero (image); + image = 0; } private: - WindowsBitmapImage* image; + ScopedPointer image; TemporaryImage (const TemporaryImage&); TemporaryImage& operator= (const TemporaryImage&); @@ -215012,35 +214948,15 @@ private: return false; } - class JuceDropTarget : public IDropTarget + class JuceDropTarget : public ComBaseClassHelper { public: JuceDropTarget (Win32ComponentPeer* const owner_) - : owner (owner_), - refCount (1) + : owner (owner_) { } - virtual ~JuceDropTarget() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDropTarget) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + ~JuceDropTarget() {} HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { @@ -215073,7 +214989,6 @@ private: private: Win32ComponentPeer* const owner; - int refCount; StringArray files; void updateFileList (IDataObject* const pDataObject) @@ -215857,15 +215772,13 @@ static Image* createImageFromHICON (HICON icon) throw() if (GetIconInfo (icon, &info)) { - Image* const mask = createImageFromHBITMAP (info.hbmMask); - + ScopedPointer mask (createImageFromHBITMAP (info.hbmMask)); if (mask == 0) return 0; - Image* const image = createImageFromHBITMAP (info.hbmColor); - + ScopedPointer image (createImageFromHBITMAP (info.hbmColor)); if (image == 0) - return mask; + return mask.release(); for (int y = image->getHeight(); --y >= 0;) { @@ -215878,8 +215791,7 @@ static Image* createImageFromHICON (HICON icon) throw() } } - delete mask; - return image; + return image.release(); } return 0; @@ -216115,36 +216027,11 @@ void MouseCursor::showInAllWindows() const showInWindow (0); } -class JuceDropSource : public IDropSource +class JuceDropSource : public ComBaseClassHelper { - int refCount; - public: - JuceDropSource() - : refCount (1) - { - } - - virtual ~JuceDropSource() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDropSource) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + JuceDropSource() {} + ~JuceDropSource() {} HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys) { @@ -216163,36 +216050,16 @@ public: } }; -class JuceEnumFormatEtc : public IEnumFORMATETC +class JuceEnumFormatEtc : public ComBaseClassHelper { public: JuceEnumFormatEtc (const FORMATETC* const format_) - : refCount (1), - format (format_), + : format (format_), index (0) { } - virtual ~JuceEnumFormatEtc() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IEnumFORMATETC) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + ~JuceEnumFormatEtc() {} HRESULT __stdcall Clone (IEnumFORMATETC** result) { @@ -216243,7 +216110,6 @@ public: } private: - int refCount; const FORMATETC* const format; int index; @@ -216262,12 +216128,11 @@ private: JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&); }; -class JuceDataObject : public IDataObject +class JuceDataObject : public ComBaseClassHelper { JuceDropSource* const dropSource; const FORMATETC* const format; const STGMEDIUM* const medium; - int refCount; JuceDataObject (const JuceDataObject&); JuceDataObject& operator= (const JuceDataObject&); @@ -216278,8 +216143,7 @@ public: const STGMEDIUM* const medium_) : dropSource (dropSource_), format (format_), - medium (medium_), - refCount (1) + medium (medium_) { } @@ -216288,22 +216152,6 @@ public: jassert (refCount == 0); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDataObject) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium) { if ((pFormatEtc->tymed & format->tymed) != 0 @@ -217197,33 +217045,12 @@ const String SystemClipboard::getTextFromClipboard() namespace ActiveXHelpers { - class JuceIStorage : public IStorage + + class JuceIStorage : public ComBaseClassHelper { - int refCount; - public: - JuceIStorage() : refCount (1) {} - - virtual ~JuceIStorage() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IStorage) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + JuceIStorage() {} + ~JuceIStorage() {} HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; } HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; } @@ -217244,38 +217071,13 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - class JuceOleInPlaceFrame : public IOleInPlaceFrame + class JuceOleInPlaceFrame : public ComBaseClassHelper { - int refCount; HWND window; public: - JuceOleInPlaceFrame (HWND window_) - : refCount (1), - window (window_) - { - } - - virtual ~JuceOleInPlaceFrame() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IOleInPlaceFrame) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + JuceOleInPlaceFrame (HWND window_) : window (window_) {} + ~JuceOleInPlaceFrame() {} HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; } HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; } @@ -217293,42 +217095,22 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - class JuceIOleInPlaceSite : public IOleInPlaceSite + class JuceIOleInPlaceSite : public ComBaseClassHelper { - int refCount; HWND window; JuceOleInPlaceFrame* frame; public: JuceIOleInPlaceSite (HWND window_) - : refCount (1), - window (window_) - { - frame = new JuceOleInPlaceFrame (window); - } + : window (window_), + frame (new JuceOleInPlaceFrame (window)) + {} - virtual ~JuceIOleInPlaceSite() + ~JuceIOleInPlaceSite() { - jassert (refCount == 0); frame->Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IOleInPlaceSite) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; } HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; } HRESULT __stdcall CanInPlaceActivate() { return S_OK; } @@ -217356,46 +217138,32 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - class JuceIOleClientSite : public IOleClientSite + class JuceIOleClientSite : public ComBaseClassHelper { - int refCount; JuceIOleInPlaceSite* inplaceSite; public: JuceIOleClientSite (HWND window) - : refCount (1) - { - inplaceSite = new JuceIOleInPlaceSite (window); - } + : inplaceSite (new JuceIOleInPlaceSite (window)) + {} - virtual ~JuceIOleClientSite() + ~JuceIOleClientSite() { - jassert (refCount == 0); inplaceSite->Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) + HRESULT __stdcall QueryInterface (REFIID type, void __RPC_FAR* __RPC_FAR* result) { - if (id == IID_IUnknown || id == IID_IOleClientSite) - { - AddRef(); - *result = this; - return S_OK; - } - else if (id == IID_IOleInPlaceSite) + if (type == IID_IOleInPlaceSite) { inplaceSite->AddRef(); - *result = inplaceSite; + *result = static_cast (inplaceSite); return S_OK; } - *result = 0; - return E_NOINTERFACE; + return ComBaseClassHelper ::QueryInterface (type, result); } - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall SaveObject() { return E_NOTIMPL; } HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; } HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; } @@ -218179,6 +217947,7 @@ public: EventHandler* handler = new EventHandler (owner); connectionPoint->Advise (handler, &adviseCookie); + handler->Release(); } } } @@ -218250,14 +218019,13 @@ private: IConnectionPoint* connectionPoint; DWORD adviseCookie; - class EventHandler : public IDispatch, + class EventHandler : public ComBaseClassHelper , public ComponentMovementWatcher { public: EventHandler (WebBrowserComponent* owner_) : ComponentMovementWatcher (owner_), - owner (owner_), - refCount (0) + owner (owner_) { } @@ -218265,22 +218033,6 @@ private: { } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; } HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; } HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; } @@ -218329,7 +218081,6 @@ private: private: WebBrowserComponent* const owner; - int refCount; EventHandler (const EventHandler&); EventHandler& operator= (const EventHandler&); @@ -221044,13 +220795,13 @@ static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMa return result; } -class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents, +class AudioCDBurner::Pimpl : public ComBaseClassHelper , public Timer { public: Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_) : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0), - listener (0), progress (0), shouldCancel (false), refCount (1) + listener (0), progress (0), shouldCancel (false) { HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook); jassert (SUCCEEDED (hr)); @@ -221073,25 +220824,6 @@ public: Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (result == 0) - return E_POINTER; - - if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall QueryCancel (boolean* pbCancel) { if (listener != 0 && ! shouldCancel) @@ -221203,9 +220935,6 @@ public: AudioCDBurner::BurnProgressListener* listener; float progress; bool shouldCancel; - -private: - int refCount; }; AudioCDBurner::AudioCDBurner (const int deviceIndex) @@ -227193,7 +226922,7 @@ private: CoTaskMemFree (pmt); } - class GrabberCallback : public ISampleGrabberCB + class GrabberCallback : public ComBaseClassHelper { public: GrabberCallback (DShowCameraDeviceInteral& owner_) @@ -227201,25 +226930,6 @@ private: { } - HRESULT __stdcall QueryInterface (REFIID id, void** result) - { - if (id == IID_IUnknown) - *result = dynamic_cast (this); - else if (id == IID_ISampleGrabberCB) - *result = dynamic_cast (this); - else - { - *result = 0; - return E_NOINTERFACE; - } - - AddRef(); - return S_OK; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/) { return E_FAIL; @@ -227232,7 +226942,6 @@ private: } private: - int refCount; DShowCameraDeviceInteral& owner; GrabberCallback (const GrabberCallback&); @@ -227256,13 +226965,13 @@ CameraDevice::CameraDevice (const String& name_, int /*index*/) CameraDevice::~CameraDevice() { stopRecording(); - delete (DShowCameraDeviceInteral*) internal; + delete static_cast (internal); internal = 0; } Component* CameraDevice::createViewerComponent() { - return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal); + return new DShowCameraDeviceInteral::DShowCaptureViewerComp (static_cast (internal)); } const String CameraDevice::getFileExtension() @@ -227400,16 +227109,15 @@ CameraDevice* CameraDevice::openDevice (int index, if (filter != 0) { - CameraDevice* const cam = new CameraDevice (name, index); + ScopedPointer cam (new CameraDevice (name, index)); + DShowCameraDeviceInteral* const intern = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter, minWidth, minHeight, maxWidth, maxHeight); cam->internal = intern; if (intern->ok) - return cam; - else - delete cam; + return cam.release(); } } @@ -227692,27 +227400,58 @@ int64 File::getSize() const return juce_stat (fullPath, info) ? info.st_size : 0; } -bool juce_canWriteToFile (const String& fileName) +bool File::hasWriteAccess() const { - return access (fileName.toUTF8(), W_OK) == 0; + if (exists()) + return access (fullPath.toUTF8(), W_OK) == 0; + + if ((! isDirectory()) && fullPath.containsChar (separator)) + return getParentDirectory().hasWriteAccess(); + + return false; } -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly) +bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const { struct stat info; - const int res = stat (fileName.toUTF8(), &info); + const int res = stat (fullPath.toUTF8(), &info); if (res != 0) return false; info.st_mode &= 0777; // Just permissions - if (isReadOnly) + if (shouldBeReadOnly) info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); else // Give everybody write permission? info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; - return chmod (fileName.toUTF8(), info.st_mode) == 0; + return chmod (fullPath.toUTF8(), info.st_mode) == 0; +} + +void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const +{ + modificationTime = 0; + accessTime = 0; + creationTime = 0; + + struct stat info; + const int res = stat (fullPath.toUTF8(), &info); + if (res == 0) + { + modificationTime = (int64) info.st_mtime * 1000; + accessTime = (int64) info.st_atime * 1000; + creationTime = (int64) info.st_ctime * 1000; + } +} + +bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const +{ + struct utimbuf times; + times.actime = (time_t) (accessTime / 1000); + times.modtime = (time_t) (modificationTime / 1000); + + return utime (fullPath.toUTF8(), ×) == 0; } bool File::deleteFile() const @@ -227725,20 +227464,17 @@ bool File::deleteFile() const return remove (fullPath.toUTF8()) == 0; } -bool juce_copyFile (const String& s, const String& d); - -bool juce_moveFile (const String& source, const String& dest) +bool File::moveInternal (const File& dest) const { - if (rename (source.toUTF8(), dest.toUTF8()) == 0) + if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0) return true; - if (juce_canWriteToFile (source) - && juce_copyFile (source, dest)) + if (hasWriteAccess() && copyInternal (dest)) { - if (File (source).deleteFile()) + if (deleteFile()) return true; - File (dest).deleteFile(); + dest.deleteFile(); } return false; @@ -228036,66 +227772,26 @@ static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) +bool File::copyInternal (const File& dest) const { - modificationTime = 0; - accessTime = 0; - creationTime = 0; + FileInputStream in (*this); - struct stat info; - const int res = stat (fileName.toUTF8(), &info); - if (res == 0) + if (dest.deleteFile()) { - modificationTime = (int64) info.st_mtime * 1000; - accessTime = (int64) info.st_atime * 1000; - creationTime = (int64) info.st_ctime * 1000; - } -} - -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) -{ - struct utimbuf times; - times.actime = (time_t) (accessTime / 1000); - times.modtime = (time_t) (modificationTime / 1000); - - return utime (fileName.toUTF8(), ×) == 0; -} - -bool juce_copyFile (const String& s, const String& d) -{ - const File source (s), dest (d); - - FileInputStream* in = source.createInputStream(); - bool ok = false; - - if (in != 0) - { - if (dest.deleteFile()) { - FileOutputStream* const out = dest.createOutputStream(); + FileOutputStream out (dest); - if (out != 0) - { - const int bytesCopied = out->writeFromInputStream (*in, -1); - delete out; + if (out.failedToOpen()) + return false; - ok = (bytesCopied == source.getSize()); - - if (! ok) - dest.deleteFile(); - } + if (out.writeFromInputStream (in, -1) == getSize()) + return true; } - delete in; + dest.deleteFile(); } - return ok; + return false; } void File::findFileSystemRoots (Array& destArray) @@ -228107,11 +227803,8 @@ bool File::isOnCDRomDrive() const { struct statfs buf; - if (statfs (getFullPathName().toUTF8(), &buf) == 0) - return (buf.f_type == U_ISOFS_SUPER_MAGIC); - - // Assume not if this fails for some reason - return false; + return statfs (getFullPathName().toUTF8(), &buf) == 0 + && buf.f_type == U_ISOFS_SUPER_MAGIC; } bool File::isOnHardDisk() const @@ -228289,30 +227982,24 @@ public: if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0) { filenameFound = String::fromUTF8 (de->d_name); - const String path (parentDir + filenameFound); - if (isDir != 0 || fileSize != 0) + if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) { struct stat info; - const bool statOk = (stat (path.toUTF8(), &info) == 0); + const bool statOk = juce_stat (path, info); - if (isDir != 0) *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0)); - if (isHidden != 0) *isHidden = (de->d_name[0] == '.'); - if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0; + if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0; } - if (modTime != 0 || creationTime != 0) - { - int64 m, a, c; - juce_getFileTimes (path, m, a, c); - - if (modTime != 0) *modTime = m; - if (creationTime != 0) *creationTime = c; - } + if (isHidden != 0) + *isHidden = filenameFound.startsWithChar ('.'); if (isReadOnly != 0) - *isReadOnly = ! juce_canWriteToFile (path); + *isReadOnly = access (path.toUTF8(), W_OK) != 0; return true; } @@ -228344,8 +228031,7 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly); } -bool juce_launchFile (const String& fileName, - const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { String cmdString (fileName.replace (" ", "\\ ",false)); cmdString << " " << parameters; @@ -228960,11 +228646,6 @@ private: } }; -bool juce_isOnLine() -{ - return true; -} - void* juce_openInternetFile (const String& url, const String& headers, const MemoryBlock& postData, @@ -228985,10 +228666,7 @@ void* juce_openInternetFile (const String& url, void juce_closeInternetFile (void* handle) { - JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle; - - if (s != 0) - delete s; + delete static_cast (handle); } int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead) @@ -230226,7 +229904,7 @@ public: if (fontDirs.size() == 0) { XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf")); - XmlElement* const fontsInfo = fontsConfig.getDocumentElement(); + const ScopedPointer fontsInfo (fontsConfig.getDocumentElement()); if (fontsInfo != 0) { @@ -230234,8 +229912,6 @@ public: { fontDirs.add (e->getAllSubText().trim()); } - - delete fontsInfo; } } @@ -234780,14 +234456,12 @@ public: outputId (outputId_), isOpen_ (false), isStarted (false), - internal (0) + internal (new ALSAThread (inputId_, outputId_)) { - internal = new ALSAThread (inputId, outputId); } ~ALSAAudioIODevice() { - delete internal; } const StringArray getOutputChannelNames() @@ -234945,7 +234619,7 @@ public: private: bool isOpen_, isStarted; - ALSAThread* internal; + ScopedPointer internal; }; class ALSAAudioIODeviceType : public AudioIODeviceType @@ -237106,11 +236780,6 @@ public: @end BEGIN_JUCE_NAMESPACE -bool juce_isOnLine() -{ - return true; -} - void* juce_openInternetFile (const String& url, const String& headers, const MemoryBlock& postData, @@ -237709,27 +237378,58 @@ int64 File::getSize() const return juce_stat (fullPath, info) ? info.st_size : 0; } -bool juce_canWriteToFile (const String& fileName) +bool File::hasWriteAccess() const { - return access (fileName.toUTF8(), W_OK) == 0; + if (exists()) + return access (fullPath.toUTF8(), W_OK) == 0; + + if ((! isDirectory()) && fullPath.containsChar (separator)) + return getParentDirectory().hasWriteAccess(); + + return false; } -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly) +bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const { struct stat info; - const int res = stat (fileName.toUTF8(), &info); + const int res = stat (fullPath.toUTF8(), &info); if (res != 0) return false; info.st_mode &= 0777; // Just permissions - if (isReadOnly) + if (shouldBeReadOnly) info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); else // Give everybody write permission? info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; - return chmod (fileName.toUTF8(), info.st_mode) == 0; + return chmod (fullPath.toUTF8(), info.st_mode) == 0; +} + +void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const +{ + modificationTime = 0; + accessTime = 0; + creationTime = 0; + + struct stat info; + const int res = stat (fullPath.toUTF8(), &info); + if (res == 0) + { + modificationTime = (int64) info.st_mtime * 1000; + accessTime = (int64) info.st_atime * 1000; + creationTime = (int64) info.st_ctime * 1000; + } +} + +bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const +{ + struct utimbuf times; + times.actime = (time_t) (accessTime / 1000); + times.modtime = (time_t) (modificationTime / 1000); + + return utime (fullPath.toUTF8(), ×) == 0; } bool File::deleteFile() const @@ -237742,20 +237442,17 @@ bool File::deleteFile() const return remove (fullPath.toUTF8()) == 0; } -bool juce_copyFile (const String& s, const String& d); - -bool juce_moveFile (const String& source, const String& dest) +bool File::moveInternal (const File& dest) const { - if (rename (source.toUTF8(), dest.toUTF8()) == 0) + if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0) return true; - if (juce_canWriteToFile (source) - && juce_copyFile (source, dest)) + if (hasWriteAccess() && copyInternal (dest)) { - if (File (source).deleteFile()) + if (deleteFile()) return true; - File (dest).deleteFile(); + dest.deleteFile(); } return false; @@ -238048,50 +237745,19 @@ void InterProcessLock::exit() // compiled on its own). #if JUCE_INCLUDED_FILE -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) -{ - modificationTime = 0; - accessTime = 0; - creationTime = 0; - - struct stat info; - const int res = stat (fileName.toUTF8(), &info); - if (res == 0) - { - modificationTime = (int64) info.st_mtime * 1000; - accessTime = (int64) info.st_atime * 1000; - creationTime = (int64) info.st_ctime * 1000; - } -} - -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) -{ - struct utimbuf times; - times.actime = (time_t) (accessTime / 1000); - times.modtime = (time_t) (modificationTime / 1000); - - return utime (fileName.toUTF8(), ×) == 0; -} - -bool juce_copyFile (const String& src, const String& dst) +bool File::copyInternal (const File& dest) const { const ScopedAutoReleasePool pool; NSFileManager* fm = [NSFileManager defaultManager]; - return [fm fileExistsAtPath: juceStringToNS (src)] + return [fm fileExistsAtPath: juceStringToNS (fullPath)] #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - && [fm copyItemAtPath: juceStringToNS (src) - toPath: juceStringToNS (dst) + && [fm copyItemAtPath: juceStringToNS (fullPath) + toPath: juceStringToNS (dest.getFullPathName()) error: nil]; #else - && [fm copyPath: juceStringToNS (src) - toPath: juceStringToNS (dst) + && [fm copyPath: juceStringToNS (fullPath) + toPath: juceStringToNS (dest.getFullPathName()) handler: nil]; #endif } @@ -238353,27 +238019,22 @@ public: const String path (parentDir + filenameFound); - if (isDir != 0 || fileSize != 0) + if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) { struct stat info; const bool statOk = juce_stat (path, info); if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (isHidden != 0) *isHidden = juce_isHiddenFile (path); - if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0; + if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0; } - if (modTime != 0 || creationTime != 0) - { - int64 m, a, c; - juce_getFileTimes (path, m, a, c); - - if (modTime != 0) *modTime = m; - if (creationTime != 0) *creationTime = c; - } + if (isHidden != 0) + *isHidden = juce_isHiddenFile (path); if (isReadOnly != 0) - *isReadOnly = ! juce_canWriteToFile (path); + *isReadOnly = access (path.toUTF8(), W_OK) != 0; return true; } @@ -238425,7 +238086,7 @@ bool juce_launchExecutable (const String& pathAndArguments) return true; } -bool juce_launchFile (const String& fileName, const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { #if JUCE_IPHONE return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]]; @@ -239660,7 +239321,15 @@ public: { if (! transform.isSingularity()) { - Image* singleChannelImage = createAlphaChannelImage (sourceImage); + ScopedPointer imageToDelete; + const Image* singleChannelImage = &sourceImage; + + if (sourceImage.getFormat() != Image::SingleChannel) + { + imageToDelete = sourceImage.createCopyOfAlphaChannel(); + singleChannelImage = imageToDelete; + } + CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace); flip(); @@ -239674,7 +239343,6 @@ public: flip(); CGImageRelease (image); - deleteAlphaChannelImage (sourceImage, singleChannelImage); } } @@ -240143,20 +239811,6 @@ private: } } - static Image* createAlphaChannelImage (const Image& im) - { - if (im.getFormat() == Image::SingleChannel) - return const_cast (&im); - - return im.createCopyOfAlphaChannel(); - } - - static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm) - { - if (im.getFormat() != Image::SingleChannel) - delete alphaIm; - } - void flip() const { CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight)); @@ -244352,7 +244006,15 @@ public: { if (! transform.isSingularity()) { - Image* singleChannelImage = createAlphaChannelImage (sourceImage); + ScopedPointer imageToDelete; + const Image* singleChannelImage = &sourceImage; + + if (sourceImage.getFormat() != Image::SingleChannel) + { + imageToDelete = sourceImage.createCopyOfAlphaChannel(); + singleChannelImage = imageToDelete; + } + CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace); flip(); @@ -244366,7 +244028,6 @@ public: flip(); CGImageRelease (image); - deleteAlphaChannelImage (sourceImage, singleChannelImage); } } @@ -244835,20 +244496,6 @@ private: } } - static Image* createAlphaChannelImage (const Image& im) - { - if (im.getFormat() == Image::SingleChannel) - return const_cast (&im); - - return im.createCopyOfAlphaChannel(); - } - - static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm) - { - if (im.getFormat() != Image::SingleChannel) - delete alphaIm; - } - void flip() const { CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight)); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index da42eb2cce..8fddfdb549 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -2860,6 +2860,8 @@ protected: #endif // __JUCE_INPUTSTREAM_JUCEHEADER__ /*** End of inlined file: juce_InputStream.h ***/ +class File; + class JUCE_API OutputStream { protected: @@ -2910,7 +2912,7 @@ public: bool asUnicode, bool writeUnicodeHeaderBytes); - virtual int writeFromInputStream (InputStream& source, int maxNumBytesToWrite); + virtual int writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite); juce_UseDebuggingNewOperator }; @@ -2923,6 +2925,10 @@ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, char character); OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* text); +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data); + +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead); + #endif // __JUCE_OUTPUTSTREAM_JUCEHEADER__ /*** End of inlined file: juce_OutputStream.h ***/ @@ -4544,8 +4550,15 @@ private: const String getPathUpToLastSlash() const; void createDirectoryInternal (const String& fileName) const; + bool copyInternal (const File& dest) const; + bool moveInternal (const File& dest) const; + bool setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const; + void getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const; + bool setFileReadOnlyInternal (bool shouldBeReadOnly) const; + static const String parseAbsolutePath (const String& path); static bool fileTypeMatches (int whatToLookFor, bool isDir, bool isHidden); + }; #endif // __JUCE_FILE_JUCEHEADER__ @@ -7049,6 +7062,8 @@ public: static void beep(); + static bool openDocument (const String& documentURL, const String& parameters); + static bool launchEmailWithAttachments (const String& targetEmailAddress, const String& emailSubject, const String& bodyText, @@ -14276,7 +14291,7 @@ public: juce_UseDebuggingNewOperator private: - VoidArray knownFormats; + OwnedArray knownFormats; int defaultFormatIndex; }; diff --git a/src/audio/audio_file_formats/juce_AudioFormatManager.cpp b/src/audio/audio_file_formats/juce_AudioFormatManager.cpp index 42f30293fd..f346a5d4a6 100644 --- a/src/audio/audio_file_formats/juce_AudioFormatManager.cpp +++ b/src/audio/audio_file_formats/juce_AudioFormatManager.cpp @@ -70,7 +70,7 @@ void AudioFormatManager::registerFormat (AudioFormat* newFormat, #endif if (makeThisTheDefaultFormat) - defaultFormatIndex = knownFormats.size(); + defaultFormatIndex = getNumKnownFormats(); knownFormats.add (newFormat); } @@ -97,9 +97,6 @@ void AudioFormatManager::registerBasicFormats() void AudioFormatManager::clearFormats() { - for (int i = getNumKnownFormats(); --i >= 0;) - delete getKnownFormat(i); - knownFormats.clear(); defaultFormatIndex = 0; } @@ -111,7 +108,7 @@ int AudioFormatManager::getNumKnownFormats() const AudioFormat* AudioFormatManager::getKnownFormat (const int index) const { - return (AudioFormat*) knownFormats [index]; + return knownFormats [index]; } AudioFormat* AudioFormatManager::getDefaultFormat() const @@ -165,7 +162,7 @@ AudioFormatReader* AudioFormatManager::createReaderFor (const File& file) { // you need to actually register some formats before the manager can // use them to open a file! - jassert (knownFormats.size() > 0); + jassert (getNumKnownFormats() > 0); for (int i = 0; i < getNumKnownFormats(); ++i) { @@ -192,7 +189,7 @@ AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileSt { // you need to actually register some formats before the manager can // use them to open a file! - jassert (knownFormats.size() > 0); + jassert (getNumKnownFormats() > 0); ScopedPointer in (audioFileStream); diff --git a/src/audio/audio_file_formats/juce_AudioFormatManager.h b/src/audio/audio_file_formats/juce_AudioFormatManager.h index 93078e9557..0091824705 100644 --- a/src/audio/audio_file_formats/juce_AudioFormatManager.h +++ b/src/audio/audio_file_formats/juce_AudioFormatManager.h @@ -28,7 +28,7 @@ #include "juce_AudioFormat.h" #include "../../core/juce_Singleton.h" -#include "../../containers/juce_VoidArray.h" +#include "../../containers/juce_OwnedArray.h" //============================================================================== @@ -137,7 +137,7 @@ public: juce_UseDebuggingNewOperator private: - VoidArray knownFormats; + OwnedArray knownFormats; int defaultFormatIndex; }; diff --git a/src/core/juce_PlatformUtilities.h b/src/core/juce_PlatformUtilities.h index 6c9bc249f2..f50a977d40 100644 --- a/src/core/juce_PlatformUtilities.h +++ b/src/core/juce_PlatformUtilities.h @@ -42,6 +42,11 @@ public: /** Plays the operating system's default alert 'beep' sound. */ static void beep(); + /** Tries to launch the system's default reader for a given file or URL. */ + static bool openDocument (const String& documentURL, const String& parameters); + + /** Tries to launch the system's default email app to let the user create an email. + */ static bool launchEmailWithAttachments (const String& targetEmailAddress, const String& emailSubject, const String& bodyText, diff --git a/src/gui/components/controls/juce_TreeView.cpp b/src/gui/components/controls/juce_TreeView.cpp index acd8217873..ad2351bda1 100644 --- a/src/gui/components/controls/juce_TreeView.cpp +++ b/src/gui/components/controls/juce_TreeView.cpp @@ -229,7 +229,6 @@ public: for (int i = rowComponentItems.size(); --i >= 0;) { Component* const comp = rowComponents.getUnchecked(i); - bool keep = false; if (isParentOf (comp)) diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 46b27beb73..1596bf28a0 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -37,22 +37,10 @@ BEGIN_JUCE_NAMESPACE #include "juce_TemporaryFile.h" #include "../../core/juce_SystemStats.h" #include "../../core/juce_Random.h" +#include "../../core/juce_PlatformUtilities.h" #include "../../containers/juce_ScopedPointer.h" -//============================================================================== -bool juce_canWriteToFile (const String& fileName); -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly); -void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime); -bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime); -bool juce_copyFile (const String& source, const String& dest); -bool juce_moveFile (const String& source, const String& dest); -bool juce_launchFile (const String& fileName, const String& parameters); - - -//============================================================================== -const File File::nonexistent; - //============================================================================== File::File (const String& fullPathName) : fullPath (parseAbsolutePath (fullPathName)) @@ -86,6 +74,9 @@ File& File::operator= (const File& other) return *this; } +const File File::nonexistent; + + //============================================================================== const String File::parseAbsolutePath (const String& p) { @@ -218,24 +209,6 @@ bool File::operator> (const File& other) const } //============================================================================== -bool File::hasWriteAccess() const -{ - if (exists()) - return juce_canWriteToFile (fullPath); - -#if ! JUCE_WINDOWS - else if ((! isDirectory()) && fullPath.containsChar (separator)) - return getParentDirectory().hasWriteAccess(); - else - return false; -#else - // 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.. - else - return true; -#endif -} - bool File::setReadOnly (const bool shouldBeReadOnly, const bool applyRecursively) const { @@ -250,7 +223,7 @@ bool File::setReadOnly (const bool shouldBeReadOnly, worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked; } - return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked; + return setFileReadOnlyInternal (shouldBeReadOnly) && worked; } bool File::deleteRecursively() const @@ -280,18 +253,13 @@ bool File::moveFileTo (const File& newFile) const if (! newFile.deleteFile()) return false; - return juce_moveFile (fullPath, newFile.fullPath); + return moveInternal (newFile); } bool File::copyFileTo (const File& newFile) const { - if (*this == newFile) - return true; - - if (! newFile.deleteFile()) - return false; - - return juce_copyFile (fullPath, newFile.fullPath); + return (*this == newFile) + || (exists() && newFile.deleteFile() && copyInternal (newFile)); } bool File::copyDirectoryTo (const File& newDirectory) const @@ -519,38 +487,27 @@ bool File::createDirectory() const const Time File::getCreationTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (c); } -bool File::setCreationTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds()); -} - const Time File::getLastModificationTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (m); } -bool File::setLastModificationTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0); -} - const Time File::getLastAccessTime() const { int64 m, a, c; - juce_getFileTimes (fullPath, m, a, c); + getFileTimesInternal (m, a, c); return Time (a); } -bool File::setLastAccessTime (const Time& t) const -{ - return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0); -} +bool File::setLastModificationTime (const Time& t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); } +bool File::setLastAccessTime (const Time& t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); } +bool File::setCreationTime (const Time& t) const { return setFileTimesInternal (0, 0, t.toMilliseconds()); } //============================================================================== bool File::loadFileAsData (MemoryBlock& destBlock) const @@ -793,7 +750,7 @@ const File File::withFileExtension (const String& newExtension) const //============================================================================== bool File::startAsProcess (const String& parameters) const { - return exists() && juce_launchFile (fullPath, parameters); + return exists() && PlatformUtilities::openDocument (fullPath, parameters); } //============================================================================== diff --git a/src/io/files/juce_File.h b/src/io/files/juce_File.h index 4b55bf9822..ed8f3fcb3e 100644 --- a/src/io/files/juce_File.h +++ b/src/io/files/juce_File.h @@ -924,8 +924,15 @@ private: const String getPathUpToLastSlash() const; void createDirectoryInternal (const String& fileName) const; + bool copyInternal (const File& dest) const; + bool moveInternal (const File& dest) const; + bool setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const; + void getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const; + bool setFileReadOnlyInternal (bool shouldBeReadOnly) const; + static const String parseAbsolutePath (const String& path); static bool fileTypeMatches (int whatToLookFor, bool isDir, bool isHidden); + }; #endif // __JUCE_FILE_JUCEHEADER__ diff --git a/src/io/network/juce_URL.cpp b/src/io/network/juce_URL.cpp index 4bfb1d5fef..406b26bc7a 100644 --- a/src/io/network/juce_URL.cpp +++ b/src/io/network/juce_URL.cpp @@ -30,7 +30,9 @@ BEGIN_JUCE_NAMESPACE #include "juce_URL.h" #include "../../core/juce_Random.h" +#include "../../core/juce_PlatformUtilities.h" #include "../../text/juce_XmlDocument.h" +#include "../../io/streams/juce_MemoryOutputStream.h" //============================================================================== @@ -282,21 +284,11 @@ public: juce_closeInternetFile (handle); } - bool isError() const - { - return handle == 0; - } - //============================================================================== - int64 getTotalLength() - { - return juce_getInternetFileContentLength (handle); - } - - bool isExhausted() - { - return finished; - } + bool isError() const { return handle == 0; } + int64 getTotalLength() { return juce_getInternetFileContentLength (handle); } + bool isExhausted() { return finished; } + int64 getPosition() { return position; } int read (void* dest, int bytes) { @@ -316,11 +308,6 @@ public: } } - int64 getPosition() - { - return position; - } - bool setPosition (int64 wantedPos) { if (wantedPos != position) @@ -370,64 +357,52 @@ private: void createHeadersAndPostData (const URL& url) { + MemoryOutputStream data (256, 256, &postData); + if (url.getFilesToUpload().size() > 0) { // need to upload some files, so do it as multi-part... - String boundary (String::toHexString (Random::getSystemRandom().nextInt64())); + const String boundary (String::toHexString (Random::getSystemRandom().nextInt64())); headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n"; - appendUTF8ToPostData ("--" + boundary); + data << "--" << boundary; int i; for (i = 0; i < url.getParameters().size(); ++i) { - String s; - s << "\r\nContent-Disposition: form-data; name=\"" - << url.getParameters().getAllKeys() [i] - << "\"\r\n\r\n" - << url.getParameters().getAllValues() [i] - << "\r\n--" - << boundary; - - appendUTF8ToPostData (s); + data << "\r\nContent-Disposition: form-data; name=\"" + << url.getParameters().getAllKeys() [i] + << "\"\r\n\r\n" + << url.getParameters().getAllValues() [i] + << "\r\n--" + << boundary; } for (i = 0; i < url.getFilesToUpload().size(); ++i) { - const File f (url.getFilesToUpload().getAllValues() [i]); + const File file (url.getFilesToUpload().getAllValues() [i]); const String paramName (url.getFilesToUpload().getAllKeys() [i]); - String s; - s << "\r\nContent-Disposition: form-data; name=\"" - << paramName - << "\"; filename=\"" - << f.getFileName() - << "\"\r\n"; + data << "\r\nContent-Disposition: form-data; name=\"" << paramName + << "\"; filename=\"" << file.getFileName() << "\"\r\n"; const String mimeType (url.getMimeTypesOfUploadFiles() .getValue (paramName, String::empty)); if (mimeType.isNotEmpty()) - s << "Content-Type: " << mimeType << "\r\n"; + data << "Content-Type: " << mimeType << "\r\n"; - s << "Content-Transfer-Encoding: binary\r\n\r\n"; - - appendUTF8ToPostData (s); - - f.loadFileAsData (postData); - - s = "\r\n--" + boundary; - - appendUTF8ToPostData (s); + data << "Content-Transfer-Encoding: binary\r\n\r\n" + << file << "\r\n--" << boundary; } - appendUTF8ToPostData ("--\r\n"); + data << "--\r\n"; } else { - appendUTF8ToPostData (getMangledParameters (url.getParameters())); - appendUTF8ToPostData (url.getPostData()); + data << getMangledParameters (url.getParameters()) + << url.getPostData(); // just a short text attachment, so use simple url encoding.. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: " @@ -436,12 +411,6 @@ private: } } - void appendUTF8ToPostData (const String& text) - { - postData.append (text.toUTF8(), - (int) strlen (text.toUTF8())); - } - WebInputStream (const WebInputStream&); WebInputStream& operator= (const WebInputStream&); }; @@ -583,8 +552,6 @@ const String URL::addEscapeChars (const String& s, const bool isParameter) } //============================================================================== -extern bool juce_launchFile (const String& fileName, const String& parameters); - bool URL::launchInDefaultBrowser() const { String u (toString (true)); @@ -592,7 +559,7 @@ bool URL::launchInDefaultBrowser() const if (u.containsChar ('@') && ! u.containsChar (':')) u = "mailto:" + u; - return juce_launchFile (u, String::empty); + return PlatformUtilities::openDocument (u, String::empty); } END_JUCE_NAMESPACE diff --git a/src/io/streams/juce_OutputStream.cpp b/src/io/streams/juce_OutputStream.cpp index 7b137e603f..9232ddb747 100644 --- a/src/io/streams/juce_OutputStream.cpp +++ b/src/io/streams/juce_OutputStream.cpp @@ -31,6 +31,8 @@ BEGIN_JUCE_NAMESPACE #include "juce_OutputStream.h" #include "../../threads/juce_ScopedLock.h" #include "../../containers/juce_VoidArray.h" +#include "../../containers/juce_ScopedPointer.h" +#include "../files/juce_FileInputStream.h" //============================================================================== @@ -228,20 +230,19 @@ void OutputStream::writeText (const String& text, const bool asUnicode, } } -int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite) +int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWrite) { if (numBytesToWrite < 0) - numBytesToWrite = 0x7fffffff; + numBytesToWrite = std::numeric_limits::max(); int numWritten = 0; while (numBytesToWrite > 0 && ! source.isExhausted()) { char buffer [8192]; + const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer))); - const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer))); - - if (num == 0) + if (num <= 0) break; write (buffer, num); @@ -276,5 +277,21 @@ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const return stream; } +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data) +{ + stream.write (data.getData(), (int) data.getSize()); + return stream; +} + +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead) +{ + const ScopedPointer in (fileToRead.createInputStream()); + + if (in != 0) + stream.writeFromInputStream (*in, -1); + + return stream; +} + END_JUCE_NAMESPACE diff --git a/src/io/streams/juce_OutputStream.h b/src/io/streams/juce_OutputStream.h index 4ee4f759ee..5436954ab8 100644 --- a/src/io/streams/juce_OutputStream.h +++ b/src/io/streams/juce_OutputStream.h @@ -28,7 +28,7 @@ #include "../../text/juce_String.h" #include "juce_InputStream.h" - +class File; //============================================================================== /** @@ -199,7 +199,7 @@ public: less than zero, it will keep reading until the input is exhausted) */ - virtual int writeFromInputStream (InputStream& source, int maxNumBytesToWrite); + virtual int writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite); //============================================================================== juce_UseDebuggingNewOperator @@ -218,6 +218,11 @@ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, char character); /** Writes a null-terminated text string to a stream. */ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* text); +/** Writes a block of data from a MemoryBlock to a stream. */ +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data); + +/** Writes the contents of a file to a stream. */ +OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead); #endif // __JUCE_OUTPUTSTREAM_JUCEHEADER__ diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index a641439309..9427c60b7d 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -247,27 +247,58 @@ int64 File::getSize() const } //============================================================================== -bool juce_canWriteToFile (const String& fileName) +bool File::hasWriteAccess() const { - return access (fileName.toUTF8(), W_OK) == 0; + if (exists()) + return access (fullPath.toUTF8(), W_OK) == 0; + + if ((! isDirectory()) && fullPath.containsChar (separator)) + return getParentDirectory().hasWriteAccess(); + + return false; } -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly) +bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const { struct stat info; - const int res = stat (fileName.toUTF8(), &info); + const int res = stat (fullPath.toUTF8(), &info); if (res != 0) return false; info.st_mode &= 0777; // Just permissions - if (isReadOnly) + if (shouldBeReadOnly) info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); else // Give everybody write permission? info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; - return chmod (fileName.toUTF8(), info.st_mode) == 0; + return chmod (fullPath.toUTF8(), info.st_mode) == 0; +} + +void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const +{ + modificationTime = 0; + accessTime = 0; + creationTime = 0; + + struct stat info; + const int res = stat (fullPath.toUTF8(), &info); + if (res == 0) + { + modificationTime = (int64) info.st_mtime * 1000; + accessTime = (int64) info.st_atime * 1000; + creationTime = (int64) info.st_ctime * 1000; + } +} + +bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const +{ + struct utimbuf times; + times.actime = (time_t) (accessTime / 1000); + times.modtime = (time_t) (modificationTime / 1000); + + return utime (fullPath.toUTF8(), ×) == 0; } bool File::deleteFile() const @@ -280,20 +311,17 @@ bool File::deleteFile() const return remove (fullPath.toUTF8()) == 0; } -bool juce_copyFile (const String& s, const String& d); - -bool juce_moveFile (const String& source, const String& dest) +bool File::moveInternal (const File& dest) const { - if (rename (source.toUTF8(), dest.toUTF8()) == 0) + if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0) return true; - if (juce_canWriteToFile (source) - && juce_copyFile (source, dest)) + if (hasWriteAccess() && copyInternal (dest)) { - if (File (source).deleteFile()) + if (deleteFile()) return true; - File (dest).deleteFile(); + dest.deleteFile(); } return false; diff --git a/src/native/linux/juce_linux_Audio.cpp b/src/native/linux/juce_linux_Audio.cpp index b189791159..21c8124fbe 100644 --- a/src/native/linux/juce_linux_Audio.cpp +++ b/src/native/linux/juce_linux_Audio.cpp @@ -652,14 +652,12 @@ public: outputId (outputId_), isOpen_ (false), isStarted (false), - internal (0) + internal (new ALSAThread (inputId_, outputId_)) { - internal = new ALSAThread (inputId, outputId); } ~ALSAAudioIODevice() { - delete internal; } const StringArray getOutputChannelNames() @@ -817,7 +815,7 @@ public: private: bool isOpen_, isStarted; - ALSAThread* internal; + ScopedPointer internal; }; diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index 1a15b74ebe..e4da3a0144 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -33,66 +33,26 @@ static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h //============================================================================== -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) +bool File::copyInternal (const File& dest) const { - modificationTime = 0; - accessTime = 0; - creationTime = 0; + FileInputStream in (*this); - struct stat info; - const int res = stat (fileName.toUTF8(), &info); - if (res == 0) + if (dest.deleteFile()) { - modificationTime = (int64) info.st_mtime * 1000; - accessTime = (int64) info.st_atime * 1000; - creationTime = (int64) info.st_ctime * 1000; - } -} - -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) -{ - struct utimbuf times; - times.actime = (time_t) (accessTime / 1000); - times.modtime = (time_t) (modificationTime / 1000); - - return utime (fileName.toUTF8(), ×) == 0; -} - -bool juce_copyFile (const String& s, const String& d) -{ - const File source (s), dest (d); - - FileInputStream* in = source.createInputStream(); - bool ok = false; - - if (in != 0) - { - if (dest.deleteFile()) { - FileOutputStream* const out = dest.createOutputStream(); + FileOutputStream out (dest); - if (out != 0) - { - const int bytesCopied = out->writeFromInputStream (*in, -1); - delete out; + if (out.failedToOpen()) + return false; - ok = (bytesCopied == source.getSize()); - - if (! ok) - dest.deleteFile(); - } + if (out.writeFromInputStream (in, -1) == getSize()) + return true; } - delete in; + dest.deleteFile(); } - return ok; + return false; } void File::findFileSystemRoots (Array& destArray) @@ -105,11 +65,8 @@ bool File::isOnCDRomDrive() const { struct statfs buf; - if (statfs (getFullPathName().toUTF8(), &buf) == 0) - return (buf.f_type == U_ISOFS_SUPER_MAGIC); - - // Assume not if this fails for some reason - return false; + return statfs (getFullPathName().toUTF8(), &buf) == 0 + && buf.f_type == U_ISOFS_SUPER_MAGIC; } bool File::isOnHardDisk() const @@ -292,30 +249,24 @@ public: if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0) { filenameFound = String::fromUTF8 (de->d_name); - const String path (parentDir + filenameFound); - if (isDir != 0 || fileSize != 0) + if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) { struct stat info; - const bool statOk = (stat (path.toUTF8(), &info) == 0); + const bool statOk = juce_stat (path, info); - if (isDir != 0) *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0)); - if (isHidden != 0) *isHidden = (de->d_name[0] == '.'); - if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0; + if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0; } - if (modTime != 0 || creationTime != 0) - { - int64 m, a, c; - juce_getFileTimes (path, m, a, c); - - if (modTime != 0) *modTime = m; - if (creationTime != 0) *creationTime = c; - } + if (isHidden != 0) + *isHidden = filenameFound.startsWithChar ('.'); if (isReadOnly != 0) - *isReadOnly = ! juce_canWriteToFile (path); + *isReadOnly = access (path.toUTF8(), W_OK) != 0; return true; } @@ -349,8 +300,7 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, //============================================================================== -bool juce_launchFile (const String& fileName, - const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { String cmdString (fileName.replace (" ", "\\ ",false)); cmdString << " " << parameters; diff --git a/src/native/linux/juce_linux_Fonts.cpp b/src/native/linux/juce_linux_Fonts.cpp index 6e03d6938e..e077fc99d5 100644 --- a/src/native/linux/juce_linux_Fonts.cpp +++ b/src/native/linux/juce_linux_Fonts.cpp @@ -108,7 +108,7 @@ public: if (fontDirs.size() == 0) { XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf")); - XmlElement* const fontsInfo = fontsConfig.getDocumentElement(); + const ScopedPointer fontsInfo (fontsConfig.getDocumentElement()); if (fontsInfo != 0) { @@ -116,8 +116,6 @@ public: { fontDirs.add (e->getAllSubText().trim()); } - - delete fontsInfo; } } diff --git a/src/native/linux/juce_linux_Network.cpp b/src/native/linux/juce_linux_Network.cpp index a3fd6cc198..bfd15fa1f6 100644 --- a/src/native/linux/juce_linux_Network.cpp +++ b/src/native/linux/juce_linux_Network.cpp @@ -412,11 +412,6 @@ private: }; //============================================================================== -bool juce_isOnLine() -{ - return true; -} - void* juce_openInternetFile (const String& url, const String& headers, const MemoryBlock& postData, @@ -437,10 +432,7 @@ void* juce_openInternetFile (const String& url, void juce_closeInternetFile (void* handle) { - JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle; - - if (s != 0) - delete s; + delete static_cast (handle); } int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead) diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 73c25b969d..8c5ab8cf8e 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -210,7 +210,15 @@ public: { if (! transform.isSingularity()) { - Image* singleChannelImage = createAlphaChannelImage (sourceImage); + ScopedPointer imageToDelete; + const Image* singleChannelImage = &sourceImage; + + if (sourceImage.getFormat() != Image::SingleChannel) + { + imageToDelete = sourceImage.createCopyOfAlphaChannel(); + singleChannelImage = imageToDelete; + } + CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace); flip(); @@ -224,7 +232,6 @@ public: flip(); CGImageRelease (image); - deleteAlphaChannelImage (sourceImage, singleChannelImage); } } @@ -697,20 +704,6 @@ private: } } - static Image* createAlphaChannelImage (const Image& im) - { - if (im.getFormat() == Image::SingleChannel) - return const_cast (&im); - - return im.createCopyOfAlphaChannel(); - } - - static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm) - { - if (im.getFormat() != Image::SingleChannel) - delete alphaIm; - } - void flip() const { CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight)); diff --git a/src/native/mac/juce_mac_Files.mm b/src/native/mac/juce_mac_Files.mm index 50010f1104..36526f52e0 100644 --- a/src/native/mac/juce_mac_Files.mm +++ b/src/native/mac/juce_mac_Files.mm @@ -33,50 +33,19 @@ */ //============================================================================== -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) -{ - modificationTime = 0; - accessTime = 0; - creationTime = 0; - - struct stat info; - const int res = stat (fileName.toUTF8(), &info); - if (res == 0) - { - modificationTime = (int64) info.st_mtime * 1000; - accessTime = (int64) info.st_atime * 1000; - creationTime = (int64) info.st_ctime * 1000; - } -} - -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) -{ - struct utimbuf times; - times.actime = (time_t) (accessTime / 1000); - times.modtime = (time_t) (modificationTime / 1000); - - return utime (fileName.toUTF8(), ×) == 0; -} - -bool juce_copyFile (const String& src, const String& dst) +bool File::copyInternal (const File& dest) const { const ScopedAutoReleasePool pool; NSFileManager* fm = [NSFileManager defaultManager]; - return [fm fileExistsAtPath: juceStringToNS (src)] + return [fm fileExistsAtPath: juceStringToNS (fullPath)] #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - && [fm copyItemAtPath: juceStringToNS (src) - toPath: juceStringToNS (dst) + && [fm copyItemAtPath: juceStringToNS (fullPath) + toPath: juceStringToNS (dest.getFullPathName()) error: nil]; #else - && [fm copyPath: juceStringToNS (src) - toPath: juceStringToNS (dst) + && [fm copyPath: juceStringToNS (fullPath) + toPath: juceStringToNS (dest.getFullPathName()) handler: nil]; #endif } @@ -345,27 +314,22 @@ public: const String path (parentDir + filenameFound); - if (isDir != 0 || fileSize != 0) + if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) { struct stat info; const bool statOk = juce_stat (path, info); - if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (isHidden != 0) *isHidden = juce_isHiddenFile (path); - if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != 0) *fileSize = statOk ? info.st_size : 0; + if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0; + if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0; } - if (modTime != 0 || creationTime != 0) - { - int64 m, a, c; - juce_getFileTimes (path, m, a, c); - - if (modTime != 0) *modTime = m; - if (creationTime != 0) *creationTime = c; - } + if (isHidden != 0) + *isHidden = juce_isHiddenFile (path); if (isReadOnly != 0) - *isReadOnly = ! juce_canWriteToFile (path); + *isReadOnly = access (path.toUTF8(), W_OK) != 0; return true; } @@ -419,7 +383,7 @@ bool juce_launchExecutable (const String& pathAndArguments) return true; } -bool juce_launchFile (const String& fileName, const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { #if JUCE_IPHONE return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]]; diff --git a/src/native/mac/juce_mac_Network.mm b/src/native/mac/juce_mac_Network.mm index 025116aa92..018486d209 100644 --- a/src/native/mac/juce_mac_Network.mm +++ b/src/native/mac/juce_mac_Network.mm @@ -326,11 +326,6 @@ public: BEGIN_JUCE_NAMESPACE -bool juce_isOnLine() -{ - return true; -} - void* juce_openInternetFile (const String& url, const String& headers, const MemoryBlock& postData, diff --git a/src/native/windows/juce_win32_ActiveXComponent.cpp b/src/native/windows/juce_win32_ActiveXComponent.cpp index 7ef22d9277..fdad85f307 100644 --- a/src/native/windows/juce_win32_ActiveXComponent.cpp +++ b/src/native/windows/juce_win32_ActiveXComponent.cpp @@ -29,33 +29,12 @@ namespace ActiveXHelpers { - class JuceIStorage : public IStorage + //============================================================================== + class JuceIStorage : public ComBaseClassHelper { - int refCount; - public: - JuceIStorage() : refCount (1) {} - - virtual ~JuceIStorage() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IStorage) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + JuceIStorage() {} + ~JuceIStorage() {} HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; } HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; } @@ -76,39 +55,14 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - - class JuceOleInPlaceFrame : public IOleInPlaceFrame + //============================================================================== + class JuceOleInPlaceFrame : public ComBaseClassHelper { - int refCount; HWND window; public: - JuceOleInPlaceFrame (HWND window_) - : refCount (1), - window (window_) - { - } - - virtual ~JuceOleInPlaceFrame() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IOleInPlaceFrame) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + JuceOleInPlaceFrame (HWND window_) : window (window_) {} + ~JuceOleInPlaceFrame() {} HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; } HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; } @@ -126,43 +80,23 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - - class JuceIOleInPlaceSite : public IOleInPlaceSite + //============================================================================== + class JuceIOleInPlaceSite : public ComBaseClassHelper { - int refCount; HWND window; JuceOleInPlaceFrame* frame; public: JuceIOleInPlaceSite (HWND window_) - : refCount (1), - window (window_) - { - frame = new JuceOleInPlaceFrame (window); - } + : window (window_), + frame (new JuceOleInPlaceFrame (window)) + {} - virtual ~JuceIOleInPlaceSite() + ~JuceIOleInPlaceSite() { - jassert (refCount == 0); frame->Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IOleInPlaceSite) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; } HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; } HRESULT __stdcall CanInPlaceActivate() { return S_OK; } @@ -190,47 +124,33 @@ namespace ActiveXHelpers juce_UseDebuggingNewOperator }; - - class JuceIOleClientSite : public IOleClientSite + //============================================================================== + class JuceIOleClientSite : public ComBaseClassHelper { - int refCount; JuceIOleInPlaceSite* inplaceSite; public: JuceIOleClientSite (HWND window) - : refCount (1) - { - inplaceSite = new JuceIOleInPlaceSite (window); - } + : inplaceSite (new JuceIOleInPlaceSite (window)) + {} - virtual ~JuceIOleClientSite() + ~JuceIOleClientSite() { - jassert (refCount == 0); inplaceSite->Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) + HRESULT __stdcall QueryInterface (REFIID type, void __RPC_FAR* __RPC_FAR* result) { - if (id == IID_IUnknown || id == IID_IOleClientSite) - { - AddRef(); - *result = this; - return S_OK; - } - else if (id == IID_IOleInPlaceSite) + if (type == IID_IOleInPlaceSite) { inplaceSite->AddRef(); - *result = inplaceSite; + *result = static_cast (inplaceSite); return S_OK; } - *result = 0; - return E_NOINTERFACE; + return ComBaseClassHelper ::QueryInterface (type, result); } - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall SaveObject() { return E_NOTIMPL; } HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; } HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; } diff --git a/src/native/windows/juce_win32_AudioCDReader.cpp b/src/native/windows/juce_win32_AudioCDReader.cpp index 2750e067a4..78fd3748ee 100644 --- a/src/native/windows/juce_win32_AudioCDReader.cpp +++ b/src/native/windows/juce_win32_AudioCDReader.cpp @@ -2137,13 +2137,13 @@ static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMa } //============================================================================== -class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents, +class AudioCDBurner::Pimpl : public ComBaseClassHelper , public Timer { public: Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_) : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0), - listener (0), progress (0), shouldCancel (false), refCount (1) + listener (0), progress (0), shouldCancel (false) { HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook); jassert (SUCCEEDED (hr)); @@ -2166,25 +2166,6 @@ public: Release(); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (result == 0) - return E_POINTER; - - if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall QueryCancel (boolean* pbCancel) { if (listener != 0 && ! shouldCancel) @@ -2296,9 +2277,6 @@ public: AudioCDBurner::BurnProgressListener* listener; float progress; bool shouldCancel; - -private: - int refCount; }; //============================================================================== diff --git a/src/native/windows/juce_win32_CameraDevice.cpp b/src/native/windows/juce_win32_CameraDevice.cpp index b9979fa4f5..9376e20cb5 100644 --- a/src/native/windows/juce_win32_CameraDevice.cpp +++ b/src/native/windows/juce_win32_CameraDevice.cpp @@ -624,7 +624,7 @@ private: } //============================================================================== - class GrabberCallback : public ISampleGrabberCB + class GrabberCallback : public ComBaseClassHelper { public: GrabberCallback (DShowCameraDeviceInteral& owner_) @@ -632,25 +632,6 @@ private: { } - HRESULT __stdcall QueryInterface (REFIID id, void** result) - { - if (id == IID_IUnknown) - *result = dynamic_cast (this); - else if (id == IID_ISampleGrabberCB) - *result = dynamic_cast (this); - else - { - *result = 0; - return E_NOINTERFACE; - } - - AddRef(); - return S_OK; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } - //============================================================================== STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/) { @@ -664,7 +645,6 @@ private: } private: - int refCount; DShowCameraDeviceInteral& owner; GrabberCallback (const GrabberCallback&); @@ -691,13 +671,13 @@ CameraDevice::CameraDevice (const String& name_, int /*index*/) CameraDevice::~CameraDevice() { stopRecording(); - delete (DShowCameraDeviceInteral*) internal; + delete static_cast (internal); internal = 0; } Component* CameraDevice::createViewerComponent() { - return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal); + return new DShowCameraDeviceInteral::DShowCaptureViewerComp (static_cast (internal)); } const String CameraDevice::getFileExtension() @@ -837,16 +817,15 @@ CameraDevice* CameraDevice::openDevice (int index, if (filter != 0) { - CameraDevice* const cam = new CameraDevice (name, index); + ScopedPointer cam (new CameraDevice (name, index)); + DShowCameraDeviceInteral* const intern = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter, minWidth, minHeight, maxWidth, maxHeight); cam->internal = intern; if (intern->ok) - return cam; - else - delete cam; + return cam.release(); } } diff --git a/src/native/windows/juce_win32_Files.cpp b/src/native/windows/juce_win32_Files.cpp index 02fa7bbc2b..1de88c9182 100644 --- a/src/native/windows/juce_win32_Files.cpp +++ b/src/native/windows/juce_win32_Files.cpp @@ -65,28 +65,32 @@ bool File::isDirectory() const return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES); } -bool juce_canWriteToFile (const String& fileName) +bool File::hasWriteAccess() const { - const DWORD attr = GetFileAttributes (fileName); - return (attr & FILE_ATTRIBUTE_READONLY) == 0; + if (exists()) + return (GetFileAttributes (fullPath) & 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.. + return true; } -bool juce_setFileReadOnly (const String& fileName, bool isReadOnly) +bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const { - DWORD attr = GetFileAttributes (fileName); + DWORD attr = GetFileAttributes (fullPath); if (attr == INVALID_FILE_ATTRIBUTES) return false; - if (isReadOnly != juce_canWriteToFile (fileName)) + if (shouldBeReadOnly == ((attr & FILE_ATTRIBUTE_READONLY) != 0)) return true; - if (isReadOnly) + if (shouldBeReadOnly) attr |= FILE_ATTRIBUTE_READONLY; else attr &= ~FILE_ATTRIBUTE_READONLY; - return SetFileAttributes (fileName, attr) != FALSE; + return SetFileAttributes (fullPath, attr) != FALSE; } bool File::isHidden() const @@ -126,14 +130,14 @@ bool File::moveToTrash() const return SHFileOperation (&fos) == 0; } -bool juce_moveFile (const String& source, const String& dest) +bool File::copyInternal (const File& dest) const { - return MoveFile (source, dest) != 0; + return CopyFile (fullPath, dest.getFullPathName(), false) != 0; } -bool juce_copyFile (const String& source, const String& dest) +bool File::moveInternal (const File& dest) const { - return CopyFile (source, dest, false) != 0; + return MoveFile (fullPath, dest.getFullPathName()) != 0; } void File::createDirectoryInternal (const String& fileName) const @@ -237,14 +241,11 @@ static void timeToFileTime (const int64 time, FILETIME* const ft) reinterpret_cast (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000); } -void juce_getFileTimes (const String& fileName, - int64& modificationTime, - int64& accessTime, - int64& creationTime) +void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const { WIN32_FILE_ATTRIBUTE_DATA attributes; - if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes)) + if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes)) { modificationTime = fileTimeToTime (&attributes.ftLastWriteTime); creationTime = fileTimeToTime (&attributes.ftCreationTime); @@ -256,12 +257,9 @@ void juce_getFileTimes (const String& fileName, } } -bool juce_setFileTimes (const String& fileName, - int64 modificationTime, - int64 accessTime, - int64 creationTime) +bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const { - void* const h = juce_fileOpen (fileName, true); + void* const h = juce_fileOpen (fullPath, true); bool ok = false; if (h != 0) @@ -600,7 +598,7 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, //============================================================================== -bool juce_launchFile (const String& fileName, const String& parameters) +bool PlatformUtilities::openDocument (const String& fileName, const String& parameters) { HINSTANCE hInstance = 0; diff --git a/src/native/windows/juce_win32_NativeIncludes.h b/src/native/windows/juce_win32_NativeIncludes.h index dfd209ef98..db1abf18ec 100644 --- a/src/native/windows/juce_win32_NativeIncludes.h +++ b/src/native/windows/juce_win32_NativeIncludes.h @@ -228,5 +228,28 @@ public: T* p; }; +//============================================================================== +template +class ComBaseClassHelper : public ComClass +{ +public: + ComBaseClassHelper() : refCount (1) {} + virtual ~ComBaseClassHelper() {} + + HRESULT __stdcall QueryInterface (REFIID refId, void __RPC_FAR* __RPC_FAR* result) + { + if (refId == __uuidof (ComClass)) { AddRef(); *result = dynamic_cast (this); return S_OK; } + if (refId == IID_IUnknown) { AddRef(); *result = dynamic_cast (this); return S_OK; } + + *result = 0; + return E_NOINTERFACE; + } + + ULONG __stdcall AddRef() { return ++refCount; } + ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; } + +protected: + int refCount; +}; #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__ diff --git a/src/native/windows/juce_win32_Network.cpp b/src/native/windows/juce_win32_Network.cpp index 81d77f3a54..c7ae272b0e 100644 --- a/src/native/windows/juce_win32_Network.cpp +++ b/src/native/windows/juce_win32_Network.cpp @@ -37,14 +37,6 @@ #endif //============================================================================== -bool juce_isOnLine() -{ - DWORD connectionType; - - return InternetGetConnectedState (&connectionType, 0) != 0 - || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0; -} - struct ConnectionAndRequestStruct { HINTERNET connection, request; @@ -293,10 +285,9 @@ void juce_closeInternetFile (void* handle) { if (handle != 0) { - ConnectionAndRequestStruct* const crs = static_cast (handle); + ScopedPointer crs (static_cast (handle)); InternetCloseHandle (crs->request); InternetCloseHandle (crs->connection); - delete crs; } } diff --git a/src/native/windows/juce_win32_WebBrowserComponent.cpp b/src/native/windows/juce_win32_WebBrowserComponent.cpp index c7aad1b86a..b9c56dca7b 100644 --- a/src/native/windows/juce_win32_WebBrowserComponent.cpp +++ b/src/native/windows/juce_win32_WebBrowserComponent.cpp @@ -68,6 +68,7 @@ public: EventHandler* handler = new EventHandler (owner); connectionPoint->Advise (handler, &adviseCookie); + handler->Release(); } } } @@ -142,14 +143,13 @@ private: DWORD adviseCookie; //============================================================================== - class EventHandler : public IDispatch, + class EventHandler : public ComBaseClassHelper , public ComponentMovementWatcher { public: EventHandler (WebBrowserComponent* owner_) : ComponentMovementWatcher (owner_), - owner (owner_), - refCount (0) + owner (owner_) { } @@ -158,22 +158,6 @@ private: } //============================================================================== - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; } HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; } HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; } @@ -223,7 +207,6 @@ private: private: WebBrowserComponent* const owner; - int refCount; EventHandler (const EventHandler&); EventHandler& operator= (const EventHandler&); diff --git a/src/native/windows/juce_win32_Windowing.cpp b/src/native/windows/juce_win32_Windowing.cpp index 01da9fbd64..1ef038e8bc 100644 --- a/src/native/windows/juce_win32_Windowing.cpp +++ b/src/native/windows/juce_win32_Windowing.cpp @@ -844,15 +844,8 @@ private: { public: //============================================================================== - TemporaryImage() - : image (0) - { - } - - ~TemporaryImage() - { - delete image; - } + TemporaryImage() {} + ~TemporaryImage() {} //============================================================================== WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw() @@ -860,10 +853,7 @@ private: const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB; if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format) - { - delete image; image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false); - } startTimer (3000); return image; @@ -873,11 +863,11 @@ private: void timerCallback() { stopTimer(); - deleteAndZero (image); + image = 0; } private: - WindowsBitmapImage* image; + ScopedPointer image; TemporaryImage (const TemporaryImage&); TemporaryImage& operator= (const TemporaryImage&); @@ -1526,35 +1516,15 @@ private: } //============================================================================== - class JuceDropTarget : public IDropTarget + class JuceDropTarget : public ComBaseClassHelper { public: JuceDropTarget (Win32ComponentPeer* const owner_) - : owner (owner_), - refCount (1) + : owner (owner_) { } - virtual ~JuceDropTarget() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDropTarget) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + ~JuceDropTarget() {} HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect) { @@ -1587,7 +1557,6 @@ private: private: Win32ComponentPeer* const owner; - int refCount; StringArray files; void updateFileList (IDataObject* const pDataObject) @@ -2411,15 +2380,13 @@ static Image* createImageFromHICON (HICON icon) throw() if (GetIconInfo (icon, &info)) { - Image* const mask = createImageFromHBITMAP (info.hbmMask); - + ScopedPointer mask (createImageFromHBITMAP (info.hbmMask)); if (mask == 0) return 0; - Image* const image = createImageFromHBITMAP (info.hbmColor); - + ScopedPointer image (createImageFromHBITMAP (info.hbmColor)); if (image == 0) - return mask; + return mask.release(); for (int y = image->getHeight(); --y >= 0;) { @@ -2432,8 +2399,7 @@ static Image* createImageFromHICON (HICON icon) throw() } } - delete mask; - return image; + return image.release(); } return 0; @@ -2673,36 +2639,11 @@ void MouseCursor::showInAllWindows() const //============================================================================== //============================================================================== -class JuceDropSource : public IDropSource +class JuceDropSource : public ComBaseClassHelper { - int refCount; - public: - JuceDropSource() - : refCount (1) - { - } - - virtual ~JuceDropSource() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDropSource) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + JuceDropSource() {} + ~JuceDropSource() {} HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys) { @@ -2722,36 +2663,16 @@ public: }; -class JuceEnumFormatEtc : public IEnumFORMATETC +class JuceEnumFormatEtc : public ComBaseClassHelper { public: JuceEnumFormatEtc (const FORMATETC* const format_) - : refCount (1), - format (format_), + : format (format_), index (0) { } - virtual ~JuceEnumFormatEtc() - { - jassert (refCount == 0); - } - - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IEnumFORMATETC) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } + ~JuceEnumFormatEtc() {} HRESULT __stdcall Clone (IEnumFORMATETC** result) { @@ -2802,7 +2723,6 @@ public: } private: - int refCount; const FORMATETC* const format; int index; @@ -2821,12 +2741,11 @@ private: JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&); }; -class JuceDataObject : public IDataObject +class JuceDataObject : public ComBaseClassHelper { JuceDropSource* const dropSource; const FORMATETC* const format; const STGMEDIUM* const medium; - int refCount; JuceDataObject (const JuceDataObject&); JuceDataObject& operator= (const JuceDataObject&); @@ -2837,8 +2756,7 @@ public: const STGMEDIUM* const medium_) : dropSource (dropSource_), format (format_), - medium (medium_), - refCount (1) + medium (medium_) { } @@ -2847,22 +2765,6 @@ public: jassert (refCount == 0); } - HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result) - { - if (id == IID_IUnknown || id == IID_IDataObject) - { - AddRef(); - *result = this; - return S_OK; - } - - *result = 0; - return E_NOINTERFACE; - } - - ULONG __stdcall AddRef() { return ++refCount; } - ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; } - HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium) { if ((pFormatEtc->tymed & format->tymed) != 0