feat: hash screenshot
This commit is contained in:
parent
4cf3258bdd
commit
4f4e168583
29
Command.cs
29
Command.cs
|
@ -1,5 +1,6 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using Blake3;
|
||||
using Dalamud.Game.Command;
|
||||
using Newtonsoft.Json;
|
||||
using WebP.Net;
|
||||
|
@ -38,28 +39,41 @@ internal class Command : IDisposable {
|
|||
}
|
||||
|
||||
var saveAs = this.Plugin.Config.SaveFormat;
|
||||
byte[] imageData;
|
||||
string ext;
|
||||
if (saveAs.ToImageFormat() is { } format) {
|
||||
this.SaveNative(format, bitmap);
|
||||
var data = this.SaveNative(format, bitmap);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
(imageData, ext) = data.Value;
|
||||
} else if (saveAs is Format.WebpLossless or Format.WebpLossy) {
|
||||
using var webp = new WebPObject(bitmap);
|
||||
var bytes = saveAs == Format.WebpLossless
|
||||
imageData = saveAs == Format.WebpLossless
|
||||
? webp.GetWebPLossless()
|
||||
: webp.GetWebPLossy(this.Plugin.Config.SaveFormatData);
|
||||
using var stream = this.OpenFile("webp");
|
||||
stream.Write(bytes);
|
||||
ext = "webp";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
using var stream = this.OpenFile(ext);
|
||||
stream.Write(imageData);
|
||||
|
||||
var meta = ScreenshotMetadata.Capture(this.Plugin);
|
||||
var hash = new Blake3HashAlgorithm().ComputeHash(imageData);
|
||||
meta.Blake3Hash = Convert.ToHexString(hash);
|
||||
var json = JsonConvert.SerializeObject(meta, Formatting.Indented);
|
||||
Plugin.Log.Info(json);
|
||||
|
||||
this.Plugin.ChatGui.Print("Screenshot saved.");
|
||||
}
|
||||
|
||||
private void SaveNative(ImageFormat format, Image bitmap) {
|
||||
private (byte[], string)? SaveNative(ImageFormat format, Image bitmap) {
|
||||
var encoder = GetEncoder(format);
|
||||
if (encoder == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
|
||||
|
@ -75,8 +89,9 @@ internal class Command : IDisposable {
|
|||
],
|
||||
};
|
||||
|
||||
using var stream = this.OpenFile(ext);
|
||||
using var stream = new MemoryStream();
|
||||
bitmap.Save(stream, encoder, parameters);
|
||||
return (stream.ToArray(), ext);
|
||||
}
|
||||
|
||||
private FileStream OpenFile(string ext) {
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blake3" Version="1.0.0" />
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
"version": 1,
|
||||
"dependencies": {
|
||||
"net7.0-windows7.0": {
|
||||
"Blake3": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.0.0, )",
|
||||
"resolved": "1.0.0",
|
||||
"contentHash": "PR0aJRXkBGk8dPhpAdrscHzTpbNiFQ/oQLAG5vEuwTE4Vu2u4D6UZwwr7tqlDyjCpbE76pWwjZz5BmpoNNZZ/A=="
|
||||
},
|
||||
"DalamudPackager": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.1.12, )",
|
||||
|
|
Loading…
Reference in New Issue