//============================================================================== static bool munge (const File& templateFile, const File& targetFile, const String& wildcard, StringArray& alreadyIncludedFiles, const StringArray& includesToIgnore) { if (! templateFile.existsAsFile()) { std::cout << " The template file doesn't exist!\n\n"; return false; } StringArray wildcards; wildcards.addTokens (wildcard, ";,", "'\""); wildcards.trim(); wildcards.removeEmptyStrings(); std::cout << "Building: " << targetFile.getFullPathName() << "...\n"; TemporaryFile temp (targetFile); ScopedPointer <FileOutputStream> out (temp.getFile().createOutputStream (1024 * 128)); if (out == 0) { std::cout << "\n!! ERROR - couldn't write to the target file: " << temp.getFile().getFullPathName() << "\n\n"; return false; } out->setNewLineString ("\n"); if (! parseFile (targetFile.getParentDirectory(), targetFile, *out, templateFile, alreadyIncludedFiles, includesToIgnore, wildcards, true, false)) { return false; } out = 0; if (calculateFileHashCode (targetFile) == calculateFileHashCode (temp.getFile())) { std::cout << " -- No need to write - new file is identical\n"; return true; } if (! temp.overwriteTargetFileWithTemporary()) { std::cout << "\n!! ERROR - couldn't write to the target file: " << targetFile.getFullPathName() << "\n\n"; return false; } return true; }
bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, size_t numBytes) { if (file.getSize() == (int64) numBytes && calculateMemoryHashCode (data, numBytes) == calculateFileHashCode (file)) return true; if (file.exists()) return file.replaceWithData (data, numBytes); return file.appendData (data, numBytes); }
bool overwriteFileWithNewDataIfDifferent (const File& file, const void* data, int numBytes) { if (file.getSize() == numBytes) { MemoryInputStream newStream (data, numBytes, false); if (calculateStreamHashCode (newStream) == calculateFileHashCode (file)) return true; } TemporaryFile temp (file); return temp.getFile().appendData (data, numBytes) && temp.overwriteTargetFileWithTemporary(); }