diff --git a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs index 7d15aacbae..d1f069e8bb 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs @@ -269,15 +269,20 @@ namespace ICSharpCode.SharpDevelop.Gui StatusBarService.RedrawStatusbar(); } + string GetMementoFileName(string contentName) + { + string directory = Path.Combine(PropertyService.ConfigDirectory, "temp"); + //string directoryName = Path.GetDirectoryName(contentName); + return Path.Combine(directory, + Path.GetFileName(contentName) + + "." + contentName.ToLowerInvariant().GetHashCode().ToString("x") + + ".xml"); + } + public Properties GetStoredMemento(IViewContent content) { if (content != null && content.FileName != null) { - string directory = Path.Combine(PropertyService.ConfigDirectory, "temp"); - if (!Directory.Exists(directory)) { - Directory.CreateDirectory(directory); - } - string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName); + string fullFileName = GetMementoFileName(content.FileName); // check the file name length because it could be more than the maximum length of a file name if (FileUtility.IsValidFileName(fullFileName) && File.Exists(fullFileName)) { @@ -299,8 +304,7 @@ namespace ICSharpCode.SharpDevelop.Gui } Properties memento = ((IMementoCapable)content).CreateMemento(); - string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName); + string fullFileName = GetMementoFileName(content.FileName); if (FileUtility.IsValidFileName(fullFileName)) { FileUtility.ObservedSave(new NamedFileOperationDelegate(memento.Save), fullFileName, FileErrorPolicy.Inform); diff --git a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs index 54e8cf0d1f..f0a07ed47c 100644 --- a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs +++ b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs @@ -296,9 +296,10 @@ namespace ICSharpCode.SharpDevelop.Project static string GetPreferenceFileName(string projectFileName) { string directory = PropertyService.ConfigDirectory + "preferences"; - string fileName = projectFileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); - string fullFileName = Path.Combine(directory, fileName + ".xml"); - return fullFileName; + return Path.Combine(directory, + Path.GetFileName(projectFileName) + + "." + projectFileName.ToLowerInvariant().GetHashCode().ToString("x") + + ".xml"); } public static void SaveSolutionPreferences() diff --git a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs index 289d71447b..58db370b0f 100644 --- a/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs +++ b/src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs @@ -265,6 +265,8 @@ namespace ICSharpCode.Core } } + public static int MaxPathLength = 260; + /// /// This method checks the file fileName if it is valid. /// @@ -273,7 +275,7 @@ namespace ICSharpCode.Core // Fixme: 260 is the hardcoded maximal length for a path on my Windows XP system // I can't find a .NET property or method for determining this variable. - if (fileName == null || fileName.Length == 0 || fileName.Length >= 260) { + if (fileName == null || fileName.Length == 0 || fileName.Length >= MaxPathLength) { return false; }