From e24d5ae83b4c7b0d570307a1e3c998d205ac748f Mon Sep 17 00:00:00 2001 From: Suterusu Kusanagi Date: Tue, 21 Jul 2026 15:41:11 -0400 Subject: [PATCH] Add check for empty files --- .../Pairs/VisibleUserDataDistributor.cs | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/PlayerSync/PlayerData/Pairs/VisibleUserDataDistributor.cs b/PlayerSync/PlayerData/Pairs/VisibleUserDataDistributor.cs index 4dd4b07a..243d118a 100644 --- a/PlayerSync/PlayerData/Pairs/VisibleUserDataDistributor.cs +++ b/PlayerSync/PlayerData/Pairs/VisibleUserDataDistributor.cs @@ -26,7 +26,7 @@ public class VisibleUserDataDistributor : DisposableMediatorSubscriberBase private readonly HashSet _usersToPushDataTo = []; private readonly SemaphoreSlim _pushDataSemaphore = new(1, 1); private readonly CancellationTokenSource _runtimeCts = new(); - private readonly HashSet _filesTooLargeHashes = new HashSet(); + private readonly HashSet _filesTooLargeOrEmptyHasBeenNotified = new HashSet(); public VisibleUserDataDistributor(ILogger logger, ApiController apiController, DalamudUtilService dalamudUtil, @@ -114,7 +114,7 @@ private void PushCharacterData(bool forced = false) if (_fileUploadTask == null || (_fileUploadTask?.IsCompleted ?? false) || forced) { _uploadingCharacterData = _lastCreatedData.DeepClone(); - RemoveFilesThatAreTooLarge(); // psync allows for 200 MiB to the server, 300 MiB once decompressed + RemoveFilesThatAreTooLargeOrEmpty(); // psync allows for 200 MiB to the server, 300 MiB once decompressed Logger.LogDebug("Starting UploadTask for {hash}, Reason: TaskIsNull: {task}, TaskIsCompleted: {taskCpl}, Forced: {frc}", _lastCreatedData.DataHash, _fileUploadTask == null, _fileUploadTask?.IsCompleted ?? false, forced); _fileUploadTask = _fileTransferManager.UploadFiles(_uploadingCharacterData, [.. _usersToPushDataTo]); @@ -139,41 +139,59 @@ private void PushCharacterData(bool forced = false) }); } - private void RemoveFilesThatAreTooLarge() + private void RemoveFilesThatAreTooLargeOrEmpty() { try { - // check for files that are larger than what the server allows for - Dictionary> filesTooLarge = new(); + Dictionary> filesTooLargeorEmpty = new(); foreach (var fileReplacements in _uploadingCharacterData!.FileReplacements) { foreach (var replacement in fileReplacements.Value) { + bool mustRemoveReplacementData = false; + var cache = _fileCacheManager.GetFileCacheByHash(replacement.Hash); if (cache == null) + { continue; + } - if ((cache.Size != null && cache.Size > 300 * 1024 * 1024) || (cache.CompressedSize != null && cache.CompressedSize > 200 * 1024 * 1024)) + // check for empty files + if (cache.Size != null && cache.Size == 0) + { + mustRemoveReplacementData = true; + } + + // check for files that are larger than what the server allows for + else if ((cache.Size != null && cache.Size > 300 * 1024 * 1024) || (cache.CompressedSize != null && cache.CompressedSize > 200 * 1024 * 1024)) { Logger.LogWarning("File {file} exceeds the size limit to sync and will not be sent. (300 MiB, or 200 MiB compressed)", cache.ResolvedFilepath); - if (!filesTooLarge.Keys.Contains(fileReplacements.Key)) - { - filesTooLarge[fileReplacements.Key] = new(); - } - filesTooLarge[fileReplacements.Key].Add(replacement); - if (!_filesTooLargeHashes.Contains(cache.Hash) && _configService.Current.ShowFileUnableToSyncNotification) + if (!_filesTooLargeOrEmptyHasBeenNotified.Contains(cache.Hash) && _configService.Current.ShowFileUnableToSyncNotification) { var isTexFile = cache.ResolvedFilepath.EndsWith(".tex", StringComparison.OrdinalIgnoreCase); var texInfo = isTexFile ? " Ensure it is compressed and consider reducing its resolution." : ""; Mediator.Publish(new NotificationMessage("File Size Error", $"The file {cache.ResolvedFilepath} exceeds the size limit and will not sync. (300 MiB, or 200 MiB compressed)" + texInfo, MareConfiguration.Models.NotificationType.Warning)); + _filesTooLargeOrEmptyHasBeenNotified.Add(cache.Hash); + } + + mustRemoveReplacementData = true; + } - _filesTooLargeHashes.Add(cache.Hash); + if (mustRemoveReplacementData) + { + if (!filesTooLargeorEmpty.ContainsKey(fileReplacements.Key)) + { + // create an empty replacements list for this ObjectKind if ObjectKind not already in the dictionary + filesTooLargeorEmpty[fileReplacements.Key] = []; } + filesTooLargeorEmpty[fileReplacements.Key].Add(replacement); } } } - foreach (var replacements in filesTooLarge) + + // check each ObjectKind that is present for any items in its replacement list to remove + foreach (var replacements in filesTooLargeorEmpty) { foreach (var replacement in replacements.Value) { @@ -183,7 +201,7 @@ private void RemoveFilesThatAreTooLarge() } catch (Exception ex) { - Logger.LogError(ex, "Failed to properly detect if files to upload are too large."); + Logger.LogError(ex, "Failed to properly detect if files to upload are too large or empty."); } } } \ No newline at end of file