Fixed sub editor crashing when attempting to use illegal characters in the filename. Closes #207

This commit is contained in:
Joonas Rikkonen
2018-01-08 15:34:33 +02:00
parent 32deb06e51
commit 778b1a78ad
2 changed files with 9 additions and 5 deletions
@@ -379,11 +379,14 @@ namespace Barotrauma
return false; return false;
} }
if (nameBox.Text.Contains("../")) foreach (char illegalChar in Path.GetInvalidFileNameChars())
{ {
DebugConsole.ThrowError("Illegal symbols in filename (../)"); if (nameBox.Text.Contains(illegalChar))
nameBox.Flash(); {
return false; GUI.AddMessage(TextManager.Get("SubNameIllegalCharsWarning").Replace("[illegalchar]", illegalChar.ToString()), Color.Red, 3.0f);
nameBox.Flash();
return false;
}
} }
string savePath = nameBox.Text + ".sub"; string savePath = nameBox.Text + ".sub";
@@ -226,6 +226,7 @@
<ShowGaps>Gaps</ShowGaps> <ShowGaps>Gaps</ShowGaps>
<PreviouslyUsedLabel>Previously used</PreviouslyUsedLabel> <PreviouslyUsedLabel>Previously used</PreviouslyUsedLabel>
<SubNameMissingWarning>Name your submarine before saving it.</SubNameMissingWarning> <SubNameMissingWarning>Name your submarine before saving it.</SubNameMissingWarning>
<SubNameIllegalCharsWarning>Illegal symbols in filename ([illegalchar])</SubNameIllegalCharsWarning>
<SubSavedNotification>Submarine saved to [filepath].</SubSavedNotification> <SubSavedNotification>Submarine saved to [filepath].</SubSavedNotification>
<SaveSubDialogHeader>Save submarine</SaveSubDialogHeader> <SaveSubDialogHeader>Save submarine</SaveSubDialogHeader>
<SaveSubDialogName>Name</SaveSubDialogName> <SaveSubDialogName>Name</SaveSubDialogName>