Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct CInformation {
- public string Username;
- public string Password;
- public string Server;
- }
- const int EOF = -1;
- const int CR = (int)'\r';
- const int LF = (int)'\n';
- public void ReadConfiguration(string path) {
- if (configurations != null)
- {
- //Clear the memory
- configurations.Clear();
- GC.Collect();
- }
- configurations = new List<CInformation>();
- if(File.Exists(path)){
- FileStream str = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
- int b=0;
- string aux = "";
- while ((b = str.ReadByte()) != EOF) {
- if (b == CR) // Windows style files(CRLF)
- continue;
- if (b == LF)// IF line end
- {
- string[] _info = aux.Split(';');
- if (_info.Length > 2) // Check if line is well formed
- {
- CInformation info = new CInformation();
- info.Username = _info[0];
- info.Password = _info[1];
- info.Server = _info[2];
- configurations.Add(info);
- }
- aux = "";
- }
- else
- aux+=((char)b).ToString();
- }
- //If any line remains
- if (aux.Length > 0)
- {
- string[] last = aux.Split(';');
- if (last.Length > 2) // Check if line is well formed
- {
- CInformation info = new CInformation();
- info.Username = last[0];
- info.Password = last[1];
- info.Server = last[2];
- configurations.Add(info);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement