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; }
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; } }
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; }