CfgList* CfgValue::LoadFile (std::string name) { InputBuffer buf; FILE *f = fopen (name.c_str(), "rb"); if (!f) throw ContentException(SPrintf("Failed to open file %s\n", name.c_str())); fseek (f, 0, SEEK_END); buf.len = ftell(f); buf.data = new char [buf.len]; fseek (f, 0, SEEK_SET); if (!fread (buf.data, buf.len, 1, f)) { fclose (f); delete[] buf.data; throw ContentException(SPrintf("Failed to read file %s\n", name.c_str())); } buf.filename = name.c_str(); fclose (f); CfgList *nlist = new CfgList; try { nlist->Parse (buf, true); } catch (const ContentException &e) { delete[] buf.data; delete nlist; throw e; } delete[] buf.data; return nlist; }
CfgList* CfgValue::LoadFile (const char *name) { InputBuffer buf; FILE *f = fopen (name, "rb"); if (!f) { logger.Trace (NL_Debug, "Failed to open file %s\n", name); return 0; } fseek (f, 0, SEEK_END); buf.len = ftell(f); buf.data = new char [buf.len]; fseek (f, 0, SEEK_SET); if (!fread (buf.data, buf.len, 1, f)) { logger.Trace (NL_Debug, "Failed to read file %s\n", name); fclose (f); delete[] buf.data; return 0; } buf.filename = name; fclose (f); CfgList *nlist = new CfgList; if (!nlist->Parse (buf,true)) { delete nlist; delete[] buf.data; return 0; } delete[] buf.data; return nlist; }