Trim dots at the end of filenames on Windows

Closes #977
This commit is contained in:
Tyrrrz
2023-01-03 10:34:53 +02:00
parent db45b49af7
commit d9c06bacda
2 changed files with 52 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace DiscordChatExporter.Core.Utils;
@@ -15,6 +16,14 @@ public static class PathEx
foreach (var c in path)
buffer.Append(!InvalidFileNameChars.Contains(c) ? c : '_');
// File names cannot end with a dot on Windows
// https://github.com/Tyrrrz/DiscordChatExporter/issues/977
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
while (buffer.Length > 0 && buffer[^1] == '.')
buffer.Remove(buffer.Length - 1, 1);
}
return buffer.ToString();
}