diff --git a/DiscordChatExporter.Cli/Verbs/ExportChannelVerb.cs b/DiscordChatExporter.Cli/Verbs/ExportChannelVerb.cs index 56b6c2f..0669701 100644 --- a/DiscordChatExporter.Cli/Verbs/ExportChannelVerb.cs +++ b/DiscordChatExporter.Cli/Verbs/ExportChannelVerb.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Threading.Tasks; using DiscordChatExporter.Cli.Verbs.Options; using DiscordChatExporter.Core.Helpers; @@ -32,15 +33,15 @@ namespace DiscordChatExporter.Cli.Verbs Options.After, Options.Before); // Generate file path if not set or is a directory - var filePath = Options.FilePath; - if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\")) + var filePath = Options.OutputPath; + if (filePath.IsBlank() || ExportHelper.IsDirectoryPath(filePath)) { // Generate default file name - var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, + var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, chatLog.Channel, Options.After, Options.Before); - // Append the file name to the file path - filePath += defaultFileName; + // Combine paths + filePath = Path.Combine(filePath ?? "", fileName); } // Export diff --git a/DiscordChatExporter.Cli/Verbs/ExportDirectMessagesVerb.cs b/DiscordChatExporter.Cli/Verbs/ExportDirectMessagesVerb.cs index 6695130..f49e6a9 100644 --- a/DiscordChatExporter.Cli/Verbs/ExportDirectMessagesVerb.cs +++ b/DiscordChatExporter.Cli/Verbs/ExportDirectMessagesVerb.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -48,17 +49,12 @@ namespace DiscordChatExporter.Cli.Verbs var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel, Options.After, Options.Before); - // Generate file path if not set or is a directory - var filePath = Options.FilePath; - if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\")) - { - // Generate default file name - var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, - chatLog.Channel, Options.After, Options.Before); + // Generate default file name + var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, + chatLog.Channel, Options.After, Options.Before); - // Append the file name to the file path - filePath += defaultFileName; - } + // Generate file path + var filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); diff --git a/DiscordChatExporter.Cli/Verbs/ExportGuildVerb.cs b/DiscordChatExporter.Cli/Verbs/ExportGuildVerb.cs index da7d6ea..3aae103 100644 --- a/DiscordChatExporter.Cli/Verbs/ExportGuildVerb.cs +++ b/DiscordChatExporter.Cli/Verbs/ExportGuildVerb.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -49,17 +50,12 @@ namespace DiscordChatExporter.Cli.Verbs var chatLog = await dataService.GetChatLogAsync(Options.GetToken(), channel, Options.After, Options.Before); - // Generate file path if not set or is a directory - var filePath = Options.FilePath; - if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\")) - { - // Generate default file name - var defaultFileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, - chatLog.Channel, Options.After, Options.Before); + // Generate default file name + var fileName = ExportHelper.GetDefaultExportFileName(Options.ExportFormat, chatLog.Guild, + chatLog.Channel, Options.After, Options.Before); - // Append the file name to the file path - filePath += defaultFileName; - } + // Generate file path + var filePath = Path.Combine(Options.OutputPath ?? "", fileName); // Export exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); diff --git a/DiscordChatExporter.Cli/Verbs/Options/ExportOptions.cs b/DiscordChatExporter.Cli/Verbs/Options/ExportOptions.cs index 436535a..766504d 100644 --- a/DiscordChatExporter.Cli/Verbs/Options/ExportOptions.cs +++ b/DiscordChatExporter.Cli/Verbs/Options/ExportOptions.cs @@ -9,8 +9,8 @@ namespace DiscordChatExporter.Cli.Verbs.Options [Option('f', "format", Default = ExportFormat.HtmlDark, HelpText = "Output file format.")] public ExportFormat ExportFormat { get; set; } - [Option('o', "output", Default = null, HelpText = "Output file path.")] - public string FilePath { get; set; } + [Option('o', "output", Default = null, HelpText = "Output file or directory path.")] + public string OutputPath { get; set; } [Option("after", Default = null, HelpText = "Limit to messages sent after this date.")] public DateTime? After { get; set; }