From 157d9dcabaa6a8fc3c4652245dc7531feea0027e Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 14 Nov 2017 19:08:45 +0200 Subject: [PATCH] Fixed errors when attempting to save server logs with illegal characters in the server name --- .../BarotraumaShared/Source/Networking/ServerLog.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Networking/ServerLog.cs b/Barotrauma/BarotraumaShared/Source/Networking/ServerLog.cs index 75c01d533..cea50e2e8 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/ServerLog.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/ServerLog.cs @@ -136,14 +136,16 @@ namespace Barotrauma.Networking } } - string fileName = serverName+"_"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".txt"; + string fileName = serverName + "_" + DateTime.Now.ToShortDateString() + "_" + DateTime.Now.ToShortTimeString() + ".txt"; - fileName = fileName.Replace(":", ""); - fileName = fileName.Replace("../", ""); - fileName = fileName.Replace("/", ""); + var invalidChars = Path.GetInvalidFileNameChars(); + foreach (char invalidChar in invalidChars) + { + fileName = fileName.Replace(invalidChar.ToString(), ""); + } string filePath = Path.Combine(SavePath, fileName); - + try { File.WriteAllLines(filePath, lines.Select(l => l.Text));