mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-28 05:34:12 -04:00
parent
563f5cb67b
commit
06c33373de
3 changed files with 24 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using DiscordChatExporter.Domain.Discord.Models;
|
||||
using DiscordChatExporter.Domain.Internal;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Exporting
|
||||
{
|
||||
|
@ -127,8 +128,7 @@ namespace DiscordChatExporter.Domain.Exporting
|
|||
buffer.Append($".{format.GetFileExtension()}");
|
||||
|
||||
// Replace invalid chars
|
||||
foreach (var invalidChar in Path.GetInvalidFileNameChars())
|
||||
buffer.Replace(invalidChar, '_');
|
||||
PathEx.EscapePath(buffer);
|
||||
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
|
|
@ -27,10 +27,11 @@ namespace DiscordChatExporter.Domain.Exporting
|
|||
{
|
||||
var originalFileName = Regex.Match(url, @".+/([^?]*)").Groups[1].Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(originalFileName))
|
||||
return GetRandomSuffix();
|
||||
var fileName = !string.IsNullOrWhiteSpace(originalFileName) ?
|
||||
$"{Path.GetFileNameWithoutExtension(originalFileName)}-{GetRandomSuffix()}{Path.GetExtension(originalFileName)}" :
|
||||
GetRandomSuffix();
|
||||
|
||||
return $"{Path.GetFileNameWithoutExtension(originalFileName)}-{GetRandomSuffix()}{Path.GetExtension(originalFileName)}";
|
||||
return PathEx.EscapePath(fileName);
|
||||
}
|
||||
|
||||
// HACK: ConfigureAwait() is crucial here to enable sync-over-async in HtmlMessageWriter
|
||||
|
|
18
DiscordChatExporter.Domain/Internal/PathEx.cs
Normal file
18
DiscordChatExporter.Domain/Internal/PathEx.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal
|
||||
{
|
||||
internal static class PathEx
|
||||
{
|
||||
public static StringBuilder EscapePath(StringBuilder pathBuffer)
|
||||
{
|
||||
foreach (var invalidChar in Path.GetInvalidFileNameChars())
|
||||
pathBuffer.Replace(invalidChar, '_');
|
||||
|
||||
return pathBuffer;
|
||||
}
|
||||
|
||||
public static string EscapePath(string path) => EscapePath(new StringBuilder(path)).ToString();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue