From 779ced6da10e35df9273b95928ed182cddecee27 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 2 Dec 2023 22:36:15 +0100 Subject: Reformat --- MatrixRoomUtils.Desktop/FileStorageProvider.cs | 4 +++- MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs | 8 +++++--- MatrixRoomUtils.Desktop/MRUStorageWrapper.cs | 6 +++--- MatrixRoomUtils.Desktop/MainWindow.axaml.cs | 4 ++-- MatrixRoomUtils.Desktop/MatrixRoomUtils.Desktop.csproj | 13 ------------- MatrixRoomUtils.Desktop/Program.cs | 2 +- 6 files changed, 14 insertions(+), 23 deletions(-) (limited to 'MatrixRoomUtils.Desktop') diff --git a/MatrixRoomUtils.Desktop/FileStorageProvider.cs b/MatrixRoomUtils.Desktop/FileStorageProvider.cs index 7f73cf3..0429d1a 100644 --- a/MatrixRoomUtils.Desktop/FileStorageProvider.cs +++ b/MatrixRoomUtils.Desktop/FileStorageProvider.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using ArcaneLibs.Extensions; using LibMatrix.Extensions; @@ -19,13 +20,14 @@ public class FileStorageProvider : IStorageProvider { new Logger(new LoggerFactory()).LogInformation("test"); Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}"); TargetPath = targetPath; - if(!Directory.Exists(targetPath)) { + if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } } public async Task SaveObjectAsync(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson()); + [RequiresUnreferencedCode("This API uses reflection to deserialize JSON")] public async Task LoadObjectAsync(string key) => JsonSerializer.Deserialize(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); public Task ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key))); diff --git a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs b/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs index 4f265ee..c7a311d 100644 --- a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs +++ b/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Diagnostics.CodeAnalysis; using ArcaneLibs.Extensions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -9,6 +10,7 @@ namespace MatrixRoomUtils.Desktop; public class MRUDesktopConfiguration { private static ILogger _logger; + [RequiresUnreferencedCode("Uses reflection binding")] public MRUDesktopConfiguration(ILogger logger, IConfiguration config, HostBuilderContext host) { _logger = logger; logger.LogInformation("Loading configuration for environment: {}...", host.HostingEnvironment.EnvironmentName); @@ -24,7 +26,7 @@ public class MRUDesktopConfiguration { private static string ExpandPath(string path, bool retry = true) { _logger.LogInformation("Expanding path `{}`", path); - if (path.StartsWith("~")) { + if (path.StartsWith('~')) { path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path[1..]); } @@ -34,8 +36,8 @@ public class MRUDesktopConfiguration { _logger.LogInformation("Expanded path to `{}`", path); var tries = 0; - while(retry && path.ContainsAnyOf("~$".Split())) { - if(tries++ > 100) + while (retry && path.ContainsAnyOf("~$".Split())) { + if (tries++ > 100) throw new Exception($"Path `{path}` contains unrecognised environment variables"); path = ExpandPath(path, false); } diff --git a/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs b/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs index bc01774..8a44518 100644 --- a/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs +++ b/MatrixRoomUtils.Desktop/MRUStorageWrapper.cs @@ -7,7 +7,7 @@ namespace MatrixRoomUtils.Desktop; public class MRUStorageWrapper(TieredStorageService storageService, HomeserverProviderService homeserverProviderService) { public async Task?> GetAllTokens() { - if(!await storageService.DataStorageProvider.ObjectExistsAsync("mru.tokens")) { + if (!await storageService.DataStorageProvider.ObjectExistsAsync("mru.tokens")) { return null; } return await storageService.DataStorageProvider.LoadObjectAsync>("mru.tokens") ?? @@ -15,7 +15,7 @@ public class MRUStorageWrapper(TieredStorageService storageService, HomeserverPr } public async Task GetCurrentToken() { - if(!await storageService.DataStorageProvider.ObjectExistsAsync("token")) { + if (!await storageService.DataStorageProvider.ObjectExistsAsync("token")) { return null; } var currentToken = await storageService.DataStorageProvider.LoadObjectAsync("token"); @@ -41,7 +41,7 @@ public class MRUStorageWrapper(TieredStorageService storageService, HomeserverPr tokens.Add(loginResponse); await storageService.DataStorageProvider.SaveObjectAsync("mru.tokens", tokens); - if(await GetCurrentToken() is null) + if (await GetCurrentToken() is null) await SetCurrentToken(loginResponse); } diff --git a/MatrixRoomUtils.Desktop/MainWindow.axaml.cs b/MatrixRoomUtils.Desktop/MainWindow.axaml.cs index 0bed93d..9db59c5 100644 --- a/MatrixRoomUtils.Desktop/MainWindow.axaml.cs +++ b/MatrixRoomUtils.Desktop/MainWindow.axaml.cs @@ -28,7 +28,7 @@ public partial class MainWindow : Window { // for (int i = 0; i < 100; i++) { - // roomList.Children.Add(new RoomListEntry()); + // roomList.Children.Add(new RoomListEntry()); // } } @@ -45,6 +45,6 @@ public partial class MainWindow : Window { // public Command // protected void LoadedCommand() { - // _logger.LogInformation("async command"); + // _logger.LogInformation("async command"); // } } diff --git a/MatrixRoomUtils.Desktop/MatrixRoomUtils.Desktop.csproj b/MatrixRoomUtils.Desktop/MatrixRoomUtils.Desktop.csproj index 012f74b..6d9fc0e 100644 --- a/MatrixRoomUtils.Desktop/MatrixRoomUtils.Desktop.csproj +++ b/MatrixRoomUtils.Desktop/MatrixRoomUtils.Desktop.csproj @@ -46,17 +46,4 @@ Always - - - - - - NavigationStack.axaml - Code - - - RoomListEntry.axaml - Code - - diff --git a/MatrixRoomUtils.Desktop/Program.cs b/MatrixRoomUtils.Desktop/Program.cs index 6e299eb..aa1d9d3 100644 --- a/MatrixRoomUtils.Desktop/Program.cs +++ b/MatrixRoomUtils.Desktop/Program.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; using Microsoft.Extensions.Hosting; using Tmds.DBus.Protocol; -- cgit 1.5.1