From a571337c9b6c573e1522d2fa37feb33d26700b2a Mon Sep 17 00:00:00 2001 From: UniqProject <3046095+UniqProject@users.noreply.github.com> Date: Sat, 21 Jan 2023 14:07:20 +0100 Subject: [PATCH] Fix report file writing when ISO Disc Label contains non-safe characters --- BDInfo/FormReport.cs | 2 ++ BDInfo/ToolBox.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/BDInfo/FormReport.cs b/BDInfo/FormReport.cs index f691539df0..fd9b868f78 100644 --- a/BDInfo/FormReport.cs +++ b/BDInfo/FormReport.cs @@ -47,6 +47,8 @@ public void Generate( string reportName = string.Format( CultureInfo.InvariantCulture, "BDINFO.{0}.txt", BDROM.VolumeLabel); + + reportName = ToolBox.GetSafeFileName(reportName); reportFile = File.CreateText(Path.Combine(Environment.CurrentDirectory, reportName)); } diff --git a/BDInfo/ToolBox.cs b/BDInfo/ToolBox.cs index a85c366bbc..672e2a3758 100644 --- a/BDInfo/ToolBox.cs +++ b/BDInfo/ToolBox.cs @@ -49,5 +49,21 @@ public static string ReadString( return val; } + + public static string GetSafeFileName(string fileName) + { + string outFileName = fileName; + + foreach (char lDisallowed in System.IO.Path.GetInvalidFileNameChars()) + { + outFileName = outFileName.Replace(lDisallowed.ToString(), ""); + } + foreach (char lDisallowed in System.IO.Path.GetInvalidPathChars()) + { + outFileName = outFileName.Replace(lDisallowed.ToString(), ""); + } + + return outFileName; + } } } \ No newline at end of file