-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSharedStatic.V1Ext_Update5.cs
More file actions
79 lines (70 loc) · 3.06 KB
/
Copy pathSharedStatic.V1Ext_Update5.cs
File metadata and controls
79 lines (70 loc) · 3.06 KB
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
using Hi3Helper.Plugin.Core.Management;
using Hi3Helper.Plugin.Core.Utility;
using Microsoft.Extensions.Logging;
namespace Hi3Helper.Plugin.Core;
public partial class SharedStaticV1Ext
{
// Update5
/// <summary>
/// Sets the per-file progress callback from the Main Application.
/// To disable the callback, set <paramref name="perFileProgressCallback"/> to <see cref="nint.Zero"/>.
/// </summary>
/// <param name="perFileProgressCallback">The address of the per-file progress callback function.</param>
internal delegate HResult SetPerFileProgressCallbackDelegate(nint perFileProgressCallback);
/// <summary>
/// The stored function pointer for the per-file progress callback from the Main Application.
/// </summary>
internal static nint PerFileProgressCallbackAddr;
/// <summary>
/// Invokes the per-file progress callback if it has been registered by the Main Application.
/// </summary>
/// <param name="perFileDownloadedBytes">Bytes downloaded for the current file.</param>
/// <param name="perFileTotalBytes">Total size of the current file.</param>
public static unsafe void InvokePerFileProgress(long perFileDownloadedBytes, long perFileTotalBytes)
{
if (PerFileProgressCallbackAddr == nint.Zero)
{
return;
}
// Call the callback
InstallPerFileProgress progress = new()
{
PerFileDownloadedBytes = perFileDownloadedBytes,
PerFileTotalBytes = perFileTotalBytes
};
((delegate* unmanaged[Cdecl]<ref readonly InstallPerFileProgress, void>)
PerFileProgressCallbackAddr)(in progress);
}
}
public partial class SharedStaticV1Ext<T>
{
private static void InitExtension_Update5Exports()
{
/* ----------------------------------------------------------------------
* Update 5 Feature Sets
* ----------------------------------------------------------------------
* This feature sets includes the following feature:
* - Per-file Install Progress Callback
* - SetPerFileProgressCallback
*/
// -> Plugin Per-file Progress Callback Setter
TryRegisterApiExport<SetPerFileProgressCallbackDelegate>("SetPerFileProgressCallback", SetPerFileProgressCallback);
}
#region ABI Proxies
/// <summary>
/// This method is an ABI proxy and installer for the Per-file Progress Callback functionality.
/// </summary>
private static HResult SetPerFileProgressCallback(nint perFileProgressCallback)
{
if (perFileProgressCallback == nint.Zero)
{
PerFileProgressCallbackAddr = nint.Zero;
InstanceLogger.LogTrace("[SetPerFileProgressCallback] Per-file progress callback has been uninstalled");
return HResult.Ok;
}
PerFileProgressCallbackAddr = perFileProgressCallback;
InstanceLogger.LogTrace("[SetPerFileProgressCallback] Per-file progress callback has been installed at address: 0x{Ptr:x8}", perFileProgressCallback);
return HResult.Ok;
}
#endregion
}