diff --git a/juce_Config.h b/juce_Config.h index 91f22dc768..517cb0c3b0 100644 --- a/juce_Config.h +++ b/juce_Config.h @@ -71,7 +71,7 @@ info about this. */ #ifndef JUCE_ASIO - #define JUCE_ASIO 1 + #define JUCE_ASIO 0 #endif /** JUCE_WASAPI: Enables WASAPI audio devices (Windows Vista and above). @@ -102,7 +102,7 @@ installed, and its header files will need to be on your include path. */ #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC)) - #define JUCE_QUICKTIME 1 + #define JUCE_QUICKTIME 0 #endif @@ -137,7 +137,7 @@ reduce code size. */ #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC) - #define JUCE_USE_CDBURNER 1 + #define JUCE_USE_CDBURNER 0 #endif /** JUCE_USE_CDREADER: Enables the audio CD reader code (Mac and Windows only). @@ -217,7 +217,7 @@ If you're not using any embedded web-pages, turning this off may reduce your code size. */ #ifndef JUCE_WEB_BROWSER - #define JUCE_WEB_BROWSER 1 + #define JUCE_WEB_BROWSER 0 #endif diff --git a/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp b/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp index 5d81f051f4..e515d11b58 100644 --- a/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp @@ -347,7 +347,7 @@ public: { if (ok) { - FLAC__stream_encoder_finish (encoder); + FlacNamespace::FLAC__stream_encoder_finish (encoder); output->flush(); } else @@ -356,7 +356,7 @@ public: // to the caller of createWriter() } - FLAC__stream_encoder_delete (encoder); + FlacNamespace::FLAC__stream_encoder_delete (encoder); } //============================================================================== diff --git a/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp b/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp index be99e5ba14..d92cd90b49 100644 --- a/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_OggVorbisAudioFormat.cpp @@ -127,7 +127,7 @@ public: ~OggReader() { - ov_clear (&ovFile); + OggVorbisNamespace::ov_clear (&ovFile); } //============================================================================== @@ -167,8 +167,8 @@ public: reservoirStart = jmax (0, (int) startSampleInFile); samplesInReservoir = reservoir.getNumSamples(); - if (reservoirStart != (int) ov_pcm_tell (&ovFile)) - ov_pcm_seek (&ovFile, reservoirStart); + if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile)) + OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart); int offset = 0; int numToRead = samplesInReservoir; @@ -177,7 +177,7 @@ public: { float** dataIn = 0; - const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream); + const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream); if (samps <= 0) break; @@ -312,6 +312,7 @@ public: ~OggWriter() { + using namespace OggVorbisNamespace; if (ok) { // write a zero-length packet to show ogg that we're finished.. @@ -336,6 +337,7 @@ public: //============================================================================== bool write (const int** samplesToWrite, int numSamples) { + using namespace OggVorbisNamespace; if (! ok) return false; diff --git a/src/containers/juce_Value.cpp b/src/containers/juce_Value.cpp index abb81abdbd..cb7f1557b7 100644 --- a/src/containers/juce_Value.cpp +++ b/src/containers/juce_Value.cpp @@ -140,6 +140,11 @@ const var Value::getValue() const return value->getValue(); } +Value::operator const var() const +{ + return getValue(); +} + void Value::setValue (const var& newValue) { value->setValue (newValue); diff --git a/src/events/juce_InterprocessConnection.cpp b/src/events/juce_InterprocessConnection.cpp index 03f139ed8b..71d2ea0aa0 100644 --- a/src/events/juce_InterprocessConnection.cpp +++ b/src/events/juce_InterprocessConnection.cpp @@ -281,27 +281,27 @@ bool InterprocessConnection::readNextMessageInt() if (bytes == sizeof (messageHeader) && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader) { - const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]); + int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]); if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize) { MemoryBlock messageData (bytesInMessage, true); int bytesRead = 0; - while (bytesRead < bytesInMessage) + while (bytesInMessage > 0) { if (threadShouldExit()) return false; const int numThisTime = jmin (bytesInMessage, 65536); - const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true) - : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime, - pipeReceiveMessageTimeout); + const int bytesIn = (socket != 0) ? socket->read (static_cast (messageData.getData()) + bytesRead, numThisTime, true) + : pipe->read (static_cast (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout); if (bytesIn <= 0) break; bytesRead += bytesIn; + bytesInMessage -= bytesIn; } if (bytesRead >= 0) diff --git a/src/utilities/juce_PropertiesFile.cpp b/src/utilities/juce_PropertiesFile.cpp index 5853667836..ded019f7f4 100644 --- a/src/utilities/juce_PropertiesFile.cpp +++ b/src/utilities/juce_PropertiesFile.cpp @@ -27,7 +27,6 @@ BEGIN_JUCE_NAMESPACE - #include "juce_PropertiesFile.h" #include "../io/files/juce_TemporaryFile.h" #include "../io/files/juce_FileInputStream.h" @@ -41,20 +40,24 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP")); -static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP")); +namespace PropertyFileConstants +{ + static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP"); + static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP"); -static const tchar* const propertyFileXmlTag = T("PROPERTIES"); -static const tchar* const propertyTagName = T("VALUE"); + static const char* const fileTag = "PROPERTIES"; + static const char* const valueTag = "VALUE"; + static const char* const nameAttribute = "name"; + static const char* const valueAttribute = "val"; +} //============================================================================== -PropertiesFile::PropertiesFile (const File& f, - const int millisecondsBeforeSaving, - const int options_) +PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving, const int options_) : PropertySet (ignoreCaseOfKeyNames), file (f), timerInterval (millisecondsBeforeSaving), options (options_), + loadedOk (false), needsWriting (false) { // You need to correctly specify just one storage format for the file @@ -62,22 +65,21 @@ PropertiesFile::PropertiesFile (const File& f, || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML); - ScopedPointer fileStream (f.createInputStream()); + ScopedPointer fileStream (f.createInputStream()); if (fileStream != 0) { int magicNumber = fileStream->readInt(); - if (magicNumber == propFileMagicNumberCompressed) + if (magicNumber == PropertyFileConstants::magicNumberCompressed) { - fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), - true); - - magicNumber = propFileMagicNumber; + fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true); + magicNumber = PropertyFileConstants::magicNumber; } - if (magicNumber == propFileMagicNumber) + if (magicNumber == PropertyFileConstants::magicNumber) { + loadedOk = true; BufferedInputStream in (fileStream.release(), 2048, true); int numValues = in.readInt(); @@ -98,24 +100,26 @@ PropertiesFile::PropertiesFile (const File& f, fileStream = 0; XmlDocument parser (f); - ScopedPointer doc (parser.getDocumentElement (true)); + ScopedPointer doc (parser.getDocumentElement (true)); - if (doc != 0 && doc->hasTagName (propertyFileXmlTag)) + if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag)) { doc = parser.getDocumentElement(); if (doc != 0) { - forEachXmlChildElementWithTagName (*doc, e, propertyTagName) + loadedOk = true; + + forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag) { - const String name (e->getStringAttribute (T("name"))); + const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute)); if (name.isNotEmpty()) { getAllProperties().set (name, e->getFirstChildElement() != 0 ? e->getFirstChildElement()->createDocument (String::empty, true) - : e->getStringAttribute (T("val"))); + : e->getStringAttribute (PropertyFileConstants::valueAttribute)); } } } @@ -127,6 +131,10 @@ PropertiesFile::PropertiesFile (const File& f, } } } + else + { + loadedOk = ! f.exists(); + } } PropertiesFile::~PropertiesFile() @@ -146,6 +154,11 @@ bool PropertiesFile::needsToBeSaved() const return needsWriting; } +void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved) +{ + const ScopedLock sl (getLock()); + needsWriting = needsToBeSaved; +} bool PropertiesFile::save() { @@ -160,12 +173,12 @@ bool PropertiesFile::save() if ((options & storeAsXML) != 0) { - XmlElement doc (propertyFileXmlTag); + XmlElement doc (PropertyFileConstants::fileTag); for (int i = 0; i < getAllProperties().size(); ++i) { - XmlElement* const e = doc.createNewChildElement (propertyTagName); - e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]); + XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag); + e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]); // if the value seems to contain xml, store it as such.. XmlDocument xmlContent (getAllProperties().getAllValues() [i]); @@ -174,22 +187,26 @@ bool PropertiesFile::save() if (childElement != 0) e->addChildElement (childElement); else - e->setAttribute (T("val"), getAllProperties().getAllValues() [i]); + e->setAttribute (PropertyFileConstants::valueAttribute, + getAllProperties().getAllValues() [i]); } - return doc.writeToFile (file, String::empty); + if (doc.writeToFile (file, String::empty)) + { + needsWriting = false; + return true; + } } else { TemporaryFile tempFile (file); - ScopedPointer out (tempFile.getFile().createOutputStream()); if (out != 0) { if ((options & storeAsCompressedBinary) != 0) { - out->writeInt (propFileMagicNumberCompressed); + out->writeInt (PropertyFileConstants::magicNumberCompressed); out->flush(); out = new GZIPCompressorOutputStream (out.release(), 9, true); @@ -199,7 +216,7 @@ bool PropertiesFile::save() // have you set up the storage option flags correctly? jassert ((options & storeAsBinary) != 0); - out->writeInt (propFileMagicNumber); + out->writeInt (PropertyFileConstants::magicNumber); } const int numProperties = getAllProperties().size(); @@ -260,9 +277,9 @@ const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationN #endif #ifdef JUCE_LINUX - const File dir ((commonToAllUsers ? T("/var/") : T("~/")) + const File dir ((commonToAllUsers ? "/var/" : "~/") + (folderName.isNotEmpty() ? folderName - : (T(".") + applicationName))); + : ("." + applicationName))); #endif #if JUCE_WIN32 diff --git a/src/utilities/juce_PropertiesFile.h b/src/utilities/juce_PropertiesFile.h index bddc8028a9..dea6b86106 100644 --- a/src/utilities/juce_PropertiesFile.h +++ b/src/utilities/juce_PropertiesFile.h @@ -73,13 +73,13 @@ public: each time a value-change method is called). If it is less than zero, the file won't be saved until save() or saveIfNeeded() are explicitly called. - @param options a combination of the flags in the FileFormatOptions + @param optionFlags a combination of the flags in the FileFormatOptions enum, which specify the type of file to save, and other options. */ PropertiesFile (const File& file, - const int millisecondsBeforeSaving, - const int options); + int millisecondsBeforeSaving, + int optionFlags); /** Destructor. @@ -87,6 +87,13 @@ public: */ ~PropertiesFile(); + //============================================================================== + /** Returns true if this file was created from a valid (or non-existent) file. + If the file failed to load correctly because it was corrupt or had insufficient + access, this will be false. + */ + bool isValidFile() const throw() { return loadedOk; } + //============================================================================== /** This will flush all the values to disk if they've changed since the last time they were saved. @@ -108,10 +115,16 @@ public: */ bool save(); - /** Returns true if the properties have been altered since the last time they were - saved. + /** Returns true if the properties have been altered since the last time they were saved. + The file is flagged as needing to be saved when you change a value, but you can + explicitly set this flag with setNeedsToBeSaved(). */ bool needsToBeSaved() const; + + /** Explicitly sets the flag to indicate whether the file needs saving or not. + @see needsToBeSaved + */ + void setNeedsToBeSaved (bool needsToBeSaved); //============================================================================== /** Returns the file that's being used. */ @@ -131,9 +144,9 @@ public: static PropertiesFile* createDefaultAppPropertiesFile (const String& applicationName, const String& fileNameSuffix, const String& folderName, - const bool commonToAllUsers, - const int millisecondsBeforeSaving, - const int propertiesFileOptions); + bool commonToAllUsers, + int millisecondsBeforeSaving, + int propertiesFileOptions); /** Handy utility to choose a file in the standard OS-dependent location for application settings files. @@ -158,7 +171,7 @@ public: static const File getDefaultAppSettingsFile (const String& applicationName, const String& fileNameSuffix, const String& folderName, - const bool commonToAllUsers); + bool commonToAllUsers); //============================================================================== juce_UseDebuggingNewOperator @@ -172,7 +185,7 @@ private: File file; int timerInterval; const int options; - bool needsWriting; + bool loadedOk, needsWriting; void timerCallback();