public static void Add(BibtexRecordType record) { records.Add(record); }
public static void Load() { records = new ArrayList(); StreamReader stream = null; while (true) { try { stream = new StreamReader(Filename); if (stream == null) { Debug.WriteLine(1, "Argh, couldn't open the file!"); } break; } catch (DirectoryNotFoundException e) { Debug.WriteLine(10, e.Message); Debug.WriteLine(1, "Directory {0} not found! Creating it...", Path.GetDirectoryName(Filename)); Directory.CreateDirectory(Path.GetDirectoryName(Filename)); } catch (FileNotFoundException e) { Debug.WriteLine(10, e.Message); Debug.WriteLine(1, "File {0} not found! Instantiating it...", Filename); Stream recStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("bibtex_records"); var outRecStream = new FileStream(Filename, FileMode.CreateNew); var data = new byte[recStream.Length]; recStream.Read(data, 0, (int)recStream.Length); recStream.Close(); outRecStream.Write(data, 0, data.Length); outRecStream.Close(); } } if (stream != null) { while (true) { string recordName = stream.ReadLine(); if (recordName == null) { // end of file break; } string description = stream.ReadLine(); if (description == null) { break; } string spec = stream.ReadLine(); if (spec == null) { break; } string temp = stream.ReadLine(); if (temp == null) { break; } string[] fields = temp.Split(','); temp = stream.ReadLine(); if (temp == null) { break; } string[] required = temp.Split(','); stream.ReadLine(); // blank line between records var record = new BibtexRecordType(); record.name = recordName; record.description = description; record.spec = (Convert.ToInt32(spec) == 1); var sarray = new StringArrayList(); for (int i = 0; i < fields.Length; i++) { sarray.Add(fields [i]); } record.fields = sarray; var iarray = new IntArrayList(); for (int i = 0; i < required.Length; i++) { iarray.Add(Convert.ToInt32(required [i])); } record.optional = iarray; records.Add(record); Debug.WriteLine(5, "Read in info for record '" + recordName + "'"); } stream.Close(); } }