Skip to content

Commit

Permalink
Merge pull request #79 from lichie567/develop
Browse files Browse the repository at this point in the history
merge from Develop
  • Loading branch information
lichie567 authored Aug 2, 2024
2 parents 8f7a620 + 442a496 commit 06c06c1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 49 deletions.
56 changes: 24 additions & 32 deletions LMeter/ACT/FFLogsClient.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using Microsoft.ClearScript.V8;
using Dalamud.Plugin.Services;
using LMeter.Helpers;
using Newtonsoft.Json;

namespace LMeter.Act
{
public partial class FFLogsClient : IPluginDisposable
public class FFLogsClient : IPluginDisposable
{
[GeneratedRegex(@"https://assets.rpglogs.com/js/log-parsers/parser-ff\.[a-f0-9]+\.js", RegexOptions.Compiled)]
private static partial Regex GeneratedRegex();
private static Regex ParserUrlRegex { get; } = GeneratedRegex();

private const string FFLOGS_URL = "https://www.fflogs.com/desktop-client/parser";
private static readonly string LMETER_USERAGENT = $"LMeter/{Plugin.Version} (+https://github.com/lichie567/LMeter)";
private const string PARSER_FILENAME = "parser-ff.c0affdeee3005b9d.js";
private readonly string PARSER_URL = $"https://assets.rpglogs.com/js/log-parsers/{PARSER_FILENAME}";
private static readonly string LMETER_USERAGENT = $"LMeter/{Plugin.Version}";

private V8ScriptEngine Engine { get; set; }
private string ParserScript { get; init; }
Expand All @@ -31,19 +28,28 @@ public FFLogsClient()

try
{
HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(LMETER_USERAGENT);
HttpResponseMessage response = httpClient.GetAsync(FFLOGS_URL).GetAwaiter().GetResult();
string result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Match match = ParserUrlRegex.Match(result);
if (match.Success)
string parserFile = Path.Join(Plugin.ConfigFileDir, PARSER_FILENAME);
bool parserCached = File.Exists(parserFile);
if (parserCached)
{
this.ParserScript = File.ReadAllText(parserFile);
}
else
{
string parser_url = match.Groups[0].ToString();
response = httpClient.GetAsync(parser_url).GetAwaiter().GetResult();
this.ParserScript = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(LMETER_USERAGENT);
HttpResponseMessage response = httpClient.GetAsync(PARSER_URL).GetAwaiter().GetResult();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
this.ParserScript = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
}

this.InitializeEngine();
if (!parserCached && this.Initialized == true)
{
File.WriteAllText(parserFile, this.ParserScript);
}
}
catch (Exception ex)
{
Expand All @@ -68,20 +74,6 @@ private void InitializeEngine()
}
}

// Debugging
// public void Run(string command)
// {
// try
// {
// var result = this.Engine.Evaluate(command);
// Singletons.Get<IPluginLog>().Info($"{result}");
// }
// catch(Exception ex)
// {
// Singletons.Get<IPluginLog>().Error(ex.ToString());
// }
// }

public void ParseLine(string logLine)
{
if (this.Initialized)
Expand Down
6 changes: 3 additions & 3 deletions LMeter/LMeter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<!-- Assembly Configuration -->
<PropertyGroup>
<AssemblyName>LMeter</AssemblyName>
<AssemblyVersion>0.4.1.1</AssemblyVersion>
<FileVersion>0.4.1.1</FileVersion>
<InformationalVersion>0.4.1.1</InformationalVersion>
<AssemblyVersion>0.4.1.2</AssemblyVersion>
<FileVersion>0.4.1.2</FileVersion>
<InformationalVersion>0.4.1.2</InformationalVersion>
</PropertyGroup>

<!-- Build Configuration -->
Expand Down
2 changes: 1 addition & 1 deletion LMeter/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Plugin : IDalamudPlugin
{
public const string ConfigFileName = "LMeter.json";

public static string Version { get; private set; } = "0.4.1.1";
public static string Version { get; private set; } = "0.4.1.2";
public static string ConfigFileDir { get; private set; } = "";
public static string ConfigFilePath { get; private set; } = "";
public static string AssemblyFileDir { get; private set; } = "";
Expand Down
11 changes: 0 additions & 11 deletions LMeter/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ private void OnLogout()

private void PluginCommand(string command, string arguments)
{
// if (arguments.StartsWith("script"))
// {
// string[] split = arguments.Split(" ");
// FFLogsClient? client = Singletons.Get<LogClient>()._fflogsClient;
// if (client is not null && split.Length > 1)
// {
// client.Run(split[1]);
// }
// return;
// }

string[] argArray = arguments.Split(" ");
switch (argArray)
{
Expand Down
3 changes: 3 additions & 0 deletions LMeter/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.4.1.2
- Update FFLogs integration

# Version 0.4.1.1
- Fix bug with [dps] tag not working for some users

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.1")]
[assembly: AssemblyFileVersion("0.4.1.1")]
[assembly: AssemblyVersion("0.4.1.2")]
[assembly: AssemblyFileVersion("0.4.1.2")]

0 comments on commit 06c06c1

Please sign in to comment.