Skip to content

Commit a9c3915

Browse files
authored
Merge pull request #7 from siegrest/dev
v1.0.3
2 parents 90aaa2c + dcace70 commit a9c3915

40 files changed

+1026
-890
lines changed

Domain/Domain.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="LogRegExps.cs" />
5050
<Compile Include="LogType.cs" />
5151
<Compile Include="Release.cs" />
52+
<Compile Include="Settings.cs" />
5253
</ItemGroup>
5354
<ItemGroup>
5455
<Folder Include="Properties\" />

Domain/LogRegExps.cs

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public static class LogRegExps {
88
public static readonly LogRegex[] RegExpList = {
99
new LogRegex {
1010
Type = LogType.LoginScreen,
11-
ParseAction = null,
1211
RegExps = new[] {
1312
// 2017/12/27 18:38:37 16952332 698 [INFO Client 5156] Abnormal disconnect: An unexpected disconnection occurred.
1413
new Regex(LogRegex.LogPrefix + @"Abnormal disconnect.+$"),
@@ -19,7 +18,6 @@ public static class LogRegExps {
1918

2019
new LogRegex {
2120
Type = LogType.CharacterSelect,
22-
ParseAction = null,
2321
RegExps = new[] {
2422
// 2019/03/01 12:22:13 873163875 ac [INFO Client 4364] Async connecting to lon01.login.pathofexile.com:20481
2523
// new Regex(LogRegex.LogPrefix + @"Async connecting.+$"),
@@ -30,7 +28,6 @@ public static class LogRegExps {
3028

3129
new LogRegex {
3230
Type = LogType.AreaChange,
33-
ParseAction = null,
3431
RegExps = new[] {
3532
// 2019/03/01 12:36:42 874033015 a21 [INFO Client 4364] : You have entered Oriath.
3633
new Regex(LogRegex.LogPrefix + @"You have entered (.*)\.$")
@@ -39,7 +36,6 @@ public static class LogRegExps {
3936

4037
new LogRegex {
4138
Type = LogType.StatusChange,
42-
ParseAction = null,
4339
RegExps = new[] {
4440
// 2019/03/01 12:39:58 874229375 a21 [INFO Client 4364] : AFK mode is now ON. Autoreply "This player is AFK."
4541
// 2019/03/01 12:40:06 874236671 a21 [INFO Client 4364] : DND mode is now ON. Autoreply "This player has DND mode enabled."

Domain/LogRegex.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace Domain {
55
public class LogRegex {
66
public const string LogPrefix = @"^([0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}).*\[INFO Client [0-9]*] :? ?";
7-
public Action<LogMatch> ParseAction;
87
public LogType Type;
98
public Regex[] RegExps;
109
}

Domain/Release.cs

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ namespace Domain {
22
public sealed class Release {
33
public string html_url { get; set; }
44
public string tag_name { get; set; }
5+
public bool prerelease { get; set; }
56
}
67
}

Domain/Settings.cs

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
using System;
2+
using System.Globalization;
3+
using System.IO;
4+
using System.Reflection;
5+
using System.Text.RegularExpressions;
6+
7+
namespace Domain {
8+
public class Settings {
9+
public const string DiscordAppId = "551089446460850176";
10+
public const string ProgramName = "Exiled Presence";
11+
public const string GameWindowTitle = "Path of Exile";
12+
public const string Version = "v1.0.3";
13+
14+
public static readonly string StartupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
15+
public static readonly string StartupShortcutPath = Path.Combine(StartupFolderPath, $"{ProgramName}.url");
16+
public static readonly string AppPath = Assembly.GetEntryAssembly().Location;
17+
public static readonly Regex SessIdRegex = new Regex("^[0-9a-fA-F]{32}$");
18+
public static readonly Regex VersionRegex = new Regex(@"^v\d+(\.\d+)*$");
19+
20+
public static readonly TimeSpan PresencePollInterval = TimeSpan.FromMilliseconds(500);
21+
public static readonly TimeSpan UpdateCheckInterval = TimeSpan.FromHours(24);
22+
public static readonly TimeSpan CharacterUpdateInterval = TimeSpan.FromSeconds(60);
23+
private const string ConfTimeFormat = "yyyy-MM-dd HH:mm";
24+
25+
26+
public string AccountName { get; set; }
27+
public string PoeSessionId { get; set; }
28+
29+
private string _configVersion;
30+
private string _lastUpdateCheck;
31+
private string _showElapsedTime;
32+
private string _showCharName;
33+
private string _showCharXp;
34+
private string _showCharLevel;
35+
36+
public bool ShowElapsedTime => _showElapsedTime.Equals("1");
37+
public bool ShowCharName => _showCharName.Equals("1");
38+
public bool ShowCharXp => _showCharXp.Equals("1");
39+
public bool ShowCharLevel => _showCharLevel.Equals("1");
40+
41+
public bool CheckUpdates => string.IsNullOrEmpty(_lastUpdateCheck) ||
42+
DateTime.ParseExact(_lastUpdateCheck, ConfTimeFormat, CultureInfo.InvariantCulture,
43+
DateTimeStyles.AssumeUniversal) < DateTime.UtcNow.Subtract(UpdateCheckInterval);
44+
45+
/// <summary>
46+
/// Loads in settings from another instance
47+
/// </summary>
48+
public void Update(Settings settings) {
49+
AccountName = settings.AccountName;
50+
PoeSessionId = settings.PoeSessionId;
51+
_lastUpdateCheck = settings._lastUpdateCheck;
52+
_configVersion = settings._configVersion;
53+
54+
_showElapsedTime = settings._showElapsedTime;
55+
_showCharName = settings._showCharName;
56+
_showCharXp = settings._showCharXp;
57+
_showCharLevel = settings._showCharXp;
58+
}
59+
60+
/// <summary>
61+
/// Validate all config values
62+
/// </summary>
63+
public void Validate() {
64+
if (AccountName == null || PoeSessionId == null || _lastUpdateCheck == null || _configVersion == null ||
65+
_showCharXp == null | _showCharName == null || _showCharLevel == null || _showElapsedTime == null) {
66+
throw new ArgumentNullException();
67+
}
68+
69+
if (!string.IsNullOrEmpty(PoeSessionId) && !SessIdRegex.IsMatch(PoeSessionId)) {
70+
throw new ArgumentException("Invalid session ID");
71+
}
72+
73+
if (!string.IsNullOrEmpty(AccountName) && AccountName.Length < 3) {
74+
throw new ArgumentException("Invalid account name");
75+
}
76+
77+
if (!string.IsNullOrEmpty(_lastUpdateCheck) && !DateTime.TryParseExact(_lastUpdateCheck,
78+
ConfTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out _)) {
79+
throw new ArgumentException($"Invalid last update time (expected format {ConfTimeFormat})");
80+
}
81+
82+
if (string.IsNullOrEmpty(_configVersion) || !VersionRegex.IsMatch(_configVersion)) {
83+
throw new ArgumentException("Invalid config version");
84+
}
85+
86+
if (string.IsNullOrEmpty(_showElapsedTime) ||
87+
!_showElapsedTime.Equals("0") &&
88+
!_showElapsedTime.Equals("1")) {
89+
throw new ArgumentException("Invalid value for show elapsed time (expected 1 or 0)");
90+
}
91+
92+
if (string.IsNullOrEmpty(_showCharName) ||
93+
!_showCharName.Equals("0") &&
94+
!_showCharName.Equals("1")) {
95+
throw new ArgumentException("Invalid value for show character name (expected 1 or 0)");
96+
}
97+
98+
if (string.IsNullOrEmpty(_showCharXp) ||
99+
!_showCharXp.Equals("0") &&
100+
!_showCharXp.Equals("1")) {
101+
throw new ArgumentException("Invalid value for show character xp (expected 1 or 0)");
102+
}
103+
104+
if (string.IsNullOrEmpty(_showCharLevel) ||
105+
!_showCharLevel.Equals("0") &&
106+
!_showCharLevel.Equals("1")) {
107+
throw new ArgumentException("Invalid value for show character level (expected 1 or 0)");
108+
}
109+
}
110+
111+
/// <summary>
112+
/// Loads the default values
113+
/// </summary>
114+
public void Reset() {
115+
Update(new Settings());
116+
}
117+
118+
/// <summary>
119+
/// Attempt to store value with key
120+
/// </summary>
121+
public void ParseValue(string key, string val) {
122+
if (string.IsNullOrEmpty(val)) {
123+
val = null;
124+
} else if (val.StartsWith("#")) {
125+
val = "";
126+
}
127+
128+
switch (key) {
129+
case "account name":
130+
AccountName = val;
131+
break;
132+
133+
case "session id":
134+
PoeSessionId = val;
135+
break;
136+
137+
case "last update check":
138+
_lastUpdateCheck = val;
139+
break;
140+
141+
case "show elapsed time":
142+
_showElapsedTime = val;
143+
break;
144+
145+
case "show character name":
146+
_showCharName = val;
147+
break;
148+
149+
case "show character xp":
150+
_showCharXp = val;
151+
break;
152+
153+
case "show character level":
154+
_showCharLevel = val;
155+
break;
156+
157+
case "config version":
158+
_configVersion = val;
159+
break;
160+
161+
default:
162+
return;
163+
}
164+
}
165+
166+
/// <summary>
167+
/// Attempt to get value from key
168+
/// </summary>
169+
public string GetValue(string key) {
170+
switch (key) {
171+
case "account name":
172+
return AccountName;
173+
174+
case "session id":
175+
return PoeSessionId;
176+
177+
case "last update check":
178+
return _lastUpdateCheck;
179+
180+
case "config version":
181+
return _configVersion ?? Version;
182+
183+
case "show elapsed time":
184+
return _showElapsedTime ?? "1";
185+
186+
case "show character name":
187+
return _showCharName ?? "1";
188+
189+
case "show character xp":
190+
return _showCharXp ?? "1";
191+
192+
case "show character level":
193+
return _showCharLevel ?? "1";
194+
195+
default:
196+
return null;
197+
}
198+
}
199+
200+
/// <summary>
201+
/// Sets the last update check time to now
202+
/// </summary>
203+
public void UpdateLastUpdateTime() {
204+
_lastUpdateCheck = DateTime.UtcNow.ToString(ConfTimeFormat);
205+
}
206+
}
207+
}

Exiled Presence.sln

-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csp
44
EndProject
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{5FE478F0-A5D6-43B1-9FBE-FB50586BB542}"
66
EndProject
7-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utility", "Utility\Utility.csproj", "{5232385C-D0E6-49E5-9208-8FF7BFE43B59}"
8-
EndProject
97
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordRPC", "DiscordRPC\DiscordRPC.csproj", "{819D20D6-8D88-45C1-A4D2-AA21F10ABD19}"
108
EndProject
119
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Program", "Program\Program.csproj", "{0ACA0321-92A3-4499-8124-BC52929B588E}"
@@ -24,10 +22,6 @@ Global
2422
{5FE478F0-A5D6-43B1-9FBE-FB50586BB542}.Debug|Any CPU.Build.0 = Debug|Any CPU
2523
{5FE478F0-A5D6-43B1-9FBE-FB50586BB542}.Release|Any CPU.ActiveCfg = Release|Any CPU
2624
{5FE478F0-A5D6-43B1-9FBE-FB50586BB542}.Release|Any CPU.Build.0 = Release|Any CPU
27-
{5232385C-D0E6-49E5-9208-8FF7BFE43B59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28-
{5232385C-D0E6-49E5-9208-8FF7BFE43B59}.Debug|Any CPU.Build.0 = Debug|Any CPU
29-
{5232385C-D0E6-49E5-9208-8FF7BFE43B59}.Release|Any CPU.ActiveCfg = Release|Any CPU
30-
{5232385C-D0E6-49E5-9208-8FF7BFE43B59}.Release|Any CPU.Build.0 = Release|Any CPU
3125
{819D20D6-8D88-45C1-A4D2-AA21F10ABD19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3226
{819D20D6-8D88-45C1-A4D2-AA21F10ABD19}.Debug|Any CPU.Build.0 = Debug|Any CPU
3327
{819D20D6-8D88-45C1-A4D2-AA21F10ABD19}.Release|Any CPU.ActiveCfg = Release|Any CPU

Program/Program.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
<Project>{5fe478f0-a5d6-43b1-9fbe-fb50586bb542}</Project>
8080
<Name>Service</Name>
8181
</ProjectReference>
82-
<ProjectReference Include="..\Utility\Utility.csproj">
83-
<Project>{5232385c-d0e6-49e5-9208-8ff7bfe43b59}</Project>
84-
<Name>Utility</Name>
85-
</ProjectReference>
8682
</ItemGroup>
8783
<ItemGroup>
8884
<EmbeddedResource Include="Properties\Resources.resx">

0 commit comments

Comments
 (0)