-
-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathFeatureNaming.cs
83 lines (77 loc) · 3.22 KB
/
FeatureNaming.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
ViVe - Windows feature configuration library
Copyright (C) 2019-2023 @thebookisclosed
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Albacore.ViVeTool
{
internal class FeatureNaming
{
internal const string DictFileName = "FeatureDictionary.pfs";
internal static string DictFilePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), DictFileName);
internal static List<uint> FindIdsForNames(IEnumerable<string> featureNames)
{
if (!File.Exists(DictFilePath))
return null;
var result = new List<uint>();
var namesCommas = featureNames.Select(x => x.ToLowerInvariant() + ",").ToList();
using (StreamReader reader = new StreamReader(File.OpenRead(DictFilePath)))
{
while (!reader.EndOfStream)
{
var currentLine = reader.ReadLine().ToLowerInvariant();
foreach (var nc in namesCommas)
{
if (currentLine.StartsWith(nc))
{
result.Add(uint.Parse(currentLine.Substring(nc.Length)));
namesCommas.Remove(nc);
break;
}
}
if (namesCommas.Count == 0)
break;
}
}
return result;
}
internal static Dictionary<uint, string> FindNamesForFeatures(IEnumerable<uint> featureIDs)
{
var result = new Dictionary<uint, string>();
if (!File.Exists(DictFilePath))
return null;
var idsCommas = featureIDs.Select(x => "," + x.ToString()).ToList();
using (StreamReader reader = new StreamReader(File.OpenRead(DictFilePath)))
{
while (!reader.EndOfStream)
{
var currentLine = reader.ReadLine();
foreach (var ic in idsCommas)
{
if (currentLine.EndsWith(ic))
{
result[uint.Parse(ic.Substring(1))] = currentLine.Substring(0, currentLine.IndexOf(','));
idsCommas.Remove(ic);
break;
}
}
if (idsCommas.Count == 0)
break;
}
}
return result;
}
}
}