diff --git a/LightlessSync.sln b/LightlessSync.sln index 5b7ca3c..768301b 100644 --- a/LightlessSync.sln +++ b/LightlessSync.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.1.32328.378 +# Visual Studio Version 18 +VisualStudioVersion = 18.0.11205.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{585B740D-BA2C-429B-9CF3-B2D223423748}" ProjectSection(SolutionItems) = preProject @@ -22,24 +22,24 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|Any CPU.ActiveCfg = Release|x64 - {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|Any CPU.Build.0 = Release|x64 + {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|Any CPU.Build.0 = Debug|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|x64.ActiveCfg = Debug|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Debug|x64.Build.0 = Debug|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Release|Any CPU.ActiveCfg = Release|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Release|Any CPU.Build.0 = Release|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Release|x64.ActiveCfg = Release|x64 {BB929046-4CD2-B174-EBAA-C756AC3AC8DA}.Release|x64.Build.0 = Release|x64 - {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|Any CPU.Build.0 = Release|Any CPU + {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|Any CPU.Build.0 = Debug|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|x64.ActiveCfg = Debug|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Debug|x64.Build.0 = Debug|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Release|Any CPU.ActiveCfg = Release|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Release|Any CPU.Build.0 = Release|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Release|x64.ActiveCfg = Release|Any CPU {A4E42AFA-5045-7E81-937F-3A320AC52987}.Release|x64.Build.0 = Release|Any CPU - {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|Any CPU.ActiveCfg = Debug|x64 - {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|Any CPU.Build.0 = Debug|x64 + {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|Any CPU.ActiveCfg = Release|x64 + {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|Any CPU.Build.0 = Release|x64 {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|x64.ActiveCfg = Debug|x64 {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Debug|x64.Build.0 = Debug|x64 {C104F6BE-9CC4-9CF7-271C-5C3A1F646601}.Release|Any CPU.ActiveCfg = Release|x64 diff --git a/LightlessSync/FileCache/CacheMonitor.cs b/LightlessSync/FileCache/CacheMonitor.cs index 486e11e..0dc0cb7 100644 --- a/LightlessSync/FileCache/CacheMonitor.cs +++ b/LightlessSync/FileCache/CacheMonitor.cs @@ -72,7 +72,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase { while (_dalamudUtil.IsOnFrameworkThread && !token.IsCancellationRequested) { - await Task.Delay(1).ConfigureAwait(false); + await Task.Delay(1, token).ConfigureAwait(false); } RecalculateFileCacheSize(token); @@ -101,8 +101,8 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase } record WatcherChange(WatcherChangeTypes ChangeType, string? OldPath = null); - private readonly Dictionary _watcherChanges = new Dictionary(StringComparer.OrdinalIgnoreCase); - private readonly Dictionary _lightlessChanges = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _watcherChanges = new(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _lightlessChanges = new(StringComparer.OrdinalIgnoreCase); public void StopMonitoring() { @@ -128,7 +128,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase } var fsType = FileSystemHelper.GetFilesystemType(_configService.Current.CacheFolder, _dalamudUtil.IsWine); - if (fsType == FileSystemHelper.FilesystemType.NTFS) + if (fsType == FileSystemHelper.FilesystemType.NTFS && !_dalamudUtil.IsWine) { StorageisNTFS = true; Logger.LogInformation("Lightless Storage is on NTFS drive: {isNtfs}", StorageisNTFS); @@ -403,94 +403,99 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase public void RecalculateFileCacheSize(CancellationToken token) { - if (string.IsNullOrEmpty(_configService.Current.CacheFolder) || - !Directory.Exists(_configService.Current.CacheFolder)) + var folder = _configService.Current.CacheFolder; + if (string.IsNullOrWhiteSpace(folder) || !Directory.Exists(folder)) { FileCacheSize = 0; return; } FileCacheSize = -1; - bool isWine = _dalamudUtil?.IsWine ?? false; try { var drive = DriveInfo.GetDrives() - .FirstOrDefault(d => _configService.Current.CacheFolder - .StartsWith(d.Name, StringComparison.OrdinalIgnoreCase)); - + .FirstOrDefault(d => folder.StartsWith(d.Name, StringComparison.OrdinalIgnoreCase)); if (drive != null) FileCacheDriveFree = drive.AvailableFreeSpace; } catch (Exception ex) { - Logger.LogWarning(ex, "Could not determine drive size for storage folder {folder}", _configService.Current.CacheFolder); + Logger.LogWarning(ex, "Could not determine drive size for storage folder {folder}", folder); } - var files = Directory.EnumerateFiles(_configService.Current.CacheFolder) - .Select(f => new FileInfo(f)) - .OrderBy(f => f.LastAccessTime) - .ToList(); - - long totalSize = 0; + List files; + try + { + files = [.. new DirectoryInfo(folder) + .EnumerateFiles("*", SearchOption.TopDirectoryOnly) + .OrderBy(f => f.LastAccessTimeUtc)]; + } + catch (Exception ex) + { + Logger.LogWarning(ex, "Failed to enumerate files in {folder}", folder); + FileCacheSize = 0; + return; + } + + var entries = new List<(FileInfo fi, long size)>(files.Count); + long total = 0; foreach (var f in files) { token.ThrowIfCancellationRequested(); - try + long size; + if (_configService.Current.UseCompactor) { - long size = 0; - - if (!isWine) + try { - try - { - size = _fileCompactor.GetFileSizeOnDisk(f); - } - catch (Exception ex) - { - Logger.LogTrace(ex, "GetFileSizeOnDisk failed for {file}, using fallback length", f.FullName); - size = f.Length; - } + size = _fileCompactor.GetFileSizeOnDisk(f); + if (size < 0) size = f.Length; } - else + catch (Exception ex) { + Logger.LogTrace(ex, "GetFileSizeOnDisk failed for {file}, using Length", f.FullName); size = f.Length; } - - totalSize += size; - } - catch (Exception ex) + } + else { - Logger.LogTrace(ex, "Error getting size for {file}", f.FullName); + size = f.Length; } + + + entries.Add((f, size)); + total += size; } - FileCacheSize = totalSize; + FileCacheSize = total; - var maxCacheInBytes = (long)(_configService.Current.MaxLocalCacheInGiB * 1024d * 1024d * 1024d); - if (FileCacheSize < maxCacheInBytes) - return; + var maxCacheBytes = (long)(_configService.Current.MaxLocalCacheInGiB * 1024d * 1024d * 1024d); + if (FileCacheSize < maxCacheBytes) return; - var maxCacheBuffer = maxCacheInBytes * 0.05d; + var buffer = (long)(maxCacheBytes * 0.05d); + var target = maxCacheBytes - buffer; - while (FileCacheSize > maxCacheInBytes - (long)maxCacheBuffer && files.Count > 0) + var i = 0; + while (i < entries.Count && FileCacheSize > target) { - var oldestFile = files[0]; + token.ThrowIfCancellationRequested(); + var (fi, sz) = entries[i]; try { - long fileSize = oldestFile.Length; - File.Delete(oldestFile.FullName); - FileCacheSize -= fileSize; + File.Delete(fi.FullName); + FileCacheSize -= sz; } catch (Exception ex) { - Logger.LogTrace(ex, "Failed to delete old file {file}", oldestFile.FullName); + Logger.LogTrace(ex, "Failed to delete old file {file}", fi.FullName); + } + finally + { + i++; } - - files.RemoveAt(0); } } @@ -510,12 +515,19 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase protected override void Dispose(bool disposing) { base.Dispose(disposing); - _scanCancellationTokenSource?.Cancel(); + // Disposing of file system watchers PenumbraWatcher?.Dispose(); LightlessWatcher?.Dispose(); + + // Disposing of cancellation token sources + _scanCancellationTokenSource?.CancelDispose(); + _scanCancellationTokenSource?.Dispose(); _penumbraFswCts?.CancelDispose(); + _penumbraFswCts?.Dispose(); _lightlessFswCts?.CancelDispose(); + _lightlessFswCts?.Dispose(); _periodicCalculationTokenSource?.CancelDispose(); + _periodicCalculationTokenSource?.Dispose(); } private void FullFileScan(CancellationToken ct) @@ -593,7 +605,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase List entitiesToRemove = []; List entitiesToUpdate = []; - object sync = new(); + Lock sync = new(); Thread[] workerThreads = new Thread[threadCount]; ConcurrentQueue fileCaches = new(_fileDbManager.GetAllFileCaches()); diff --git a/LightlessSync/FileCache/FileCacheManager.cs b/LightlessSync/FileCache/FileCacheManager.cs index 29d2aa7..40feede 100644 --- a/LightlessSync/FileCache/FileCacheManager.cs +++ b/LightlessSync/FileCache/FileCacheManager.cs @@ -41,11 +41,8 @@ public sealed class FileCacheManager : IHostedService private string CsvBakPath => _csvPath + ".bak"; - private static string NormalizeSeparators(string path) - { - return path.Replace("/", "\\", StringComparison.Ordinal) + private static string NormalizeSeparators(string path) => path.Replace("/", "\\", StringComparison.Ordinal) .Replace("\\\\", "\\", StringComparison.Ordinal); - } private static string NormalizePrefixedPathKey(string prefixedPath) { diff --git a/LightlessSync/UI/CharaDataHubUi.McdOnline.cs b/LightlessSync/UI/CharaDataHubUi.McdOnline.cs index 2703acc..d4aeaa9 100644 --- a/LightlessSync/UI/CharaDataHubUi.McdOnline.cs +++ b/LightlessSync/UI/CharaDataHubUi.McdOnline.cs @@ -463,12 +463,16 @@ internal sealed partial class CharaDataHubUi else { var desc = pose.Description; - if (ImGui.InputTextWithHint("##description", "Description", ref desc, 100)) + if (desc != null) { - pose.Description = desc; - updateDto.UpdatePoseList(); + if (ImGui.InputTextWithHint("##description", "Description", ref desc, 100)) + { + pose.Description = desc; + updateDto.UpdatePoseList(); + } + ImGui.SameLine(); } - ImGui.SameLine(); + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete")) { updateDto.RemovePose(pose); diff --git a/LightlessSync/UI/DownloadUi.cs b/LightlessSync/UI/DownloadUi.cs index 337fb41..1902124 100644 --- a/LightlessSync/UI/DownloadUi.cs +++ b/LightlessSync/UI/DownloadUi.cs @@ -23,6 +23,7 @@ public class DownloadUi : WindowMediatorSubscriberBase private readonly UiSharedService _uiShared; private readonly PairProcessingLimiter _pairProcessingLimiter; private readonly ConcurrentDictionary _uploadingPlayers = new(); + private readonly Dictionary _smoothed = []; private bool _notificationDismissed = true; private int _lastDownloadStateHash = 0; @@ -204,8 +205,18 @@ public class DownloadUi : WindowMediatorSubscriberBase foreach (var transfer in _currentDownloads.ToList()) { - var screenPos = _dalamudUtilService.WorldToScreen(transfer.Key.GetGameObject()); - if (screenPos == Vector2.Zero) continue; + var transferKey = transfer.Key; + var rawPos = _dalamudUtilService.WorldToScreen(transferKey.GetGameObject()); + //If RawPos is zero, remove it from smoothed dictionary + if (rawPos == Vector2.Zero) + { + _smoothed.Remove(transferKey); + continue; + } + //Smoothing out the movement and fix jitter around the position. + Vector2 screenPos = _smoothed.TryGetValue(transferKey, out var lastPos) ? (rawPos - lastPos).Length() < 4f ? lastPos : rawPos : rawPos; + _smoothed[transferKey] = screenPos; + var totalBytes = transfer.Value.Sum(c => c.Value.TotalBytes); var transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes); diff --git a/LightlessSync/UI/Models/Changelog.cs b/LightlessSync/UI/Models/Changelog.cs deleted file mode 100644 index 23d26c4..0000000 --- a/LightlessSync/UI/Models/Changelog.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace LightlessSync.UI.Models -{ - public class ChangelogFile - { - public string Tagline { get; init; } = string.Empty; - public string Subline { get; init; } = string.Empty; - public List Changelog { get; init; } = new(); - public List? Credits { get; init; } - } - - public class ChangelogEntry - { - public string Name { get; init; } = string.Empty; - public string Date { get; init; } = string.Empty; - public string Tagline { get; init; } = string.Empty; - public bool? IsCurrent { get; init; } - public string? Message { get; init; } - public List? Versions { get; init; } - } - - public class ChangelogVersion - { - public string Number { get; init; } = string.Empty; - public List Items { get; init; } = new(); - } - - public class CreditCategory - { - public string Category { get; init; } = string.Empty; - public List Items { get; init; } = new(); - } - - public class CreditItem - { - public string Name { get; init; } = string.Empty; - public string Role { get; init; } = string.Empty; - } - - public class CreditsFile - { - public List Credits { get; init; } = new(); - } -} \ No newline at end of file diff --git a/LightlessSync/UI/Models/ChangelogEntry.cs b/LightlessSync/UI/Models/ChangelogEntry.cs new file mode 100644 index 0000000..919a6da --- /dev/null +++ b/LightlessSync/UI/Models/ChangelogEntry.cs @@ -0,0 +1,12 @@ +namespace LightlessSync.UI.Models +{ + public class ChangelogEntry + { + public string Name { get; init; } = string.Empty; + public string Date { get; init; } = string.Empty; + public string Tagline { get; init; } = string.Empty; + public bool? IsCurrent { get; init; } + public string? Message { get; init; } + public List? Versions { get; init; } + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/ChangelogFile.cs b/LightlessSync/UI/Models/ChangelogFile.cs new file mode 100644 index 0000000..37997c8 --- /dev/null +++ b/LightlessSync/UI/Models/ChangelogFile.cs @@ -0,0 +1,10 @@ +namespace LightlessSync.UI.Models +{ + public class ChangelogFile + { + public string Tagline { get; init; } = string.Empty; + public string Subline { get; init; } = string.Empty; + public List Changelog { get; init; } = new(); + public List? Credits { get; init; } + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/ChangelogVersion.cs b/LightlessSync/UI/Models/ChangelogVersion.cs new file mode 100644 index 0000000..b70ace6 --- /dev/null +++ b/LightlessSync/UI/Models/ChangelogVersion.cs @@ -0,0 +1,8 @@ +namespace LightlessSync.UI.Models +{ + public class ChangelogVersion + { + public string Number { get; init; } = string.Empty; + public List Items { get; init; } = []; + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/CreditCategory.cs b/LightlessSync/UI/Models/CreditCategory.cs new file mode 100644 index 0000000..5b25cca --- /dev/null +++ b/LightlessSync/UI/Models/CreditCategory.cs @@ -0,0 +1,8 @@ +namespace LightlessSync.UI.Models +{ + public class CreditCategory + { + public string Category { get; init; } = string.Empty; + public List Items { get; init; } = []; + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/CreditItem.cs b/LightlessSync/UI/Models/CreditItem.cs new file mode 100644 index 0000000..ae0c4be --- /dev/null +++ b/LightlessSync/UI/Models/CreditItem.cs @@ -0,0 +1,8 @@ +namespace LightlessSync.UI.Models +{ + public class CreditItem + { + public string Name { get; init; } = string.Empty; + public string Role { get; init; } = string.Empty; + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/CreditsFile.cs b/LightlessSync/UI/Models/CreditsFile.cs new file mode 100644 index 0000000..b6b6a83 --- /dev/null +++ b/LightlessSync/UI/Models/CreditsFile.cs @@ -0,0 +1,7 @@ +namespace LightlessSync.UI.Models +{ + public class CreditsFile + { + public List Credits { get; init; } = []; + } +} \ No newline at end of file diff --git a/LightlessSync/UI/Models/LightlessNotification.cs b/LightlessSync/UI/Models/LightlessNotification.cs index 3c6edea..4ae49a4 100644 --- a/LightlessSync/UI/Models/LightlessNotification.cs +++ b/LightlessSync/UI/Models/LightlessNotification.cs @@ -1,7 +1,7 @@ -using Dalamud.Interface; using LightlessSync.LightlessConfiguration.Models; -using System.Numerics; + namespace LightlessSync.UI.Models; + public class LightlessNotification { public string Id { get; set; } = Guid.NewGuid().ToString(); @@ -20,13 +20,3 @@ public class LightlessNotification public bool IsAnimatingOut { get; set; } = false; public uint? SoundEffectId { get; set; } = null; } -public class LightlessNotificationAction -{ - public string Id { get; set; } = Guid.NewGuid().ToString(); - public string Label { get; set; } = string.Empty; - public FontAwesomeIcon Icon { get; set; } = FontAwesomeIcon.None; - public Vector4 Color { get; set; } = Vector4.One; - public Action OnClick { get; set; } = _ => { }; - public bool IsPrimary { get; set; } = false; - public bool IsDestructive { get; set; } = false; -} \ No newline at end of file diff --git a/LightlessSync/UI/Models/LightlessNotificationAction.cs b/LightlessSync/UI/Models/LightlessNotificationAction.cs new file mode 100644 index 0000000..7c9fd53 --- /dev/null +++ b/LightlessSync/UI/Models/LightlessNotificationAction.cs @@ -0,0 +1,15 @@ +using Dalamud.Interface; +using System.Numerics; + +namespace LightlessSync.UI.Models; + +public class LightlessNotificationAction +{ + public string Id { get; set; } = Guid.NewGuid().ToString(); + public string Label { get; set; } = string.Empty; + public FontAwesomeIcon Icon { get; set; } = FontAwesomeIcon.None; + public Vector4 Color { get; set; } = Vector4.One; + public Action OnClick { get; set; } = _ => { }; + public bool IsPrimary { get; set; } = false; + public bool IsDestructive { get; set; } = false; +} \ No newline at end of file diff --git a/LightlessSync/UI/UIColors.cs b/LightlessSync/UI/UIColors.cs index dadb9f0..2b2e65c 100644 --- a/LightlessSync/UI/UIColors.cs +++ b/LightlessSync/UI/UIColors.cs @@ -96,10 +96,10 @@ namespace LightlessSync.UI public static Vector4 HexToRgba(string hexColor) { hexColor = hexColor.TrimStart('#'); - int r = int.Parse(hexColor.Substring(0, 2), NumberStyles.HexNumber); - int g = int.Parse(hexColor.Substring(2, 2), NumberStyles.HexNumber); - int b = int.Parse(hexColor.Substring(4, 2), NumberStyles.HexNumber); - int a = hexColor.Length == 8 ? int.Parse(hexColor.Substring(6, 2), NumberStyles.HexNumber) : 255; + int r = int.Parse(hexColor[..2], NumberStyles.HexNumber); + int g = int.Parse(hexColor[2..4], NumberStyles.HexNumber); + int b = int.Parse(hexColor[4..6], NumberStyles.HexNumber); + int a = hexColor.Length == 8 ? int.Parse(hexColor[6..8], NumberStyles.HexNumber) : 255; return new Vector4(r / 255f, g / 255f, b / 255f, a / 255f); } diff --git a/LightlessSync/UI/UISharedService.cs b/LightlessSync/UI/UISharedService.cs index ae9c7a9..243de3d 100644 --- a/LightlessSync/UI/UISharedService.cs +++ b/LightlessSync/UI/UISharedService.cs @@ -70,7 +70,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase private bool _isOneDrive = false; private bool _isPenumbraDirectory = false; private bool _moodlesExists = false; - private Dictionary _oauthTokenExpiry = new(); + private readonly Dictionary _oauthTokenExpiry = []; private bool _penumbraExists = false; private bool _petNamesExists = false; private int _serverSelectionIndex = -1; @@ -1067,7 +1067,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase { using (ImRaii.Disabled(_discordOAuthUIDs == null)) { - var aliasPairs = _discordOAuthUIDs?.Result?.Select(t => new UIDAliasPair(t.Key, t.Value)).ToList() ?? [new UIDAliasPair(item.UID ?? null, null)]; + var aliasPairs = _discordOAuthUIDs?.Result?.Select(t => new UidAliasPair(t.Key, t.Value)).ToList() ?? [new UidAliasPair(item.UID ?? null, null)]; var uidComboName = "UID###" + item.CharacterName + item.WorldId + serverUri + indexOffset + aliasPairs.Count; DrawCombo(uidComboName, aliasPairs, (v) => @@ -1253,6 +1253,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase UidFont.Dispose(); GameFont.Dispose(); MediumFont.Dispose(); + _discordOAuthGetCts.Dispose(); } private static void CenterWindow(float width, float height, ImGuiCond cond = ImGuiCond.None) @@ -1325,6 +1326,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase return result; } + public sealed record IconScaleData(Vector2 IconSize, Vector2 NormalizedIconScale, float OffsetX, float IconScaling); - private record UIDAliasPair(string? UID, string? Alias); + private sealed record UidAliasPair(string? UID, string? Alias); } \ No newline at end of file diff --git a/LightlessSync/UI/UpdateNotesUi.cs b/LightlessSync/UI/UpdateNotesUi.cs index 54a45f0..5fb2480 100644 --- a/LightlessSync/UI/UpdateNotesUi.cs +++ b/LightlessSync/UI/UpdateNotesUi.cs @@ -742,7 +742,7 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase using var changelogStream = assembly.GetManifestResourceStream("LightlessSync.Changelog.changelog.yaml"); if (changelogStream != null) { - using var reader = new StreamReader(changelogStream, Encoding.UTF8, true, 128); + using var reader = new StreamReader(changelogStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, 128); var yaml = reader.ReadToEnd(); _changelog = deserializer.Deserialize(yaml) ?? new(); } @@ -751,7 +751,7 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase using var creditsStream = assembly.GetManifestResourceStream("LightlessSync.Changelog.credits.yaml"); if (creditsStream != null) { - using var reader = new StreamReader(creditsStream, Encoding.UTF8, true, 128); + using var reader = new StreamReader(creditsStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, 128); var yaml = reader.ReadToEnd(); _credits = deserializer.Deserialize(yaml) ?? new(); } diff --git a/LightlessSync/Utils/Crypto.cs b/LightlessSync/Utils/Crypto.cs index 11f08fd..0e8879f 100644 --- a/LightlessSync/Utils/Crypto.cs +++ b/LightlessSync/Utils/Crypto.cs @@ -46,7 +46,7 @@ public static class Crypto return hash; return _hashListPlayersSHA256[playerToHash] = - BitConverter.ToString(_sha256CryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(playerToHash.Item1 + playerToHash.Item2.ToString()))).Replace("-", "", StringComparison.Ordinal); + Convert.ToHexString(_sha256CryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(playerToHash.Item1 + playerToHash.Item2.ToString()))); } public static string GetHash256(this string stringToHash) @@ -60,7 +60,7 @@ public static class Crypto return hash; return _hashListSHA256[stringToCompute] = - BitConverter.ToString(_sha256CryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(stringToCompute))).Replace("-", "", StringComparison.Ordinal); + Convert.ToHexString(_sha256CryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(stringToCompute))); } #pragma warning restore SYSLIB0021 // Type or member is obsolete } \ No newline at end of file diff --git a/LightlessSync/Utils/SeStringUtils.cs b/LightlessSync/Utils/SeStringUtils.cs index 7507515..6cb1686 100644 --- a/LightlessSync/Utils/SeStringUtils.cs +++ b/LightlessSync/Utils/SeStringUtils.cs @@ -57,10 +57,9 @@ public static class SeStringUtils continue; var hasColor = fragment.Color.HasValue; - Vector4 color = default; if (hasColor) { - color = fragment.Color!.Value; + Vector4 color = fragment.Color!.Value; builder.PushColorRgba(color); } @@ -233,7 +232,7 @@ public static class SeStringUtils protected abstract byte ChunkType { get; } } - private class ColorPayload : AbstractColorPayload + private sealed class ColorPayload : AbstractColorPayload { protected override byte ChunkType => 0x13; @@ -247,12 +246,12 @@ public static class SeStringUtils public ColorPayload(Vector4 color) : this(new Vector3(color.X, color.Y, color.Z)) { } } - private class ColorEndPayload : AbstractColorEndPayload + private sealed class ColorEndPayload : AbstractColorEndPayload { protected override byte ChunkType => 0x13; } - private class GlowPayload : AbstractColorPayload + private sealed class GlowPayload : AbstractColorPayload { protected override byte ChunkType => 0x14; @@ -266,7 +265,7 @@ public static class SeStringUtils public GlowPayload(Vector4 color) : this(new Vector3(color.X, color.Y, color.Z)) { } } - private class GlowEndPayload : AbstractColorEndPayload + private sealed class GlowEndPayload : AbstractColorEndPayload { protected override byte ChunkType => 0x14; }