int GetFile(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; int Length=0; // Start by In0 if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); XString RemoteFile((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString LocalFile((CKSTRING) beh->GetInputParameterReadDataPtr(1)); char *Type = "Type_B"; int Get = FtpRecvFile ( RemoteFile.Str(),LocalFile.Str(),*Type, FALSE,NULL,NULL); Length = FtpBytesToBeTransferred(); if ( Get !=0 ){ beh->SetOutputParameterValue(3,&Get); beh->ActivateOutput(2); return CKBR_OK; } beh->SetOutputParameterValue(0,&Length); beh->ActivateOutput(0); return CKBR_ACTIVATENEXTFRAME; } beh->GetOutputParameterValue(0,&Length); int down=FtpBytesTransferred(); beh->SetOutputParameterValue(1,&down); float progress=(float)(down*100.0f/Length); // percentage of file downloaded progress /=100.0f; beh->SetOutputParameterValue(2,&progress); if ( down == Length){ beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
bool KLUPD::IniFile::load() { if(!LocalFile(m_fileName, pLog).exists()) { TRACE_MESSAGE2("File does not exist '%S'", m_fileName.toWideChar()); return false; } // do not create a new file here. If it doesn't exist, just return false and report the failure. FileStream file(pLog); if(!file.open(m_fileName, std::ios::in)) { TRACE_MESSAGE2("Failed to load ini configuration file, because failed to open file '%S'", m_fileName.toWideChar()); return false; } const bool autoKey = (m_flags & AUTOCREATE_KEYS) == AUTOCREATE_KEYS; const bool autoSec = (m_flags & AUTOCREATE_SECTIONS) == AUTOCREATE_SECTIONS; NoCaseString comment; Section *section = getSection(L""); // needs to be set to restore the original values later m_flags |= AUTOCREATE_KEYS | AUTOCREATE_SECTIONS; bool doneWithFile = false; while(!doneWithFile) { NoCaseString line; file.getLine(line); line.trim(); doneWithFile = file.done(); if(line.find_first_of(s_commentIndicators.toWideChar()) == 0) { comment += L"\n"; comment += line; } // new section else if(line.find_first_of("[") == 0) { line.erase(0, 1); const size_t lastOffset = line.find_last_of("]"); if(lastOffset != NoCaseStringImplementation::npos) { line.erase(lastOffset, 1); createSection(line, comment); section = getSection(line); comment = NoCaseString(); } } // we have a key, add this key/value pair else if(!line.empty()) { NoCaseString keyName = getNextWord(line); NoCaseString value = line; if(!keyName.empty()) { setValue(keyName, value, section ? section->m_name : NoCaseString(), comment); comment = NoCaseString(L""); } } } // restore the original flag values. if(!autoKey) m_flags &= ~AUTOCREATE_KEYS; if(!autoSec) m_flags &= ~AUTOCREATE_SECTIONS; return true; }
KLUPD::CoreError KLUPD::UpdateInfo::parse(const Path &path, FileInfo &fileInfo, const ChangeStateCheck &changeStateCheck, const FileVector &localFilesToCheckAgainst, const bool suppressSuccessLogMessages) { // index is already parsed, files already attached if(fileAlreadyParsed(fileInfo)) return CORE_NO_ERROR; const Path fullFileName = path + fileInfo.m_filename; if(!suppressSuccessLogMessages) TRACE_MESSAGE2("Parsing XML index file '%S'", fullFileName.toWideChar()); std::vector<unsigned char> buffer; const CoreError readFileResult = LocalFile(fullFileName, pLog).read(buffer); if(!KLUPD::isSuccess(readFileResult)) { TRACE_MESSAGE3("Failed to read XML index file '%S', result '%S'", fullFileName.toWideChar(), KLUPD::toString(readFileResult).toWideChar()); return readFileResult; } if(buffer.empty()) { TRACE_MESSAGE3("Index XML file '%S' is corrupted, file size is %d", fullFileName.toWideChar(), buffer.size()); return CORE_UPDATE_DESCRIPTION_DAMAGED; } // a file list obtained from XML FileVector fileList; IndexFileXMLParser xmler(fileInfo.m_filename.m_value, fileList, m_signature6Checker, fileInfo.m_relativeURLPath, m_retranslationMode, m_callbacks, pLog); XmlReader xmlReader(reinterpret_cast<const char *>(&buffer[0]), buffer.size()); if(!xmler.parseXMLRecursively(xmlReader, 0) || fileList.empty()) { TRACE_MESSAGE3("\tXML file parse error '%S', file number found %d", fullFileName.toWideChar(), fileList.size()); return CORE_UPDATE_DESCRIPTION_DAMAGED; } m_parsedIndexCache.push_back(fileInfo); xmler.GetUpdateDate(fileInfo.m_strUpdateDate); xmler.GetBlackDate(fileInfo.m_strBlackDate); // save variables to write into settings storage std::vector<UpdatedSettings> updatedSettings = xmler.updatedSettings(); m_updatedSettings.insert(m_updatedSettings.end(), updatedSettings.begin(), updatedSettings.end()); // copy to match list only those items which suits download criteria for(FileVector::iterator fileIter = fileList.begin(); fileIter != fileList.end(); ++fileIter) { // check download filters criteria should be performed NoCaseString reasonNotMatch; if(!matchesSettings(reasonNotMatch, *fileIter)) { if(!suppressSuccessLogMessages) { TRACE_MESSAGE3("\tFile filtered, download criteria does not matches: '%S', %S", reasonNotMatch.toWideChar(), fileIter->toString().toWideChar()); } continue; } // check download mandatory criteria reasonNotMatch.erase(); if(!isEntryRequired(reasonNotMatch, *fileIter, m_filterFlags)) { if(!suppressSuccessLogMessages) { TRACE_MESSAGE3("\tFile filtered, mandatory criteria does not matches: '%S', %S", reasonNotMatch.toWideChar(), fileIter->toString().toWideChar()); } continue; } // setup transaction folders fileIter->m_transactionInformation.m_currentLocation = m_callbacks.productFolder(*fileIter, m_retranslationMode); fileIter->m_transactionInformation.m_newLocation = m_callbacks.temporaryFolder(*fileIter); NoCaseString statusExplanations; fileIter->m_transactionInformation.m_changeStatus = getFileStatusAgainstLocal(*fileIter, changeStateCheck, localFilesToCheckAgainst, statusExplanations); // insert file with filtering duplicates bool fileDuplicate = false; // insert black list into the beginning of list, because it should be checked before downloading other bases if(fileIter->m_type == FileInfo::blackList) m_matchFileList.insertNewInTheBeginOfListOrUpdateTheSame(*fileIter, *fileIter, fileDuplicate, m_retranslationMode); else m_matchFileList.insertNewOrUpdateTheSame(*fileIter, *fileIter, fileDuplicate, m_retranslationMode); if(!suppressSuccessLogMessages) { // to avoid empty brackets output to trace if(!statusExplanations.empty()) statusExplanations = NoCaseString(L"(") + statusExplanations + L")"; if(fileDuplicate) { TRACE_MESSAGE3("\tDuplicate file information updated: %S %S", fileIter->toString().toWideChar(), statusExplanations.toWideChar()); } else { TRACE_MESSAGE3("\tFile matches download criteria: %S %S", fileIter->toString().toWideChar(), statusExplanations.toWideChar()); } } } return CORE_NO_ERROR; }
KLUPD::CoreError KLUPD::AdministrationKitProtocol::getFile( const Path &fileName, const Path &localPath, const Path &relativeUrlPathIn, const bool useMasterAdministrationServer) { #ifdef DISABLE_AK_FILETRANSFER TRACE_MESSAGE("Administration Kit Transport is not implemented"); return CORE_DOWNLOAD_ERROR; #else // skip initial slash in relative URL path Path relativeUrlPath = relativeUrlPathIn; if(!relativeUrlPath.empty() && (relativeUrlPath[0] == L'\\' || relativeUrlPath[0] == L'/')) { relativeUrlPath = relativeUrlPath.toWideChar() + 1; } const Path path = relativeUrlPath + fileName; /////////////////////////////////////////////// /// checking current state and parameters const CoreError connectionResult = setupLowLevelConnectionIfNeed(useMasterAdministrationServer); if(connectionResult != CORE_NO_ERROR) { TRACE_MESSAGE2("Failed to setup connection to Administration Server, result '%S'", toString(connectionResult).toWideChar()); return connectionResult; } /////////////////////////////////////////////// /// receiving data by portions size_t regettingPosition = LocalFile(localPath + fileName).size(); AutoStream destinationFile(pLog); while(true) { // check if request should be cancelled if(m_downloadProgress.checkCancel()) { TRACE_MESSAGE2("File transfer cancelled '%S'", path.toWideChar()); return CORE_CANCELLED; } const long localBufferSize = 65536; std::vector<unsigned char> localBuffer(localBufferSize, 0); int bytesRead = 0; m_downloadProgress.updateSpeedStartTimer(); const KLFT::FileOpeartionResult getChunkResult = m_adminKitTransprot->GetFileChunk( path.toWideChar(), regettingPosition, &localBuffer[0], localBuffer.size(), bytesRead); m_downloadProgress.updateSpeedStopTimer(); // a portion of file got successfully if(getChunkResult == KLFT::FR_Ok || getChunkResult == KLFT::FR_OkDownloaded) { const CoreError saveDataToFileResult = saveDataToFile( localPath + fileName, &localBuffer[0], bytesRead, regettingPosition != 0, destinationFile, pLog); if(!isSuccess(saveDataToFileResult)) { TRACE_MESSAGE3("Failed to write data obtained from Administration Server to file '%S', result '%S'", path.toWideChar(), toString(saveDataToFileResult).toWideChar()); return saveDataToFileResult; } regettingPosition += bytesRead; m_downloadProgress.bytesTransferred(bytesRead); // file has been completely downloaded if(getChunkResult == KLFT::FR_OkDownloaded) return CORE_NO_ERROR; continue; } TRACE_MESSAGE5("Failed to obtain file chunk from Administration Server, file '%S', result '%s', bytes read %d, current position %d", path.toWideChar(), toString(getChunkResult).c_str(), bytesRead, regettingPosition); if(getChunkResult == KLFT::FR_Timeout) { // TODO check if time out is over and error should be returned continue; } // error while download happened switch(getChunkResult) { // invalid AdminKit Transport identifier: either receiver was deleted or connect was already called for this receiver case KLFT::FR_WrongReceiverId: return CORE_AK_WrongReceiverId; // invalid arguments for AdminKit Transport // wrong offset is requested, consider file is downloaded and signature should be checked case KLFT::FR_WrongArguments: { // TODO: this is *work around* about the problem that AdminKit returns return CORE_NO_ERROR; // FR_WrongArguments code in case source contains // valid file in target download folder // this code can be deleted when problem is fixed in AdminKit } // file not found on AdminKit server case KLFT::FR_FileNotFound: return CORE_NO_SOURCE_FILE; // AdminKit transport file receive error case KLFT::FR_ErrorInOperation: return CORE_AK_ErrorInOperation; // unknown AdminKit transport receive operation error default: return CORE_AK_UnknownError; } } #endif // DISABLE_AK_FILETRANSFER }