MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / updateResourceHash

Method updateResourceHash

gui/nbrowserwindow.cpp:3008–3037  ·  view source on GitHub ↗

Update a resource's hash if it was edited somewhere else

Source from the content-addressed store, hash-verified

3006
3007// Update a resource's hash if it was edited somewhere else
3008void NBrowserWindow::updateResourceHash(qint32 noteLid, QByteArray oldHash, QByteArray newHash) {
3009 if (noteLid != lid)
3010 return;
3011
3012 QString content = editor->editorPage->mainFrame()->documentElement().toOuterXml();
3013
3014 // Start going through & looking for the old hash
3015 int pos = content.indexOf("<body");
3016 int endPos;
3017 int hashPos = -1;
3018 QString hashString = "hash=\"" +oldHash.toHex() +"\"";
3019 while (pos != -1) {
3020 endPos = content.indexOf(">", pos); // Find the matching end of the tag
3021 hashPos = content.indexOf(hashString, pos);
3022 if (hashPos < endPos && hashPos != -1) { // If we found the hash, begin the update
3023 QString startString = content.mid(0, hashPos);
3024 QString endString = content.mid(hashPos+hashString.length());
3025 QString newContent = startString + "hash=\"" +newHash.toHex() +"\"" +endString;
3026 QByteArray byteArray;
3027 byteArray.append(newContent);
3028 editor->setContent(byteArray);
3029 noteUpdated(lid);
3030 return;
3031 } else {
3032 pos = content.indexOf("<", pos+1);
3033 }
3034 }
3035
3036
3037}
3038
3039
3040

Callers 1

updateImageHashMethod · 0.45

Calls 1

setContentMethod · 0.45

Tested by

no test coverage detected