diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs index 7cceb5e0fd..8015b32e30 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs +++ b/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] != '_') { 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}"; } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs index fcd9219bfd..c8a36349be 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs @@ -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}"); diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs index 5033968ed2..2632bd66d7 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs @@ -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) { diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs index fdf4697497..dd7c29101f 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs @@ -139,7 +139,7 @@ namespace ICSharpCode.SharpDevelop.Project if (newName == null) { return; } - if (!FileService.CheckFileName(newName)) { + if (!FileService.CheckDirectoryEntryName(newName)) { return; } string oldFileName = FileName; diff --git a/src/Main/Base/Project/Src/Services/File/FileService.cs b/src/Main/Base/Project/Src/Services/File/FileService.cs index 2771fa0fc6..6e4e12df40 100644 --- a/src/Main/Base/Project/Src/Services/File/FileService.cs +++ b/src/Main/Base/Project/Src/Services/File/FileService.cs @@ -148,29 +148,39 @@ namespace ICSharpCode.SharpDevelop #endregion /// - /// Checks if the file name is valid and shows a MessageBox if it is not valid. + /// Checks if the path is valid and shows a MessageBox if it is not valid. /// Do not use in non-UI methods. /// - 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; } /// - /// Checks that a single directory name is valid. + /// Checks that a single directory entry (file or subdirectory) name is valid. /// - /// A single directory name not the full path - public static bool CheckDirectoryName(string name) + /// A single file name not the full path + 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; } + /// + /// Checks that a single directory name is valid. + /// + /// A single directory name not the full path + [Obsolete("Use CheckDirectoryEntryName instead")] + public static bool CheckDirectoryName(string name) + { + return CheckDirectoryEntryName(name); + } + internal sealed class LoadFileWrapper { readonly IDisplayBinding binding; diff --git a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs index 4d4ff73e19..8852a72f7a 100644 --- a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs +++ b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs @@ -428,12 +428,21 @@ namespace ICSharpCode.Core /// /// Checks that a single directory name (not the full path) is valid. /// + [ObsoleteAttribute("Use IsValidDirectoryEntryName instead")] public static bool IsValidDirectoryName(string name) + { + return IsValidDirectoryEntryName(name); + } + + /// + /// Checks that a single directory name (not the full path) is valid. + /// + 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) {