public LoadMapEntry AddEntry(string name, int start, int end, ulong[] microcodeRAM) { if (end <= start || start > microcodeRAM.Length || end > microcodeRAM.Length) { throw new InvalidOperationException("Invalid start/end parameters."); } // // Ensure no duplicate entries (by name, anyway...) // foreach (LoadMapEntry e in _mapEntries) { if (e.Name.ToLowerInvariant() == name.ToLowerInvariant()) { throw new InvalidOperationException("Duplicate map entry name."); } } // Generate a map name string mapName = name + "_map.txt"; // If the map file doesn't exist, create it now. // calculate the MD5 hash byte[] hash = ComputeHash(start, end, microcodeRAM); LoadMapEntry newEntry = new LoadMapEntry(name, mapName, start, end, hash); _mapEntries.Add(newEntry); return(newEntry); }
public void Load(string path) { using (StreamReader sr = new StreamReader(path)) { _mapEntries.Clear(); // // See "Save" for the format we're dealing with here. // while (!sr.EndOfStream) { string line = sr.ReadLine(); if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) { continue; } string[] tokens = line.Split(','); string hashString = tokens[4].Trim(); byte[] hash = new byte[hashString.Length / 2]; for (int i = 0; i < hashString.Length; i += 2) { hash[i / 2] = Convert.ToByte(hashString.Substring(i, 2), 16); } LoadMapEntry e = new LoadMapEntry( tokens[0], // name tokens[1], // mapname Convert.ToInt32(tokens[2].Trim(), 16), // start Convert.ToInt32(tokens[3].Trim(), 16), // end hash); _mapEntries.Add(e); } } }