From 2e37c955a30992c6e41214bd68b40444d9f8ceb7 Mon Sep 17 00:00:00 2001 From: Abrynos <6608231+Abrynos@users.noreply.github.com> Date: Sun, 7 Oct 2018 03:17:32 +0200 Subject: [PATCH] Make custom UI with --path argument possible (#915) * make custom UI with --path argument possible * Move logic from SharedInfo to ArchiKestrel and Fix bug with GET /Api/WWW/Directory * No lazy instantiation * Make set of WebsiteDirectory private and add default value * i think i need to watch this: https://www.youtube.com/watch?v=X4rU02088Xc * Further remove logic from SharedInfo * Use relative path in default * Add comment explaining default value of relative path * Fix bug coming from relative path as default value * Revert changes to version that worked --- ArchiSteamFarm/IPC/ArchiKestrel.cs | 9 ++++++++- ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/IPC/ArchiKestrel.cs b/ArchiSteamFarm/IPC/ArchiKestrel.cs index cd2cf1f70..d91fd6b8b 100644 --- a/ArchiSteamFarm/IPC/ArchiKestrel.cs +++ b/ArchiSteamFarm/IPC/ArchiKestrel.cs @@ -34,6 +34,8 @@ namespace ArchiSteamFarm.IPC { internal static class ArchiKestrel { private const string ConfigurationFile = nameof(IPC) + ".config"; + internal static string WebsiteDirectory { get; private set; } = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.WebsiteDirectory); + internal static HistoryTarget HistoryTarget { get; private set; } private static IWebHost KestrelWebHost; @@ -60,9 +62,14 @@ namespace ArchiSteamFarm.IPC { // The order of dependency injection matters, pay attention to it IWebHostBuilder builder = new WebHostBuilder(); + string customDirectory = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.WebsiteDirectory); + if (Directory.Exists(customDirectory)) { + WebsiteDirectory = customDirectory; + } + // Set default directories builder.UseContentRoot(SharedInfo.HomeDirectory); - builder.UseWebRoot(SharedInfo.WebsiteDirectory); + builder.UseWebRoot(WebsiteDirectory); // Check if custom config is available string absoluteConfigDirectory = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.ConfigDirectory); diff --git a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs index b33898862..40f309330 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/WWWController.cs @@ -47,7 +47,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api { return BadRequest(new GenericResponse>(false, string.Format(Strings.ErrorIsEmpty, nameof(directory)))); } - string directoryPath = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.WebsiteDirectory, directory); + string directoryPath = Path.Combine(ArchiKestrel.WebsiteDirectory, directory); if (!Directory.Exists(directoryPath)) { return BadRequest(new GenericResponse>(false, string.Format(Strings.ErrorIsInvalid, directory))); }