Skip to content

Commit

Permalink
Don't allow invalid characters for profiles and mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora-yx committed Dec 16, 2024
1 parent 81d4537 commit b2c0e00
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 1 addition & 2 deletions SA-Mod-Manager/GamesInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ public static async Task<bool> UpdateLoader(Game game, string dlLink)
dl.StartDL();
if (success)
{
List<string> excludeFile = new();
excludeFile.Add("extlib");
List<string> excludeFile = ["extlib"];
await Util.ExtractWExcludeFile(pathFinal, game.modDirectory, excludeFile);
await Util.ExtractSpecificFile(pathFinal, "extlib", App.ConfigFolder);
File.Copy(App.CurrentGame.loader.loaderdllpath, App.CurrentGame.loader.dataDllPath, true);
Expand Down
6 changes: 5 additions & 1 deletion SA-Mod-Manager/ModsCommon/EditMod.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void okBtn_Click(object sender, RoutedEventArgs e)
return;
}


SaveMod(moddir);
((MainWindow)Application.Current.MainWindow).Save();
((MainWindow)Application.Current.MainWindow).Refresh();
Expand All @@ -143,15 +144,18 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
#region Properties Tab Functions
private void nameBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
if (Util.IsStringValid(nameBox.Text))
if (Util.IsStringValid(nameBox.Text) && Util.IsValidFileName(nameBox.Text))
{
modIDBox.Text = GenerateModID().Replace(" ", "");

if (editMod == false)
folderName = Path.Combine(App.CurrentGame.modDirectory, nameBox.Text);

UIHelper.EnableButton(ref okBtn);
}
else
{
UIHelper.DisableButton(ref okBtn);
modIDBox.Text = string.Empty;
}
}
Expand Down
2 changes: 1 addition & 1 deletion SA-Mod-Manager/Profile/EditProfile.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void UI_Cancel_Click(object sender, RoutedEventArgs e)

private void ProfileNameTextbox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
if (( string.IsNullOrWhiteSpace(ProfileNameTextbox.Text) == false) && (ProfileNameTextbox.Text.Length > 1))
if (( string.IsNullOrWhiteSpace(ProfileNameTextbox.Text) == false) && (ProfileNameTextbox.Text.Length > 1) && Util.IsValidFileName(ProfileNameTextbox.Text))
{
UIHelper.EnableButton(ref btnOK);
}
Expand Down
16 changes: 16 additions & 0 deletions SA-Mod-Manager/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,22 @@ public static bool IsStringValid(string str)
return !string.IsNullOrEmpty(str) && !string.IsNullOrWhiteSpace(str);
}

public static bool IsValidFileName(string filename)
{

char[] invalidChars = Path.GetInvalidFileNameChars();

// Check if the filename contains any invalid characters eg ?, " etc.
foreach (char c in invalidChars)
{
if (filename.Contains(c))
{
return false;
}
}

return true;
}


}
Expand Down

0 comments on commit b2c0e00

Please sign in to comment.