-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mappings.cs
36 lines (32 loc) · 882 Bytes
/
Mappings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Spectre.Console;
namespace AppCompare;
static class Mappings {
public static Dictionary<string, string> ReadFromFile (string mappingFile, out int result)
{
Dictionary<string, string> dict = new ();
result = 1;
var lineno = 0;
try {
foreach (var line in File.ReadLines (mappingFile)) {
lineno++;
if (line [0] == '#')
continue;
var eq = line.IndexOf ('=');
if (eq == -1) {
AnsiConsole.MarkupLine ($"[red]Error line {lineno}:[/] Missing `=` in a non-comment (`#`) line mapping.");
return dict;
}
var file_b = line [(eq + 1)..];
if (dict.ContainsKey (file_b)) {
AnsiConsole.MarkupLine ($"[red]Error line {lineno}:[/] Duplicate mapping for `{file_b}`.");
return dict;
}
dict [file_b] = line [..eq];
}
} catch (Exception e) {
AnsiConsole.WriteException (e);
}
result = 0;
return dict;
}
}