mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Refine IsCloudSynced
This commit is contained in:
parent
5503bb32e0
commit
d59be1e660
1 changed files with 23 additions and 5 deletions
|
|
@ -4,21 +4,39 @@ public static unsafe partial class CloudApi
|
||||||
{
|
{
|
||||||
private const int CfSyncRootInfoBasic = 0;
|
private const int CfSyncRootInfoBasic = 0;
|
||||||
|
|
||||||
|
/// <summary> Determines whether a file or directory is cloud-synced using OneDrive or other providers that use the Cloud API. </summary>
|
||||||
|
/// <remarks> Can be expensive. Callers should cache the result when relevant. </remarks>
|
||||||
public static bool IsCloudSynced(string path)
|
public static bool IsCloudSynced(string path)
|
||||||
{
|
{
|
||||||
var buffer = stackalloc long[1];
|
var buffer = stackalloc long[1];
|
||||||
var hr = CfGetSyncRootInfoByPath(path, CfSyncRootInfoBasic, buffer, sizeof(long), out var length);
|
int hr;
|
||||||
Penumbra.Log.Information($"{nameof(CfGetSyncRootInfoByPath)} returned HRESULT {hr}");
|
uint length;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hr = CfGetSyncRootInfoByPath(path, CfSyncRootInfoBasic, buffer, sizeof(long), out length);
|
||||||
|
}
|
||||||
|
catch (DllNotFoundException)
|
||||||
|
{
|
||||||
|
Penumbra.Log.Debug($"{nameof(CfGetSyncRootInfoByPath)} threw DllNotFoundException");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (EntryPointNotFoundException)
|
||||||
|
{
|
||||||
|
Penumbra.Log.Debug($"{nameof(CfGetSyncRootInfoByPath)} threw EntryPointNotFoundException");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Penumbra.Log.Debug($"{nameof(CfGetSyncRootInfoByPath)} returned HRESULT 0x{hr:X8}");
|
||||||
if (hr < 0)
|
if (hr < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (length != sizeof(long))
|
if (length != sizeof(long))
|
||||||
{
|
{
|
||||||
Penumbra.Log.Warning($"Expected {nameof(CfGetSyncRootInfoByPath)} to return {sizeof(long)} bytes, got {length} bytes");
|
Penumbra.Log.Debug($"Expected {nameof(CfGetSyncRootInfoByPath)} to return {sizeof(long)} bytes, got {length} bytes");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Penumbra.Log.Information($"{nameof(CfGetSyncRootInfoByPath)} returned {{ SyncRootFileId = 0x{*buffer:X16} }}");
|
Penumbra.Log.Debug($"{nameof(CfGetSyncRootInfoByPath)} returned {{ SyncRootFileId = 0x{*buffer:X16} }}");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue