Exemplo n.º 1
0
	void NewsCache::Load()
	{
		Utils::FileStream fs;
		fs.Open(Core::cfg.GetCfgDir() + '/' + Core::cfg.GetMotdFile());
		uint size = (uint)fs.Size();
		_motd.resize(size);
		fs.Read(&_motd[0], size);
		fs.Close();
		LOG_DEBUG(("Loaded motd: %s", _motd.c_str()));

		std::string content;
		fs.Open(Core::cfg.GetCfgDir() + '/' + Core::cfg.GetNewsFile());
		size = (uint)fs.Size();
		content.resize(size);
		fs.Read(&content[0], size);

		uint i = 0;
		while(i + 1 < content.length() && (content[i] != '{' || content[i + 1] != '{'))
			++ i;
		if(i + 1 < content.length())
			i += 2;
		while(i + 1< content.length())
		{
			uint start = i;
			while(i + 1 < content.length() && (content[i] != '}' || content[i + 1] != '}'))
				++ i;
			if(i + 1 >= content.length())
				break;
			std::string date(content.begin() + start, content.begin() + i);
			i += 2;
			while(i < content.length() && (content[i] == '\r' || content[i] == '\n'))
				++ i;
			if(i >= content.length())
				break;
			start = i;
			while(i + 1 < content.length() && (content[i] != '{' || content[i + 1] != '{'))
				++ i;
			uint end = i;
			while(end > start && (content[end - 1] == '\r' || content[end - 1] == '\n'))
				-- end;
			Add(date, std::string(content.begin() + start, content.begin() + end));
			if(i + 1 < content.length())
				i += 2;
			else
				break;
		}
	}
Exemplo n.º 2
0
	XmlNode::XmlNode( const char * filename )
	{
		_parent = NULL;
		_data = NULL;
		Utils::FileStream fs;
		if(!fs.Open(filename))
			return;
		uint size = (uint)fs.Size();
		if(size == 0)
			return;
		std::string buf;
		buf.resize(size);
		fs.Read(&buf[0], size);
		fs.Close();
		mxml_node_t * root = mxmlLoadString(NULL, &buf[0], NULL);
		_data = root;
	}
Exemplo n.º 3
0
	FileCacheItem::FileCacheItem( Utils::FileStream& fs )
	{
		uint size = (uint)fs.Size();
		_data.append_zero(size);
		fs.Read(&_data[0], size);
	}