From 37fcee2f212f2ef722e3abb249b52e5273489485 Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Fri, 20 Nov 2020 16:56:30 +0200 Subject: [PATCH] Fix relative path extraction in ExportContext when base directory is empty Fixes #437 Fixes #434 --- DiscordChatExporter.Domain/Exporting/ExportContext.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/DiscordChatExporter.Domain/Exporting/ExportContext.cs b/DiscordChatExporter.Domain/Exporting/ExportContext.cs index e7dea5e..535ba4d 100644 --- a/DiscordChatExporter.Domain/Exporting/ExportContext.cs +++ b/DiscordChatExporter.Domain/Exporting/ExportContext.cs @@ -74,8 +74,11 @@ namespace DiscordChatExporter.Domain.Exporting { var filePath = await _mediaDownloader.DownloadAsync(url); - // We want relative path so that the output files can be copied around without breaking - var relativeFilePath = Path.GetRelativePath(Request.OutputBaseDirPath, filePath); + // We want relative path so that the output files can be copied around without breaking. + // Base directory path may be null if the file is stored at the root or relative to working directory. + var relativeFilePath = !string.IsNullOrWhiteSpace(Request.OutputBaseDirPath) + ? Path.GetRelativePath(Request.OutputBaseDirPath, filePath) + : filePath; // HACK: for HTML, we need to format the URL properly if (Request.Format == ExportFormat.HtmlDark || Request.Format == ExportFormat.HtmlLight)