You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.0 KiB

using System.IO.Compression;
using System.Runtime.InteropServices;
namespace EC.Util.CameraSDK;
public class CameraFactory
{
static CameraFactory()
{
string zipPath = Path.Combine("libs", "cameraSdks.zip");
if (!File.Exists(zipPath)) throw new FileNotFoundException(zipPath);
using ZipArchive archive = ZipFile.OpenRead(zipPath);
bool isWin = RuntimeInformation.IsOSPlatform(OSPlatform.Windows), is64 = Environment.Is64BitProcess;
string sysEnv = string.Format("{0}{1}", isWin ? "win" : "linux", is64 ? "64" : "32");
string hkOrDir = $"cameraSdks/hik/{sysEnv}/";
string dhOrDir = $"cameraSdks/dahua/{sysEnv}/";
string ysOrDir = $"cameraSdks/yushi/{sysEnv}/";
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.Length == 0) continue;
string fullName = entry.FullName, fileExtPath = string.Empty;
if (fullName.StartsWith(hkOrDir))
fileExtPath = Path.Join("libs", "hik", fullName[(hkOrDir.Length - 1)..]);
else if (fullName.StartsWith(dhOrDir))
fileExtPath = Path.Join("libs", "dahua", fullName[(dhOrDir.Length - 1)..]);
else if (fullName.StartsWith(ysOrDir))
fileExtPath = Path.Join("libs", "yushi", fullName[(ysOrDir.Length - 1)..]);
if (string.IsNullOrEmpty(fileExtPath)) continue;
FileInfo fi = new(fileExtPath);
if (fi.Directory != null && !fi.Directory.Exists) fi.Directory.Create();
if (!fi.Exists) entry.ExtractToFile(fileExtPath);
}
}
public static void VirtualInit()
{ }
public static ICameraSDK BuildCameraSdk(CameraInfo info)
{
ICameraSDK sdk = (info.Manufactor) switch
{
CameraManufactor.HiK => new HiKSDK(info),
CameraManufactor.DaHua => new DaHuaSDK(info),
CameraManufactor.YuShi => new YuShiSDK(info),
_ => throw new NotSupportedException(),
};
return sdk;
}
}