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
if (name.Length == 0 || !char.IsLetter(name[0]) && name[0] != '_') { if (name.Length == 0 || !char.IsLetter(name[0]) && name[0] != '_') {
return "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.ProjectNameMustStartWithLetter}"; return "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.ProjectNameMustStartWithLetter}";
} }
if (!FileUtility.IsValidDirectoryName(solution) if (!FileUtility.IsValidDirectoryEntryName(solution)
|| !FileUtility.IsValidDirectoryName(name)) || !FileUtility.IsValidDirectoryEntryName(name))
{ {
return "${res:ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.IllegalProjectNameError}"; 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
} }
} }
if (MSBuildInternals.Escape(newName) != newName if (MSBuildInternals.Escape(newName) != newName
|| !FileUtility.IsValidDirectoryName(newName) || !FileUtility.IsValidDirectoryEntryName(newName)
|| newName.Contains("'")) || newName.Contains("'"))
{ {
MessageService.ShowMessage("${res:Dialog.EditAvailableConfigurationsDialog.InvalidName}"); 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
if (newName == null) { if (newName == null) {
return; return;
} }
if (!FileService.CheckFileName(newName)) { if (!FileService.CheckDirectoryEntryName(newName)) {
return;
}
if (!FileService.CheckDirectoryName(newName)) {
return; return;
} }
if (String.Compare(Text, newName, true) == 0) { 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
if (newName == null) { if (newName == null) {
return; return;
} }
if (!FileService.CheckFileName(newName)) { if (!FileService.CheckDirectoryEntryName(newName)) {
return; return;
} }
string oldFileName = FileName; string oldFileName = FileName;

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

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

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

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

Loading…
Cancel
Save