void MCF::dlFilesFromHttp(const char* url, const char* installDir) { assert(!m_pTHandle); if (m_bStopped) return; if (!url) throw gcException(ERR_BADURL); //save the header first incase we fail saveMCF_Header(); MCFCore::Thread::HGTController *temp = new MCFCore::Thread::HGTController(url, this, installDir); temp->onProgressEvent +=delegate(&onProgressEvent); temp->onErrorEvent += delegate(&onErrorEvent); m_pTHandle = temp; try { m_pTHandle->start(); m_pTHandle->join(); safe_delete(m_pTHandle); } catch (gcException &) { safe_delete(m_pTHandle); throw; } saveMCF_Header(); }
bool MCF::fixMD5AndCRC() { gcString empty("d41d8cd98f00b204e9800998ecf8427e"); bool fixed = false; UTIL::FS::FileHandle handle; getReadHandle(handle); for (size_t x=0; x<m_pFileList.size(); x++) { if (m_pFileList[x]->isSaved() == false) continue; if (m_pFileList[x]->isCompressed() && empty == m_pFileList[x]->getCCsum()) { fixed = true; m_pFileList[x]->generateMD5(handle); } fixed = true; m_pFileList[x]->generateCRC(handle); } handle.close(); if (fixed) { saveMCF_Header(); return true; } return false; }
void MCF::saveMCFHeader() { if (m_bStopped) return; UTIL::FS::recMakeFolder(UTIL::FS::PathWithFile(m_szFile)); saveMCF_Header(); }
void MCF::dlFilesFromWeb( ) { assert(!m_pTHandle); if (m_bStopped) return; if (m_vProviderList.size() == 0) throw gcException(ERR_NOFILE); bool mcfExists = UTIL::FS::isValidFile(UTIL::FS::PathWithFile(getFile())); //save the header first incase we fail saveMCF_Header(); uint16 workerCount = (uint16)m_vProviderList.size(); if (workerCount > 3) workerCount = 3; MCFCore::Thread::WGTController *temp = new MCFCore::Thread::WGTController(m_vProviderList, workerCount, this, mcfExists); temp->onProgressEvent += delegate(&onProgressEvent); temp->onErrorEvent += delegate(&onErrorEvent); temp->onProviderEvent += delegate(&onProviderEvent); m_mThreadMutex.lock(); m_pTHandle = temp; m_mThreadMutex.unlock(); if (m_bStopped) return; try { m_pTHandle->start(); m_pTHandle->join(); safe_delete(m_pTHandle); } catch (gcException &) { safe_delete(m_pTHandle); throw; } saveMCF_Header(); }
void MCF::dlFilesFromHttp(const char* url, const char* installDir) { gcTrace("Url: {0}, Dir: {1}", url, installDir); gcAssert(!m_pTHandle); if (m_bStopped) return; if (!url) throw gcException(ERR_BADURL); //save the header first incase we fail saveMCF_Header(); MCFCore::Thread::HGTController *temp = new MCFCore::Thread::HGTController(url, this, installDir); temp->onProgressEvent +=delegate(&onProgressEvent); temp->onErrorEvent += delegate(&onErrorEvent); runThread(temp); saveMCF_Header(); }
void MCF::makeCRC() { printf("Making crc's\n"); UTIL::FS::FileHandle hFile; getReadHandle(hFile); for (size_t x=0; x<m_pFileList.size(); x++) { if (!m_pFileList[x] || !m_pFileList[x]->isSaved()) continue; m_pFileList[x]->generateCRC(hFile); } hFile.close(); saveMCF_Header(); }
void MCF::saveBlankMcf() { std::vector<size_t> saved; for (size_t x=0; x<m_pFileList.size(); x++) { if (m_pFileList[x]->isSaved()) { saved.push_back(x); m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_SAVE); } } saveMCF_Header(); for (size_t x=0; x<saved.size(); x++) { m_pFileList[saved[x]]->addFlag(MCFCore::MCFFileI::FLAG_SAVE); } }
void MCF::dlHeaderFromWeb() { if (m_bStopped) return; if (m_vProviderList.size() == 0) throw gcException(ERR_ZEROFILE); gcException lastE; bool successful = false; OutBuffer out(MCF_HEADERSIZE_V2); MCFCore::Misc::MCFServerCon msc; for (size_t x=0; x<m_vProviderList.size(); x++) { try { msc.disconnect(); msc.connect(m_vProviderList[x]->getUrl(), m_pFileAuth); msc.downloadRange(0, 5, &out); //4 id bytes and 1 version byte if (out.m_uiTotalSize != 5) throw gcException(ERR_BADHEADER, "Did not get any data from mcf server."); const char* data = out.m_szBuffer; if ( !(data[0] == 'L' && data[1] == 'M' && data[2] == 'C' && data[3] == 'F') ) throw gcException(ERR_BADHEADER, "Failed magic check."); size_t headerSize = MCF_HEADERSIZE_V1; if (data[4] == 0x01) headerSize = MCF_HEADERSIZE_V1; else if (data[4] == 0x02) headerSize = MCF_HEADERSIZE_V2; else throw gcException(ERR_BADHEADER, "Bad version number"); out.reset(); msc.downloadRange(0, headerSize, &out); if (out.m_uiTotalSize != headerSize) throw gcException(ERR_BADHEADER, "Did not get correct ammount of data from server."); MCFCore::MCFHeader webHeader((uint8*)out.m_szBuffer); if (!webHeader.isValid()) throw gcException(ERR_BADHEADER, "Mcf header was not valid."); uint32 ths = webHeader.getXmlSize(); out = ths; msc.downloadRange(webHeader.getXmlStart(), webHeader.getXmlSize(), &out); if (out.m_uiTotalSize == 0 || out.m_uiTotalSize != webHeader.getXmlSize()) throw gcException(ERR_WEBDL_FAILED, "Failed to download MCF xml from web (size is ether zero or didnt match header size)"); data = out.m_szBuffer; if (data[0] == 'L' && data[1] == 'M' && data[2] == 'C' && data[3] == 'F') throw gcException(ERR_WEBDL_FAILED, "Server failed 4gb seek."); setHeader(&webHeader); successful = true; break; } catch (gcException &e) { lastE = e; Warning(gcString("Failed to download MCF Header from {1}: {0}\n", e, m_vProviderList[x]->getUrl())); } } if (!successful) throw lastE; uint32 bz2BuffLen = getHeader()->getXmlSize()*25; char* bz2Buff = NULL; if ( isCompressed() ) { bz2Buff = new char[bz2BuffLen]; UTIL::STRING::zeroBuffer(bz2Buff, bz2BuffLen); try { UTIL::BZIP::BZ2DBuff((char*)bz2Buff, &bz2BuffLen, out.m_szBuffer, out.m_uiTotalSize); parseXml(bz2Buff, bz2BuffLen); safe_delete(bz2Buff); } catch (gcException &) { safe_delete(bz2Buff); throw; } } else { parseXml(out.m_szBuffer, out.m_uiTotalSize); } //we remove the complete flag due to the files not existing in the MCF for (size_t x=0; x< m_pFileList.size(); x++) { m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE); } if (m_szFile != "") saveMCF_Header(); }