-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUniqueArtMapping.cs
More file actions
63 lines (56 loc) · 2.31 KB
/
UniqueArtMapping.cs
File metadata and controls
63 lines (56 loc) · 2.31 KB
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
using System.Reflection;
using ExileCore;
using Newtonsoft.Json;
namespace UniqueFinder;
public static class UniqueArtMapping
{
private static Dictionary<string, List<string>> _mapping = new();
private const string CustomUniqueArtMappingPath = "uniqueArtMapping.json";
public static Dictionary<string, List<string>> Mapping(UniqueFinder plugin)
{
if (_mapping.Count != 0) return _mapping;
var customFilePath = Path.Join(plugin.DirectoryFullName, CustomUniqueArtMappingPath);
if (File.Exists(customFilePath))
{
DebugWindow.LogMsg($"UniqueFinder: Read {CustomUniqueArtMappingPath} from file system");
ReadMapping(File.ReadAllText(customFilePath));
}
else
{
try
{
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"UniqueFinder.{CustomUniqueArtMappingPath}");
if (stream is null)
{
DebugWindow.LogError($"UniqueFinder: Assembly {CustomUniqueArtMappingPath} stream is null");
_mapping = new Dictionary<string, List<string>>();
return _mapping;
}
DebugWindow.LogMsg($"UniqueFinder: Read {CustomUniqueArtMappingPath} from assembly...");
using var reader = new StreamReader(stream);
var content = reader.ReadToEnd();
ReadMapping(content);
File.WriteAllText(customFilePath, content);
}
catch (Exception ex)
{
DebugWindow.LogError($"UniqueFinder: Unable to load embedded art mapping: {ex}");
_mapping = new Dictionary<string, List<string>>();
return _mapping;
}
}
return _mapping;
}
private static void ReadMapping(string source)
{
try
{
_mapping = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(source) ?? new Dictionary<string, List<string>>();
foreach (var (renderPath, names) in _mapping) names.RemoveAll(n => n.StartsWith("Replica") && !n.StartsWith("Replica Dragonfang"));
}
catch (Exception ex)
{
DebugWindow.LogError($"UniqueFinder: Unable to load art mapping: {ex}");
}
}
}