Add Language Module, use RemoveInvalidCharacters to Remove Emojis from Filenames

This commit is contained in:
Jonathan Jenne
2021-07-08 13:50:05 +02:00
parent 79202e379e
commit 917d8b71a0
4 changed files with 56 additions and 56 deletions

View File

@@ -2,21 +2,9 @@
Imports System.Text.RegularExpressions
Imports DevExpress.XtraEditors
Imports Independentsoft
Imports DigitalData.Modules.Language
Public Class ClassFilehandle
''' <summary>
''' Diese Funktion entfernt alle Zeichen aus dem übergebenen String
''' die in Dateinamen nicht erlaubt sind.
''' </summary>
''' <param name="Input">Der zu prüfende String</param>
''' <returns>String ohne nichterlaubte Zeichen</returns>
Public Shared Function InvalidCharacters(Input As String) As String
Dim replacement = ""
'Return System.Text.RegularExpressions.Regex.Replace(Input, "[\\/:*?""<>|\r\n]", "", System.Text.RegularExpressions.RegexOptions.Singleline)
Dim regexSearch = New String(Path.GetInvalidFileNameChars()) & New String(Path.GetInvalidPathChars())
Dim r = New Regex(String.Format("[{0}]", Regex.Escape(regexSearch)))
Return r.Replace(Input, replacement)
End Function
Public Shared Function Decide_FileHandle(pFilename As String, pHandletype As String)
Try
If pFilename.EndsWith(".msg") Then
@@ -115,7 +103,7 @@ Public Class ClassFilehandle
attachment_name = attachment.LongFileName
End If
If attachment.EmbeddedMessage IsNot Nothing Then
attachment_name = ClassFilehandle.InvalidCharacters(attachment_name)
attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
tempfile = Path.Combine(Path.GetTempPath, attachment_name & ".msg")
tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
@@ -129,7 +117,7 @@ Public Class ClassFilehandle
End If
ElseIf Not attachment_name.Contains("inline") Then
'Sonderzeichen entfernen
attachment_name = ClassFilehandle.InvalidCharacters(attachment_name)
attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
tempfile = Path.Combine(Path.GetTempPath, attachment_name)
tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
If tempfile <> "" Then