diff --git a/Journal.Core/Repositories/InMemoryFragmentRepository.cs b/Journal.Core/Repositories/InMemoryFragmentRepository.cs index b9f6cf5..22bf26a 100644 --- a/Journal.Core/Repositories/InMemoryFragmentRepository.cs +++ b/Journal.Core/Repositories/InMemoryFragmentRepository.cs @@ -11,7 +11,7 @@ public class InMemoryFragmentRepository : IFragmentRepository { lock (_lock) { - return _store.ToList(); + return [.. _store]; } } @@ -90,7 +90,7 @@ public class InMemoryFragmentRepository : IFragmentRepository if (string.IsNullOrWhiteSpace(q)) return []; lock (_lock) { - return _store.Where(f => f.Tags?.Any(t => !string.IsNullOrWhiteSpace(t) && t.Contains(q, StringComparison.OrdinalIgnoreCase)) == true).ToList(); + return [.. _store.Where(f => f.Tags?.Any(t => !string.IsNullOrWhiteSpace(t) && t.Contains(q, StringComparison.OrdinalIgnoreCase)) == true)]; } } @@ -100,7 +100,7 @@ public class InMemoryFragmentRepository : IFragmentRepository if (string.IsNullOrWhiteSpace(q)) return []; lock (_lock) { - return _store.Where(f => !string.IsNullOrWhiteSpace(f.Type) && f.Type.Trim().Contains(q, StringComparison.OrdinalIgnoreCase)).ToList(); + return [.. _store.Where(f => !string.IsNullOrWhiteSpace(f.Type) && f.Type.Trim().Contains(q, StringComparison.OrdinalIgnoreCase))]; } } @@ -119,7 +119,7 @@ public class InMemoryFragmentRepository : IFragmentRepository if (timeAfter.HasValue) results = results.Where(f => f.Time > timeAfter.Value); - return results.ToList(); + return [.. results]; } } } diff --git a/Journal.Core/Repositories/SqliteFragmentRepository.cs b/Journal.Core/Repositories/SqliteFragmentRepository.cs index 50c24a7..52e7d3a 100644 --- a/Journal.Core/Repositories/SqliteFragmentRepository.cs +++ b/Journal.Core/Repositories/SqliteFragmentRepository.cs @@ -82,9 +82,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) : var conn = _session.GetConnection(); var all = ReadAllFragments(conn); - return all - .Where(f => f.Tags.Any(t => t.Contains(q, StringComparison.OrdinalIgnoreCase))) - .ToList(); + return [.. all.Where(f => f.Tags.Any(t => t.Contains(q, StringComparison.OrdinalIgnoreCase)))]; } public List GetByType(string type) @@ -95,9 +93,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) : var conn = _session.GetConnection(); var all = ReadAllFragments(conn); - return all - .Where(f => f.Type.Contains(q, StringComparison.OrdinalIgnoreCase)) - .ToList(); + return [.. all.Where(f => f.Type.Contains(q, StringComparison.OrdinalIgnoreCase))]; } public List Search(string? type = null, string? tag = null, DateTimeOffset? timeAfter = null) @@ -115,7 +111,7 @@ public sealed class SqliteFragmentRepository(IDatabaseSessionService session) : if (timeAfter.HasValue) results = results.Where(f => f.Time > timeAfter.Value); - return results.ToList(); + return [.. results]; } // ── Private helpers ────────────────────────────────────────────── diff --git a/Journal.Core/Services/Database/DatabaseSessionService.cs b/Journal.Core/Services/Database/DatabaseSessionService.cs index f16f7c6..b051529 100644 --- a/Journal.Core/Services/Database/DatabaseSessionService.cs +++ b/Journal.Core/Services/Database/DatabaseSessionService.cs @@ -25,7 +25,6 @@ public sealed class DatabaseSessionService(IJournalDatabaseService database) : I lock (_lock) { - // If password or directory changed, close the old connection if (_connection is not null && (_password != password || _dataDirectory != dataDirectory)) { diff --git a/Journal.Core/Services/Vault/VaultStorageService.cs b/Journal.Core/Services/Vault/VaultStorageService.cs index f2dd18f..01851b0 100644 --- a/Journal.Core/Services/Vault/VaultStorageService.cs +++ b/Journal.Core/Services/Vault/VaultStorageService.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.IO.Compression; using System.Globalization; using System.Security.Cryptography; @@ -42,9 +43,9 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ { File.Delete(vaultFile); } - catch + catch (Exception ex) { - // Legacy file cleanup should never block loading. + Debug.WriteLine($"[VaultStorageService] Failed to delete legacy vault file {fileName}: {ex.Message}"); } continue; } @@ -59,11 +60,11 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ } catch (CryptographicException) { - // Wrong password for this vault file; continue trying others. + Debug.WriteLine($"[VaultStorageService] Decryption failed for {fileName} (likely wrong password)"); } - catch + catch (Exception ex) { - // Non-password vault read/decrypt/extract error; continue loading others. + Debug.WriteLine($"[VaultStorageService] Failed to load vault {fileName}: {ex.GetType().Name} - {ex.Message}"); } } @@ -177,7 +178,6 @@ public class VaultStorageService(IVaultCryptoService crypto) : IVaultStorageServ } } - // Final attempt should throw with the underlying exception if deletion still fails. Directory.Delete(dataDirectory, recursive: true); }