From 73b540b41581cd3a8659f5c986f7225a4b3fd712 Mon Sep 17 00:00:00 2001 From: Ritchie Frodomar Date: Fri, 25 Oct 2024 21:41:57 -0400 Subject: [PATCH] Remove seveal unneeded APIs --- .../Core/SociallyDistantUtility.cs | 270 +----------------- 1 file changed, 15 insertions(+), 255 deletions(-) diff --git a/src/SociallyDistant.Framework/Core/SociallyDistantUtility.cs b/src/SociallyDistant.Framework/Core/SociallyDistantUtility.cs index 087719b1..72791848 100644 --- a/src/SociallyDistant.Framework/Core/SociallyDistantUtility.cs +++ b/src/SociallyDistant.Framework/Core/SociallyDistantUtility.cs @@ -31,7 +31,7 @@ namespace SociallyDistant.Core.Core 52428800, 104857600 }; - + public static readonly string PlayerHomeId = "player"; public static IEnumerable UnravelAggregateExceptions(AggregateException? aggregate) @@ -76,7 +76,7 @@ namespace SociallyDistant.Core.Core // book me a CVE <3 // - Ritchie var startInfo = new ProcessStartInfo(uri.ToString()) { UseShellExecute = true }; - + // HIGHWAY TO THE DANGER ZONE // WE GOIN' RIGHT IN TO THE DANGER ZONE! // - Ritchie @@ -88,7 +88,7 @@ namespace SociallyDistant.Core.Core var minutes = 0; var seconds = 0; var milliseconds = 0; - + // I need a minute... int minuteIndex = timeoutValue.IndexOf('m', StringComparison.Ordinal); @@ -99,7 +99,7 @@ namespace SociallyDistant.Core.Core timeoutValue = timeoutValue.Substring(minuteIndex + 1); } - + // Gimme a sec... int secondIndex = timeoutValue.IndexOf('s', StringComparison.Ordinal); if (secondIndex != -1) @@ -109,7 +109,7 @@ namespace SociallyDistant.Core.Core timeoutValue = timeoutValue.Substring(secondIndex + 1); } - + // Millisec? int millisecIndex = timeoutValue.IndexOf("ms", StringComparison.Ordinal); if (millisecIndex != -1) @@ -119,14 +119,14 @@ namespace SociallyDistant.Core.Core timeoutValue = timeoutValue.Substring(millisecIndex + 1); } - + // Add minutes to seconds, then seconds to milliseconds, then boom. We're done. seconds += minutes * 60; milliseconds += seconds * 1000; return TimeSpan.FromMilliseconds(milliseconds); } - + public static string ToUnix(this string source) { var builder = new StringBuilder(source.Length); @@ -150,7 +150,7 @@ namespace SociallyDistant.Core.Core continue; } - if (@wasWhitespace) + if (@wasWhitespace) builder.Append('_'); wasWhitespace = true; @@ -237,7 +237,7 @@ namespace SociallyDistant.Core.Core { var level = 0; var nextLevelStep = 0ul; - + for (level = 0; level < levelSteps.Count; level++) { ulong step = levelSteps[level]; @@ -254,49 +254,26 @@ namespace SociallyDistant.Core.Core return new PlayerLevelInfo(experience, level, nextLevelStep, 1); } - ulong previousLevelStep = level == 0 ? 0 : levelSteps[level - 1]; + ulong previousLevelStep = level == 0 + ? 0 + : levelSteps[level - 1]; - float progress = (experience - previousLevelStep) / (float) (nextLevelStep - previousLevelStep); + float progress = (experience - previousLevelStep) / (float)(nextLevelStep - previousLevelStep); return new PlayerLevelInfo(experience, level, nextLevelStep, progress); } - public static bool IsPosixName(string? text) - { - if (string.IsNullOrWhiteSpace(text)) - return false; - - for (var i = 0; i < text.Length; i++) - { - char character = text[i]; - - if (char.IsWhiteSpace(character)) - return false; - - if (char.IsDigit(character) && i == 0) - return false; - - if (character == '-' && i == 0) - return false; - - if (!char.IsLetterOrDigit(character) && character != '_' && character != '-') - return false; - } - - return true; - } - public static string GetHomeDirectoryHostPath(IGameContext sociallyDistant, string deviceId, int userId) { if (string.IsNullOrWhiteSpace(deviceId)) throw new InvalidOperationException("deviceId may not be whitespace."); - + string? currentSavePath = sociallyDistant.CurrentSaveDataDirectory; if (string.IsNullOrWhiteSpace(currentSavePath)) throw new InvalidOperationException("Game isn't loaded or isn't a persistent save file"); string homesPath = Path.Combine(currentSavePath, "homes"); - string devicePath = Path.Combine(homesPath, deviceId); + string devicePath = Path.Combine(homesPath, deviceId); if (!Directory.Exists(homesPath)) Directory.CreateDirectory(homesPath); @@ -310,222 +287,5 @@ namespace SociallyDistant.Core.Core return userPath; } - - public static string GetFriendlyFileSize(ulong numberOfBytes) - { - var fractionalValue = (double) numberOfBytes; - - var units = new string[] - { - "bytes", - "KB", - "MB", - "GB", - "TB" - }; - - var sb = new StringBuilder(); - - for (var i = 0; i < units.Length; i++) - { - sb.Length = 0; - sb.Append(fractionalValue.ToString("0.0")); - sb.Append(" "); - sb.Append(units[i]); - - if (fractionalValue < 1024) - break; - - fractionalValue /= 1024; - } - - return sb.ToString(); - } - - public static string GetGenderDisplayString(Gender gender) - { - // TODO: i18n - return gender switch - { - Gender.Male => "He / Him / His", - Gender.Female => "She / Her / Her's", - Gender.Unknown => "They / Them / Their", - _ => "" - }; - } - - public static IEnumerable GetSystemDiskDrives() - { -#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN - return GetSystemDiskDrives_Win32(); -#else - return GetSystemDiskDrives_Posix(); -#endif - } - - #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN - - private static IEnumerable GetSystemDiskDrives_Win32() - { - DriveInfo[] drives = DriveInfo.GetDrives(); - - var driveName = new StringBuilder(261); - var fsName = new StringBuilder(261); - - foreach (DriveInfo drive in drives) - { - if (!drive.IsReady) - continue; - - string root = drive.RootDirectory.FullName; - - if (!GetVolumeInformation( - root, - driveName, - driveName.Capacity, - out uint serialNumber, - out uint maxComponentLength, - out FileSystemFeature features, - fsName, - fsName.Capacity - )) - continue; - - driveName.Append($" ({drive.Name})"); - - yield return new SystemVolume(root, driveName.ToString(), fsName.ToString(), (ulong) drive.TotalFreeSpace, (ulong) drive.TotalSize, drive.DriveType); - } - } - - [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool GetVolumeInformation( - string rootPathName, - StringBuilder volumeNameBuffer, - int volumeNameSize, - out uint volumeSerialNumber, - out uint maximumComponentLength, - out FileSystemFeature fileSystemFlags, - StringBuilder fileSystemNameBuffer, - int nFileSystemNameSize - ); - - [Flags] - private enum FileSystemFeature : uint - { - /// - /// The file system preserves the case of file names when it places a name on disk. - /// - CasePreservedNames = 2, - - /// - /// The file system supports case-sensitive file names. - /// - CaseSensitiveSearch = 1, - - /// - /// The specified volume is a direct access (DAX) volume. This flag was introduced in Windows 10, version 1607. - /// - DaxVolume = 0x20000000, - - /// - /// The file system supports file-based compression. - /// - FileCompression = 0x10, - - /// - /// The file system supports named streams. - /// - NamedStreams = 0x40000, - - /// - /// The file system preserves and enforces access control lists (ACL). - /// - PersistentACLS = 8, - - /// - /// The specified volume is read-only. - /// - ReadOnlyVolume = 0x80000, - - /// - /// The volume supports a single sequential write. - /// - SequentialWriteOnce = 0x100000, - - /// - /// The file system supports the Encrypted File System (EFS). - /// - SupportsEncryption = 0x20000, - - /// - /// The specified volume supports extended attributes. An extended attribute is a piece of - /// application-specific metadata that an application can associate with a file and is not part - /// of the file's data. - /// - SupportsExtendedAttributes = 0x00800000, - - /// - /// The specified volume supports hard links. For more information, see Hard Links and Junctions. - /// - SupportsHardLinks = 0x00400000, - - /// - /// The file system supports object identifiers. - /// - SupportsObjectIDs = 0x10000, - - /// - /// The file system supports open by FileID. For more information, see FILE_ID_BOTH_DIR_INFO. - /// - SupportsOpenByFileId = 0x01000000, - - /// - /// The file system supports re-parse points. - /// - SupportsReparsePoints = 0x80, - - /// - /// The file system supports sparse files. - /// - SupportsSparseFiles = 0x40, - - /// - /// The volume supports transactions. - /// - SupportsTransactions = 0x200000, - - /// - /// The specified volume supports update sequence number (USN) journals. For more information, - /// see Change Journal Records. - /// - SupportsUsnJournal = 0x02000000, - - /// - /// The file system supports Unicode in file names as they appear on disk. - /// - UnicodeOnDisk = 4, - - /// - /// The specified volume is a compressed volume, for example, a DoubleSpace volume. - /// - VolumeIsCompressed = 0x8000, - - /// - /// The file system supports disk quotas. - /// - VolumeQuotas = 0x20 - } } - - #else - private static IEnumerable GetSystemDiskDrives_Posix() - { - return DriveInfo.GetDrives() - .Where(x => x.IsReady) - .Select(x => new SystemVolume(x)) - .ToArray(); - } - #endif -} }