mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-29 05:55:21 -04:00
parent
563f5cb67b
commit
06c33373de
3 changed files with 24 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DiscordChatExporter.Domain.Discord.Models;
|
using DiscordChatExporter.Domain.Discord.Models;
|
||||||
|
using DiscordChatExporter.Domain.Internal;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Domain.Exporting
|
namespace DiscordChatExporter.Domain.Exporting
|
||||||
{
|
{
|
||||||
|
@ -127,8 +128,7 @@ namespace DiscordChatExporter.Domain.Exporting
|
||||||
buffer.Append($".{format.GetFileExtension()}");
|
buffer.Append($".{format.GetFileExtension()}");
|
||||||
|
|
||||||
// Replace invalid chars
|
// Replace invalid chars
|
||||||
foreach (var invalidChar in Path.GetInvalidFileNameChars())
|
PathEx.EscapePath(buffer);
|
||||||
buffer.Replace(invalidChar, '_');
|
|
||||||
|
|
||||||
return buffer.ToString();
|
return buffer.ToString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,11 @@ namespace DiscordChatExporter.Domain.Exporting
|
||||||
{
|
{
|
||||||
var originalFileName = Regex.Match(url, @".+/([^?]*)").Groups[1].Value;
|
var originalFileName = Regex.Match(url, @".+/([^?]*)").Groups[1].Value;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(originalFileName))
|
var fileName = !string.IsNullOrWhiteSpace(originalFileName) ?
|
||||||
return GetRandomSuffix();
|
$"{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
|
// 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