-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginListing.cs
88 lines (74 loc) · 2.18 KB
/
PluginListing.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
84
85
86
87
88
namespace MO2ExportImport;
public class PluginListing: IEquatable<PluginListing>, IListing
{
private string _originalEntryString;
public string Name { get; set; }
public bool? Enabled { get; set; }
public string? PluginGroup { get; set; } = null;
public bool IsBaseGamePlugin { get; set; } = false;
public PluginListing(string entryString)
{
_originalEntryString = entryString;
Name = FormatHandler.TrimPluginActivationStatus(entryString);
Enabled = FormatHandler.GetPluginActivationStatus(entryString);
}
public PluginListing(string loadOrderEntryString, bool fromLoadOrderFile)
{
Name = loadOrderEntryString;
_originalEntryString = loadOrderEntryString;
IsBaseGamePlugin = fromLoadOrderFile;
}
public PluginListing() // for Json deserialization
{
}
public string GetCurrentEntryString()
{
string prefix = string.Empty;
if (Enabled.HasValue && Enabled.Value)
{
prefix += "*";
}
return prefix + Name;
}
public bool Equals(PluginListing? other)
{
return other is not null && Name.Equals(other.Name);
}
public bool Equals(IListing? other)
{
return other is not null && other is PluginListing && Name.Equals(other.Name);
}
public int GetIndexOf(IList<IListing> list)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i].Equals(this))
{
return i;
}
}
return -1;
}
public override string ToString()
{
return Name;
}
// Override GetHashCode
public override int GetHashCode()
{
// Combine hash codes of properties
return Name.GetHashCode();
}
// Overload == operator
public static bool operator ==(PluginListing left, PluginListing right)
{
if (ReferenceEquals(left, right)) return true;
if (left is null || right is null) return false;
return left.Equals(right);
}
// Overload != operator
public static bool operator !=(PluginListing left, PluginListing right)
{
return !(left == right);
}
}