-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPowerSyncPathResolver.cs
More file actions
68 lines (61 loc) · 2.23 KB
/
PowerSyncPathResolver.cs
File metadata and controls
68 lines (61 loc) · 2.23 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
namespace PowerSync.Common.Utils;
using System.Runtime.InteropServices;
public static class PowerSyncPathResolver
{
public static string GetNativeLibraryPath(string packagePath)
{
string fileName = GetFileNameForPlatform();
// Check the flattened path first since some technologies (eg. .NET Framework 4.8) flatten libraries into the root folder.
// Checking this path first also makes debugging easier, since one can easily change the resolved DLL.
string flattenedPath = Path.Combine(packagePath, fileName);
if (File.Exists(flattenedPath)) return flattenedPath;
// Otherwise, check the native code dir
string rid = GetRuntimeIdentifier();
string nativeDir = Path.Combine(packagePath, "runtimes", rid, "native");
return Path.Combine(nativeDir, fileName);
}
private static string GetRuntimeIdentifier()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
return "osx-arm64";
else
return "osx-x64";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
return "linux-arm64";
else
return "linux-x64";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
return "win-arm64";
else
return "win-x64";
}
throw new PlatformNotSupportedException("Unsupported platform.");
}
private static string GetFileNameForPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "libpowersync.dylib";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "libpowersync.so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "powersync.dll";
}
else
{
throw new PlatformNotSupportedException("Unsupported platform.");
}
}
}