public bool ReadOldFiltersFromDisk(string strFileName) { bool bSuccess = true; if (!File.Exists(strFileName)) { return(false); } FileStream fs = File.Open(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read); String str = string.Empty, dev = string.Empty; int len = 0, count = 0; char c = char.MinValue; //Opening bracket c = (char)fs.ReadByte(); if (c != '[') { bSuccess = false; goto EXIT; } //Read filer name - "ScfilterList" str = AdvFilterUtilities.ReadString(fs, false, false); if (string.Compare(AdvFilterUtilities.FilterName, str) != 0) { bSuccess = false; goto EXIT; } //Read version dev = AdvFilterUtilities.ReadString(fs, false, false); if (string.Compare(dev, AdvFilterUtilities.FilterRev02) < 0) { bSuccess = false; goto EXIT; } //Read filters ScAFilter aFilter = null; ScFilterElement anElement = null; count = AdvFilterUtilities.ReadShort(fs); for (int i = 0; i < count; i++) { aFilter = new ScAFilter(); aFilter.Name = AdvFilterUtilities.ReadString(fs, false, false); //filter name aFilter.ReportScType = fs.ReadByte(); //type //10--Efficiency fs.Position++; if (string.Compare(dev, AdvFilterUtilities.FilterRev03) < 0) //Scouting filter Ver.3 have play after feature { aFilter.PlayAfter = 0; } else { aFilter.PlayAfter = fs.ReadByte(); fs.Position++; } len = fs.ReadByte(); //count of elements fs.Position++; for (int j = 0; j < len; j++) { anElement = new ScFilterElement(); anElement.Type = fs.ReadByte(); //element's type fs.Position += 3; anElement.Field = AdvFilterUtilities.ReadString(fs, false, false); //element's field fs.Position += 2; anElement.Value = AdvFilterUtilities.ReadString(fs, false, false); //element's value anElement.Oper = fs.ReadByte(); //element's oper fs.Position++; anElement.Opr = fs.ReadByte(); //element's opr fs.Position++; aFilter.Elements.Add(anElement); } this.ScFilters.Add(aFilter); } EXIT: { fs.Close(); return(bSuccess); } }
public bool ReadFromDisk(string strFileName) { bool bSuccess = true; if (!File.Exists(strFileName)) { return(false); } FileStream fs = File.Open(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read); String str = string.Empty; int len = 0, count = 0; //read version str = AdvFilterUtilities.ReadString(fs, true, true); if (String.Compare(str, AdvFilterUtilities.FilterRev01) > 0) //check filter list version { fs.Close(); bSuccess = false; goto EXIT; } // //read count of filters count = AdvFilterUtilities.ReadShort(fs); //read filters ScAFilter aFilter = null; ScFilterElement anElement = null; for (int i = 0; i < count; i++) { aFilter = new ScAFilter(); aFilter.Name = AdvFilterUtilities.ReadString(fs, true, true); len = AdvFilterUtilities.ReadInt32(fs); for (int j = 0; j < len; j++) { aFilter.Types.Add(AdvFilterUtilities.ReadString(fs, true, true)); } len = AdvFilterUtilities.ReadInt32(fs); for (int j = 0; j < len; j++) { anElement = new ScFilterElement(); anElement.Field = AdvFilterUtilities.ReadString(fs, true, true); anElement.Value = AdvFilterUtilities.ReadString(fs, true, true); anElement.Oper = AdvFilterUtilities.ReadInt32(fs); anElement.Opr = AdvFilterUtilities.ReadInt32(fs); aFilter.Elements.Add(anElement); } this.ScFilters.Add(aFilter); } EXIT: { fs.Close(); return(bSuccess); } }