public void Load(string file)
{
try {
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) {
FileHeader header = ReadFileHeader(fs);
if (header.m_Identity == c_Identity && header.m_Version == c_Version) {
Reset();
for (int i = 0; i < header.m_RecordNum && fs.Position < fs.Length; ++i) {
byte[] bytes = new byte[header.m_RecordSize];
fs.Read(bytes, 0, header.m_RecordSize);
m_Records.Add(bytes);
}
if (m_Records.Count > 0) {
fs.Position = header.m_StringOffset;
m_StringList = new List<string>(ReadStrArray(fs));
fs.Position = header.m_IntListOffset;
m_IntLists = new List<int>(ReadIntArray(fs));
fs.Position = header.m_FloatListOffset;
m_FloatLists = new List<float>(ReadFloatArray(fs));
fs.Position = header.m_StrListOffset;
m_StrLists = new List<int>(ReadIntArray(fs));
Update();
bool haveError = false;
int recordSize = m_Records[0].Length;
int recordNum = m_Records.Count;
for (int i = 1; i < recordNum; ++i) {
if (m_Records[i].Length != recordSize) {
LogSystem.Error("Record Size not equal, {0}!={1}({2})", recordSize, m_Records[i].Length, i);
haveError = true;
}
}
if (haveError) {
Reset();
}
}
} else {
LogSystem.Error("Unknown binary file tag {0} or error version {1}", header.m_Identity, header.m_Version);
}
fs.Close();
}
} catch (Exception ex) {
LogSystem.Error("Exception:{0}\n{1}", ex.Message, ex.StackTrace);
}
}