diff --git a/src/downloader.cpp b/src/downloader.cpp index 7ede4f0..74e6c4a 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -649,19 +649,11 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, { int res = 0; FILE *outfile; - size_t offset=0; - - size_t from_offset, to_offset; - - struct FileInfo { - std::string filename; - std::string hash; - size_t size; - int chunks; - std::vector chunk_from; - std::vector chunk_to; - std::vector chunk_hash; - } info; + size_t offset=0, from_offset, to_offset, filesize; + std::string filehash; + int chunks; + std::vector chunk_from, chunk_to; + std::vector chunk_hash; // Get filename boost::filesystem::path pathname = filepath; @@ -689,10 +681,10 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, { std::cout << "XML: Valid XML" << std::endl; TiXmlElement *fileElem = fileNode->ToElement(); - info.filename = fileElem->Attribute("name"); - info.hash = fileElem->Attribute("md5"); - std::stringstream(fileElem->Attribute("chunks")) >> info.chunks; - std::stringstream(fileElem->Attribute("total_size")) >> info.size; + filename = fileElem->Attribute("name"); + filehash = fileElem->Attribute("md5"); + std::stringstream(fileElem->Attribute("chunks")) >> chunks; + std::stringstream(fileElem->Attribute("total_size")) >> filesize; //Iterate through all chunk nodes TiXmlNode *chunkNode = fileNode->FirstChild(); @@ -701,18 +693,18 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, TiXmlElement *chunkElem = chunkNode->ToElement(); std::stringstream(chunkElem->Attribute("from")) >> from_offset; std::stringstream(chunkElem->Attribute("to")) >> to_offset; - info.chunk_from.push_back(from_offset); - info.chunk_to.push_back(to_offset); - info.chunk_hash.push_back(chunkElem->GetText()); + chunk_from.push_back(from_offset); + chunk_to.push_back(to_offset); + chunk_hash.push_back(chunkElem->GetText()); chunkNode = fileNode->IterateChildren(chunkNode); } } std::cout << "XML: Parsing finished" << std::endl << std::endl - << info.filename << std::endl - << "\tMD5:\t" << info.hash << std::endl - << "\tChunks:\t" << info.chunks << std::endl - << "\tSize:\t" << info.size << " bytes" << std::endl << std::endl; + << filename << std::endl + << "\tMD5:\t" << filehash << std::endl + << "\tChunks:\t" << chunks << std::endl + << "\tSize:\t" << filesize << " bytes" << std::endl << std::endl; // Check if file exists if ((outfile=fopen(filepath.c_str(), "r"))!=NULL) @@ -735,7 +727,7 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, return res; } - if (offset != info.size) + if (offset != filesize) { std::cout << "Filesizes don't match" << std::endl << "Incomplete download or different version" << std::endl; @@ -762,18 +754,18 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, return res; } - for (int i=0; i