예제 #1
0
bool applyPatch(const NLMISC::CSString& patchFile,const NLMISC::CSString& srcFile,const NLMISC::CSString& destFile)
{
	nlinfo("APPLY PATCH: %s to file %s => %s",patchFile.c_str(),srcFile.c_str(),destFile.c_str());
	NLMISC::CSString cmd= "xdelta patch "+patchFile+" "+srcFile+" "+destFile;
	bool ok= system(cmd.c_str())==0;
	return ok;
}
예제 #2
0
bool CStateManager::beginState(const NLMISC::CSString& stateName)
{
	// make sure the state is valid
	if (_ValidStates.find(stateName.strip())==_ValidStates.end())
	{
		nlwarning("Cannot start state as it is not in valid state list: %s",stateName.c_str());
		return false;
	}

	// make sure the state isn't already active
	for (uint32 i=0;i<_States.size();++i)
	{
		if (_States[i]==stateName)
		{
			nlwarning("Cannot start state as it is already active: %s",stateName.c_str());
			return false;
		}
	}

	// set the state as active
	_States.push_back(stateName);

	// write the states to a file
	NLMISC::CSString stateTxt;
	stateTxt.join(_States,"\n");
	stateTxt.writeToFile(StateFileName);

	// execute the begin_state script
	CScriptManager::getInstance()->runScript("begin_"+stateName);

	return true;
}
예제 #3
0
bool applyFirstPatch(const NLMISC::CSString& patchFile,const NLMISC::CSString& destFile)
{
	nlinfo("APPLY FIRST PATCH: %s => %s",patchFile.c_str(),destFile.c_str());
	NLMISC::CSString cmd= "xdelta patch "+patchFile+" /dev/null "+destFile;
	bool ok= system(cmd.c_str())==0;
	return ok;
}
예제 #4
0
bool CStateManager::endState(const NLMISC::CSString& stateName)
{
	uint32 i;

	// make sure the state is already active
	for (i=0;i<_States.size();++i)
	{
		if (_States[i]==stateName)
		{
			break;
		}
	}
	if (i==_States.size())
	{
		nlwarning("Cannot end state as it is not already active: %s",stateName.c_str());
		return false;
	}

	// set the state as inactive
	_States.erase(_States.begin()+i);

	// write the states to a file
	NLMISC::CSString stateTxt;
	stateTxt.join(_States,"\n");
	stateTxt.writeToFile(StateFileName);

	// execute the end_state script
	CScriptManager::getInstance()->runScript("end_"+stateName);

	return true;
}
예제 #5
0
void CStateManager::addValidState(const NLMISC::CSString& stateName)
{
	if (stateName.countWords()!=1)
	{
		nlwarning("Invalid state name: %s",stateName.c_str());
		return;
	}
	_ValidStates.insert(stateName.strip());
}
예제 #6
0
	void CFileReceiver::_downloadLog(const NLMISC::CSString& fileName,uint32 bytesSoFar, uint32 bytesExpected) const
	{
		const CAdministeredModuleBase* adminModule= dynamic_cast<const CAdministeredModuleBase*>(_Parent);
		if (adminModule!=NULL)
		{
			adminModule->setStateVariable(fileName,NLMISC::toString("%d/%d",bytesSoFar,bytesExpected));
		}
		else
		{
			nldebug("CFileReceiver_Download: %s: %d/%d",fileName.c_str(),bytesSoFar,bytesExpected);
		}
	}
예제 #7
0
	void CFileReceiver::_logError(const NLMISC::CSString& msg) const
	{
		const CAdministeredModuleBase* adminModule= dynamic_cast<const CAdministeredModuleBase*>(_Parent);
		if (adminModule!=NULL)
		{
			adminModule->registerError(msg);
		}
		else
		{
			nlwarning("CFileReceiver: %s",msg.c_str());
		}
	}
예제 #8
0
	void CFileReceiver::_log(const NLMISC::CSString& msg) const
	{
		const CAdministeredModuleBase* adminModule= dynamic_cast<const CAdministeredModuleBase*>(_Parent);
		if (adminModule!=NULL)
		{
			adminModule->registerProgress(msg);
		}
		else
		{
			nldebug("CFileReceiver_%s",msg.c_str());
		}
	}
예제 #9
0
bool untar(const NLMISC::CSString& destFile)
{
	bool ok;
	nlinfo("SPA UNPACK TAR BALL: %s",destFile.c_str());

	NLMISC::CSString oldPath= NLMISC::CPath::getCurrentPath();
	NLMISC::CSString newPath= NLMISC::CFile::getPath(destFile);

	ok= NLMISC::CPath::setCurrentPath(newPath.c_str());
	DROP_IF(!ok,"Patching error - failed to change directory to: "+newPath,return false);

	NLMISC::CSString cmd;
	cmd+= "tar xzfv "+NLMISC::CFile::getFilename(destFile);
	nldebug("- system: %s",cmd.c_str());
	ok= system(cmd.c_str())==0;

	ok= NLMISC::CPath::setCurrentPath(oldPath.c_str());
	DROP_IF(!ok,"Patching error - failed to change directory to: "+oldPath,return false);

	return ok;
}
예제 #10
0
파일: scenario.cpp 프로젝트: mixxit/solinia
bool CUserComponentValidator::setUserComponentToSave(const std::string& filename, const CUserComponentValidator::TValues& values, std::string& headerMD5, const std::string &body)
{
    _Filename = filename;
//	std::ostringstream out2;
//	out2.str(body);

//	_UserComponentBody =out2.str();

    _UserComponentBody = body;

    {
        NLMISC::CHashKeyMD5 md5Id = NLMISC::getMD5((uint8*)_UserComponentBody.data(), (uint32)_UserComponentBody.size());
        _BodyMd5 = md5Id.toString().c_str();
    }

//	out2.str("");
//	out2 << NLMISC::toString("-- BodyMD5 = '%s'\n", _BodyMd5.c_str() );
//	TValues::const_iterator first(values.begin()), last(values.end());
//	for (; first != last; ++first)
//	{
    //>first->second.c_str()) "\n" => "\\n"
//		NLMISC::CSString tmp = first->second.c_str();
//		tmp = tmp.replace("\n", "\\n");

//		out2 << NLMISC::toString("-- %s = '%s'\n", first->first.c_str(), tmp.c_str());
//	}


//	_HeaderBody =out2.str();


    _HeaderBody = NLMISC::toString("-- BodyMD5 = '%s'\n", _BodyMd5.c_str() );

    TValues::const_iterator first(values.begin()), last(values.end());
    for (; first != last; ++first)
    {
        //>first->second.c_str()) "\n" => "\\n"
        NLMISC::CSString tmp = first->second.c_str();
        tmp = tmp.replace("\n", "\\n");

        _HeaderBody += NLMISC::toString("-- %s = '%s'\n", first->first.c_str(), tmp.c_str());
    }


    std::string headerBodyMd5;
    {
        NLMISC::CHashKeyMD5 md5Id = NLMISC::getMD5((uint8*)_HeaderBody.data(), (uint32)_HeaderBody.size());
        _HeaderMd5 = md5Id.toString().c_str();
        headerMD5 = _HeaderMd5;
    }

    return true;
}
예제 #11
0
파일: scenario.cpp 프로젝트: mixxit/solinia
bool CScenarioValidator::setScenarioToSave(const std::string& filename, CObject* scenario, const CScenarioValidator::TValues& values, std::string& headerMD5)
{
    _Filename = filename;
    //std::ostringstream out2;
    //out2.str("");
    std::string out2;

    if (!scenario)
    {
        return false;
    }

    //out2 <<"scenario = "<< *scenario ;
    out2 += "scenario = ";
    scenario->serialize(out2);

    _ScenarioBody = out2;
    {
        NLMISC::CHashKeyMD5 md5Id = NLMISC::getMD5((uint8*)_ScenarioBody.data(),(uint32) _ScenarioBody.size());
        _BodyMd5 = md5Id.toString().c_str();
    }


    out2.clear();
    //out2.str("");
    out2 += NLMISC::toString("-- BodyMD5 = '%s'\n", _BodyMd5.c_str() );
    TValues::const_iterator first(values.begin()), last(values.end());
    for (; first != last; ++first)
    {
        //>first->second.c_str()) "\n" => "\\n"
        NLMISC::CSString tmp = first->second.c_str();
        tmp = tmp.replace("\n", "\\n");

        out2 += NLMISC::toString("-- %s = '%s'\n", first->first.c_str(), tmp.c_str());
    }

    _HeaderBody =out2;
    std::string headerBodyMd5;
    {
        NLMISC::CHashKeyMD5 md5Id = NLMISC::getMD5((uint8*)_HeaderBody.data(), (uint32)_HeaderBody.size());
        _HeaderMd5 = md5Id.toString().c_str();
        headerMD5 = _HeaderMd5;
    }
    return true;
}
예제 #12
0
CHashKeyMD5 safeGetMD5(const NLMISC::CSString& fileName)
{
	while (true)
	{
		try
		{
			CHashKeyMD5 result= NLMISC::getMD5(fileName);
			return result;
		}
		catch(...)
		{
			nlwarning("Exception thrown in getMD5(\"%s\") ... will try again in a few seconds",fileName.c_str());
			nlSleep(3);
		}
	}
}