diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h index df37c0a1f0..c209d7bb71 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectSaver.h @@ -468,7 +468,9 @@ private: if (maxSize <= 0) maxSize = 10 * 1024 * 1024; - if (resourceFile.write (binaryDataFiles, maxSize)) + Result r (resourceFile.write (binaryDataFiles, maxSize)); + + if (r.wasOk()) { hasBinaryData = true; @@ -482,8 +484,7 @@ private: } else { - addError ("Can't create binary resources file: " - + project.getBinaryDataCppFile(0).getFullPathName()); + addError (r.getErrorMessage()); } } else diff --git a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp index ba0fd54545..a5aa6b7555 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp +++ b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.cpp @@ -109,7 +109,7 @@ static String getComment() return comment; } -bool ResourceFile::writeHeader (MemoryOutputStream& header) +Result ResourceFile::writeHeader (MemoryOutputStream& header) { const String headerGuard ("BINARYDATA_H_" + String (project.getProjectUID().hashCode() & 0x7ffffff) + "_INCLUDED"); @@ -126,6 +126,10 @@ bool ResourceFile::writeHeader (MemoryOutputStream& header) for (int i = 0; i < files.size(); ++i) { const File& file = files.getReference(i); + + if (! file.existsAsFile()) + return Result::fail ("Can't open resource file: " + file.getFullPathName()); + const int64 dataSize = file.getSize(); const String variableName (variableNames[i]); @@ -155,10 +159,10 @@ bool ResourceFile::writeHeader (MemoryOutputStream& header) << newLine << "#endif" << newLine; - return true; + return Result::ok(); } -bool ResourceFile::writeCpp (MemoryOutputStream& cpp, const File& headerFile, int& i, const int maxFileSize) +Result ResourceFile::writeCpp (MemoryOutputStream& cpp, const File& headerFile, int& i, const int maxFileSize) { const bool isFirstFile = (i == 0); @@ -247,17 +251,22 @@ bool ResourceFile::writeCpp (MemoryOutputStream& cpp, const File& headerFile, in cpp << newLine << "}" << newLine; - return true; + return Result::ok(); } -bool ResourceFile::write (Array& filesCreated, const int maxFileSize) +Result ResourceFile::write (Array& filesCreated, const int maxFileSize) { const File headerFile (project.getBinaryDataHeaderFile()); { MemoryOutputStream mo; - if (! (writeHeader (mo) && FileHelpers::overwriteFileWithNewDataIfDifferent (headerFile, mo))) - return false; + Result r (writeHeader (mo)); + + if (r.failed()) + return r; + + if (! FileHelpers::overwriteFileWithNewDataIfDifferent (headerFile, mo)) + return Result::fail ("Can't write to file: " + headerFile.getFullPathName()); filesCreated.add (headerFile); } @@ -270,8 +279,14 @@ bool ResourceFile::write (Array& filesCreated, const int maxFileSize) File cpp (project.getBinaryDataCppFile (fileIndex)); MemoryOutputStream mo; - if (! (writeCpp (mo, headerFile, i, maxFileSize) && FileHelpers::overwriteFileWithNewDataIfDifferent (cpp, mo))) - return false; + + Result r (writeCpp (mo, headerFile, i, maxFileSize)); + + if (r.failed()) + return r; + + if (! FileHelpers::overwriteFileWithNewDataIfDifferent (cpp, mo)) + return Result::fail ("Can't write to file: " + cpp.getFullPathName()); filesCreated.add (cpp); ++fileIndex; @@ -280,5 +295,5 @@ bool ResourceFile::write (Array& filesCreated, const int maxFileSize) break; } - return true; + return Result::ok(); } diff --git a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h index 5efe0f3252..10284dd97d 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ResourceFile.h @@ -50,7 +50,7 @@ public: int64 getTotalDataSize() const; - bool write (Array& filesCreated, int maxFileSize); + Result write (Array& filesCreated, int maxFileSize); //============================================================================== private: @@ -59,8 +59,8 @@ private: Project& project; String className; - bool writeHeader (MemoryOutputStream&); - bool writeCpp (MemoryOutputStream&, const File& headerFile, int& index, int maxFileSize); + Result writeHeader (MemoryOutputStream&); + Result writeCpp (MemoryOutputStream&, const File& headerFile, int& index, int maxFileSize); void addResourcesFromProjectItem (const Project::Item& node); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResourceFile)