diff options
author | Rory& <root@rory.gay> | 2024-01-24 02:31:56 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-24 17:05:25 +0100 |
commit | 03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch) | |
tree | e000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs | |
parent | Make RMU installable (diff) | |
download | MatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz |
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs')
-rw-r--r-- | MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs b/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs deleted file mode 100644 index c7a311d..0000000 --- a/MatrixRoomUtils.Desktop/MRUDesktopConfiguration.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections; -using System.Diagnostics.CodeAnalysis; -using ArcaneLibs.Extensions; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace MatrixRoomUtils.Desktop; - -public class MRUDesktopConfiguration { - private static ILogger<MRUDesktopConfiguration> _logger; - - [RequiresUnreferencedCode("Uses reflection binding")] - public MRUDesktopConfiguration(ILogger<MRUDesktopConfiguration> logger, IConfiguration config, HostBuilderContext host) { - _logger = logger; - logger.LogInformation("Loading configuration for environment: {}...", host.HostingEnvironment.EnvironmentName); - config.GetSection("MRUDesktop").Bind(this); - DataStoragePath = ExpandPath(DataStoragePath); - CacheStoragePath = ExpandPath(CacheStoragePath); - } - - public string DataStoragePath { get; set; } = ""; - public string CacheStoragePath { get; set; } = ""; - public string? SentryDsn { get; set; } - - private static string ExpandPath(string path, bool retry = true) { - _logger.LogInformation("Expanding path `{}`", path); - - if (path.StartsWith('~')) { - path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path[1..]); - } - - Environment.GetEnvironmentVariables().Cast<DictionaryEntry>().OrderByDescending(x => x.Key.ToString()!.Length).ToList().ForEach(x => { - path = path.Replace($"${x.Key}", x.Value.ToString()); - }); - - _logger.LogInformation("Expanded path to `{}`", path); - var tries = 0; - while (retry && path.ContainsAnyOf("~$".Split())) { - if (tries++ > 100) - throw new Exception($"Path `{path}` contains unrecognised environment variables"); - path = ExpandPath(path, false); - } - - return path; - } -} |