コード例 #1
0
ファイル: FileCache.cpp プロジェクト: Smallthing/blitzd
	FileCacheItem::Pointer FileCacheItem::Load( std::string n )
	{
		Utils::FileStream fs;
		if(!fs.Open(n))
		{
			LOG_ERROR(("Cannot load file: %s", n.c_str()));
			return FileCacheItem::Pointer();
		}
		FileCacheItem::Pointer ptr(new FileCacheItem(fs));
		fs.Close();
#ifdef _WIN32
		HANDLE hFile = CreateFileA(n.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
			OPEN_EXISTING, 0, NULL);
		if(hFile != INVALID_HANDLE_VALUE && hFile != NULL)
		{
			FILETIME ft;
			::GetFileTime(hFile, NULL, NULL, &ft);
			ptr->_ft = (uint64)ft.dwLowDateTime + ((uint64)ft.dwHighDateTime << 32);
			CloseHandle(hFile);
		}
		else
			ptr->_ft = 0;
#else
		struct stat st;
		if(stat(n.c_str(), &st) == 0)
			ptr->_ft = Utils::Timestamp::fromEpochTime(st.st_mtime).fileTime();
		else
			ptr->_ft = 0;
#endif
		return ptr;
	}
コード例 #2
0
 /*! \brief load and initialize the iterator with fi */
 inline void LoadBinary(utils::FileStream &fi,
                        bool silent,
                        const char *fname_) {
   this->set_cache_file(fname_);
   std::string fname = fname_;
   int tmagic;
   utils::Check(fi.Read(&tmagic, sizeof(tmagic)) != 0, "invalid input file format");
   this->CheckMagic(tmagic);
   this->info.LoadBinary(fi);
   // load in the row data file
   fname += ".row.blob";
   utils::FileStream fs(utils::FopenCheck(fname.c_str(), "rb"));
   iter_->Load(fs);
   if (!silent) {
     utils::Printf("DMatrixPage: %lux%lu matrix is loaded",
                   static_cast<unsigned long>(info.num_row()),
                   static_cast<unsigned long>(info.num_col()));
     if (fname_ != NULL) {
       utils::Printf(" from %s\n", fname_);
     } else {
       utils::Printf("\n");
     }
     if (info.group_ptr.size() != 0) {
       utils::Printf("data contains %u groups\n", (unsigned)info.group_ptr.size() - 1);
     }
   }
 }
コード例 #3
0
ファイル: XmlNode.cpp プロジェクト: Smallthing/blitzd
	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;
	}
コード例 #4
0
ファイル: NewsCache.cpp プロジェクト: Smallthing/blitzd
	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;
		}
	}
コード例 #5
0
ファイル: FileCache.cpp プロジェクト: Smallthing/blitzd
	FileCacheItem::FileCacheItem( Utils::FileStream& fs )
	{
		uint size = (uint)fs.Size();
		_data.append_zero(size);
		fs.Read(&_data[0], size);
	}