Skip to content

Commit

Permalink
Fix report file writing when ISO Disc Label contains non-safe characters
Browse files Browse the repository at this point in the history
  • Loading branch information
UniqProject committed Jan 21, 2023
1 parent fe2cacc commit a571337
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions BDInfo/FormReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
16 changes: 16 additions & 0 deletions BDInfo/ToolBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit a571337

Please sign in to comment.