Send filenames via HTTP to indexer
This commit is contained in:
parent
fe25e26980
commit
b7074793be
2 changed files with 36 additions and 7 deletions
|
@ -1,11 +1,42 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Enumeration;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Dalamud.Hooking;
|
using Dalamud.Hooking;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using Dalamud.Utility.Signatures;
|
using Dalamud.Utility.Signatures;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SqPackIndexer;
|
namespace SqPackIndexer;
|
||||||
|
|
||||||
|
public class ApiRequest
|
||||||
|
{
|
||||||
|
public string filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HttpHelper
|
||||||
|
{
|
||||||
|
private static HttpClient sharedClient = new()
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri("http://127.0.0.1:3500"),
|
||||||
|
};
|
||||||
|
|
||||||
|
public async void sendFilename(String filename)
|
||||||
|
{
|
||||||
|
using StringContent jsonContent = new(JsonConvert.SerializeObject(new
|
||||||
|
ApiRequest {
|
||||||
|
filename = filename
|
||||||
|
}),
|
||||||
|
Encoding.UTF8,
|
||||||
|
"application/json");
|
||||||
|
|
||||||
|
using HttpResponseMessage response = await sharedClient.PostAsync(
|
||||||
|
"add_hash",
|
||||||
|
jsonContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public unsafe class FileReadService : IDisposable
|
public unsafe class FileReadService : IDisposable
|
||||||
{
|
{
|
||||||
public FileReadService(ResourceManagerService resourceManager, IGameInteropProvider interop)
|
public FileReadService(ResourceManagerService resourceManager, IGameInteropProvider interop)
|
||||||
|
@ -13,6 +44,7 @@ public unsafe class FileReadService : IDisposable
|
||||||
_resourceManager = resourceManager;
|
_resourceManager = resourceManager;
|
||||||
interop.InitializeFromAttributes(this);
|
interop.InitializeFromAttributes(this);
|
||||||
_readSqPackHook.Enable();
|
_readSqPackHook.Enable();
|
||||||
|
_httpHelper = new HttpHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Invoked when a file is supposed to be read from SqPack. </summary>
|
/// <summary> Invoked when a file is supposed to be read from SqPack. </summary>
|
||||||
|
@ -53,10 +85,14 @@ public unsafe class FileReadService : IDisposable
|
||||||
[Signature(Sigs.ReadSqPack, DetourName = nameof(ReadSqPackDetour))]
|
[Signature(Sigs.ReadSqPack, DetourName = nameof(ReadSqPackDetour))]
|
||||||
private readonly Hook<ReadSqPackPrototype> _readSqPackHook = null!;
|
private readonly Hook<ReadSqPackPrototype> _readSqPackHook = null!;
|
||||||
|
|
||||||
|
private readonly HttpHelper _httpHelper;
|
||||||
|
|
||||||
private byte ReadSqPackDetour(nint resourceManager, SeFileDescriptor* fileDescriptor, int priority, bool isSync)
|
private byte ReadSqPackDetour(nint resourceManager, SeFileDescriptor* fileDescriptor, int priority, bool isSync)
|
||||||
{
|
{
|
||||||
Dalamud.Logging.PluginLog.Log("Got detour: " + fileDescriptor->ResourceHandle->FileName);
|
Dalamud.Logging.PluginLog.Log("Got detour: " + fileDescriptor->ResourceHandle->FileName);
|
||||||
|
|
||||||
|
_httpHelper.sendFilename(fileDescriptor->ResourceHandle->FileName.ToString());
|
||||||
|
|
||||||
byte? ret = null;
|
byte? ret = null;
|
||||||
_lastFileThreadResourceManager.Value = resourceManager;
|
_lastFileThreadResourceManager.Value = resourceManager;
|
||||||
ReadSqPack?.Invoke(fileDescriptor, ref priority, ref isSync, ref ret);
|
ReadSqPack?.Invoke(fileDescriptor, ref priority, ref isSync, ref ret);
|
||||||
|
|
|
@ -9,11 +9,4 @@
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<RootNamespace>SqPackIndexer</RootNamespace>
|
<RootNamespace>SqPackIndexer</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\Data\goat.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
<Visible>false</Visible>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Reference in a new issue