From d8ccf800ca1869637ee1ba59ee1d1cce6d1d8651 Mon Sep 17 00:00:00 2001 From: Er2 Date: Tue, 12 Mar 2024 15:37:08 +0300 Subject: [PATCH] Add FreeBSD support --- DepotDownloader/PlatformUtilities.cs | 20 ++++++++++++++++++++ DepotDownloader/Util.cs | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/DepotDownloader/PlatformUtilities.cs b/DepotDownloader/PlatformUtilities.cs index 9ffb70fb..a4f0b807 100644 --- a/DepotDownloader/PlatformUtilities.cs +++ b/DepotDownloader/PlatformUtilities.cs @@ -34,6 +34,12 @@ namespace DepotDownloader [FieldOffset(4)] public readonly ushort st_mode; } + [StructLayout(LayoutKind.Explicit, Size = 224)] + private readonly struct StatFBSDX64 + { + [FieldOffset(24)] public readonly ushort st_mode; + } + [DllImport("libc", EntryPoint = "__xstat", SetLastError = true)] private static extern int statLinuxX64(int version, string path, out StatLinuxX64 statLinux); @@ -49,6 +55,9 @@ namespace DepotDownloader [DllImport("libc", EntryPoint = "stat$INODE64", SetLastError = true)] private static extern int statOSXCompat(string path, out StatOSX stat); + [DllImport("libc", EntryPoint = "stat", SetLastError = true)] + private static extern int statFBSDX64(string path, out StatFBSDX64 stat); + [DllImport("libc", SetLastError = true)] private static extern int chmod(string path, uint mode); @@ -87,6 +96,17 @@ namespace DepotDownloader } } } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + switch (RuntimeInformation.ProcessArchitecture) + { + case Architecture.X64: + { + ThrowIf(statFBSDX64(path, out var stat)); + return stat.st_mode; + } + } + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { switch (RuntimeInformation.ProcessArchitecture) diff --git a/DepotDownloader/Util.cs b/DepotDownloader/Util.cs index d249c1fc..e8c20bc6 100644 --- a/DepotDownloader/Util.cs +++ b/DepotDownloader/Util.cs @@ -27,6 +27,12 @@ namespace DepotDownloader return "linux"; } + if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + // Return linux as freebsd steam client doesn't exist yet + return "linux"; + } + return "unknown"; }