X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=CollectionReader.cpp;h=00427ffab6800bbb73ad2c0d4894e0e3977b0c32;hb=e4f9c67cc94df1e370846b19ddedd4365df7b638;hp=2f4a3cd94da33960f636589caa3c920ff2f880f3;hpb=8c428eac937ccba2a2bb459ce9999a1adba5e6c0;p=ecparse.git diff --git a/CollectionReader.cpp b/CollectionReader.cpp index 2f4a3cd..00427ff 100644 --- a/CollectionReader.cpp +++ b/CollectionReader.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "CollectionReader.h" #include "GlobalSettings.h" @@ -84,6 +83,21 @@ BlobTag* CollectionReader::readBlobTag(bool header) { return blobTag; } +HashTag* CollectionReader::readHashTag() { + if (!ensureBufferCapacity(1)) { + return NULL; + } + uint8_t tagId = 0; + growingBuffer.read(&tagId, 1); + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag id %d.\n", __FILE__, __LINE__, tagId); + if (!ensureBufferCapacity(16)) { + return NULL; + } + char hash[16]; + growingBuffer.read(hash, 16); + return new HashTag(tagId, hash); +} + ED2KLink* CollectionReader::getNextLink() { if (readerInput->isEOF() && !growingBuffer.getRemaining()) { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] readInput EOF reached.\n", __FILE__, __LINE__); @@ -95,7 +109,6 @@ ED2KLink* CollectionReader::getNextLink() { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] readInput EOF reached.\n", __FILE__, __LINE__); return NULL; } - firstLink = false; } if (isTextCollection) { while (!readerInput->isEOF() && !isLineBreakPresent()) { @@ -128,7 +141,8 @@ ED2KLink* CollectionReader::getNextLink() { ED2KLink* ed2kLink = ED2KLink::parseED2KLink(line); free(line); return ed2kLink; - } else { + } + if (firstLink) { /* read header */ if (!ensureBufferCapacity(4)) { return NULL; @@ -163,6 +177,18 @@ ED2KLink* CollectionReader::getNextLink() { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] unknown tag type: %02x.\n", __FILE__, __LINE__, tagType); } } + fileCollectionCount = 0; + if (!ensureBufferCapacity(4)) { + return NULL; + } + growingBuffer.read(&fileCollectionCount, 4); + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] will read %d files.\n", __FILE__, __LINE__, fileCollectionCount); + collectionFileIndex = 0; + firstLink = false; + } + if (collectionFileIndex < fileCollectionCount) { + } else { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] reached end of collection.\n", __FILE__, __LINE__); } return NULL; } @@ -188,7 +214,6 @@ void CollectionReader::readMoreBytes() { } void CollectionReader::identifyCollectionType() { - int version; size_t readBytes; readBytes = readerInput->read(&version, 4); @@ -206,6 +231,7 @@ void CollectionReader::identifyCollectionType() { } else if (!strncmp("ed2k", (char*) &version, 4)) { isTextCollection = true; growingBuffer.write(&version, 4); + version = 0; GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] identified text collection\n", __FILE__, __LINE__); } else { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] could not identify collection!\n", __FILE__, __LINE__);