using system; using system.collections.generic; using system.linq; using system.text; using system.io; namespace khaledmohamed.database { public class read : Idisposable { private string location = ""; private streamreader sr; public int count = 0; private string[] items; private int32 curent_count = -1; public read(string file) { location = file; } public void dispose() { location = string.empty; sr = null; items = null; count = 0; } public string[] outbase() { return items; } public uint acount; public bool useread() { acount++; return items.length >= acount; } public bool reader(bool useinvalid = true) { string[] data = null; if (file.exists(location)) { try { using (sr = file.opentext(location)) { count = int.parse(sr.readline().split('=')[1]); data = new string[count]; for (int x = 0; x < count; x++) { data[x] = sr.readline(); } if (count == 0) return false; } } catch (exception e) { console.writeline(e.tostring()); return false; } } else if (useinvalid) { data = null; console.writeline("invalid reader " + location + " location"); return false; } items = new string[count]; for (int x = 0; x < count; x++) { items[x] = data[x]; } return true; } public uint32 readuint32(uint32 add_def) { curent_count += 1; if (curent_count < count) { if (items[curent_count] == null) return add_def; else return uint32.parse(items[curent_count]); } else return add_def; } public uint16 readuint16(uint16 add_def) { curent_count += 1; if (curent_count < count) { if (items[curent_count] == null) return add_def; else return uint16.parse(items[curent_count]); } else return add_def; } public uint64 readuint64(uint64 add_def) { curent_count += 1; if (curent_count < count) { if (items[curent_count] == null) return add_def; else return uint64.parse(items[curent_count]); } else return add_def; } public byte readbyte(byte add_def) { curent_count += 1; if (curent_count < count) { if (items[curent_count] == null) return add_def; else return byte.parse(items[curent_count]); } else return add_def; } public string readstring(string add_def) { curent_count += 1; if (curent_count < count) { if (items[curent_count] == null) return add_def; else return items[curent_count]; } else return add_def; } } }