Browse Source

Project Browser: don't allow user to rename files to a new including "/" or "\", as using those invalid file names would cause a crash.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5773 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
3032c5504e
  1. 4
      src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs
  2. 2
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs
  3. 5
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs
  4. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs
  5. 26
      src/Main/Base/Project/Src/Services/File/FileService.cs
  6. 11
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

4
src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs

@ -288,8 +288,8 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -288,8 +288,8 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
if (name.Length == 0 || !char.IsLetter(name[0]) && name[0] != '_') {
return "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.ProjectNameMustStartWithLetter}";
}
if (!FileUtility.IsValidDirectoryName(solution)
|| !FileUtility.IsValidDirectoryName(name))
if (!FileUtility.IsValidDirectoryEntryName(solution)
|| !FileUtility.IsValidDirectoryEntryName(name))
{
return "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.IllegalProjectNameError}";
}

2
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs

@ -182,7 +182,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -182,7 +182,7 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
if (MSBuildInternals.Escape(newName) != newName
|| !FileUtility.IsValidDirectoryName(newName)
|| !FileUtility.IsValidDirectoryEntryName(newName)
|| newName.Contains("'"))
{
MessageService.ShowMessage("${res:Dialog.EditAvailableConfigurationsDialog.InvalidName}");

5
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs

@ -478,10 +478,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -478,10 +478,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (newName == null) {
return;
}
if (!FileService.CheckFileName(newName)) {
return;
}
if (!FileService.CheckDirectoryName(newName)) {
if (!FileService.CheckDirectoryEntryName(newName)) {
return;
}
if (String.Compare(Text, newName, true) == 0) {

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs

@ -139,7 +139,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -139,7 +139,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (newName == null) {
return;
}
if (!FileService.CheckFileName(newName)) {
if (!FileService.CheckDirectoryEntryName(newName)) {
return;
}
string oldFileName = FileName;

26
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -148,29 +148,39 @@ namespace ICSharpCode.SharpDevelop @@ -148,29 +148,39 @@ namespace ICSharpCode.SharpDevelop
#endregion
/// <summary>
/// Checks if the file name is valid <b>and shows a MessageBox if it is not valid</b>.
/// Checks if the path is valid <b>and shows a MessageBox if it is not valid</b>.
/// Do not use in non-UI methods.
/// </summary>
public static bool CheckFileName(string fileName)
public static bool CheckFileName(string path)
{
if (FileUtility.IsValidPath(fileName))
if (FileUtility.IsValidPath(path))
return true;
MessageService.ShowMessage(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.SaveFile.InvalidFileNameError}", new string[,] {{"FileName", fileName}}));
MessageService.ShowMessage(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.SaveFile.InvalidFileNameError}", new string[,] {{"FileName", path}}));
return false;
}
/// <summary>
/// Checks that a single directory name is valid.
/// Checks that a single directory entry (file or subdirectory) name is valid.
/// </summary>
/// <param name="name">A single directory name not the full path</param>
public static bool CheckDirectoryName(string name)
/// <param name="name">A single file name not the full path</param>
public static bool CheckDirectoryEntryName(string name)
{
if (FileUtility.IsValidDirectoryName(name))
if (FileUtility.IsValidDirectoryEntryName(name))
return true;
MessageService.ShowMessage(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.SaveFile.InvalidFileNameError}", new string[,] {{"FileName", name}}));
return false;
}
/// <summary>
/// Checks that a single directory name is valid.
/// </summary>
/// <param name="name">A single directory name not the full path</param>
[Obsolete("Use CheckDirectoryEntryName instead")]
public static bool CheckDirectoryName(string name)
{
return CheckDirectoryEntryName(name);
}
internal sealed class LoadFileWrapper
{
readonly IDisplayBinding binding;

11
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -428,12 +428,21 @@ namespace ICSharpCode.Core @@ -428,12 +428,21 @@ namespace ICSharpCode.Core
/// <summary>
/// Checks that a single directory name (not the full path) is valid.
/// </summary>
[ObsoleteAttribute("Use IsValidDirectoryEntryName instead")]
public static bool IsValidDirectoryName(string name)
{
return IsValidDirectoryEntryName(name);
}
/// <summary>
/// Checks that a single directory name (not the full path) is valid.
/// </summary>
public static bool IsValidDirectoryEntryName(string name)
{
if (!IsValidPath(name)) {
return false;
}
if (name.IndexOfAny(new char[]{Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar}) >= 0) {
if (name.IndexOfAny(new char[]{Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar,Path.VolumeSeparatorChar}) >= 0) {
return false;
}
if (name.Trim(' ').Length == 0) {

Loading…
Cancel
Save