Browse Source

Fixed forum-5561: Preferences not saving if path exceeds certain length

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1190 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
17c49a84b4
  1. 20
      src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs
  2. 7
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs
  3. 4
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

20
src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs

@ -269,15 +269,20 @@ namespace ICSharpCode.SharpDevelop.Gui
StatusBarService.RedrawStatusbar(); 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) public Properties GetStoredMemento(IViewContent content)
{ {
if (content != null && content.FileName != null) { if (content != null && content.FileName != null) {
string directory = Path.Combine(PropertyService.ConfigDirectory, "temp"); string fullFileName = GetMementoFileName(content.FileName);
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.');
string fullFileName = Path.Combine(directory, fileName);
// check the file name length because it could be more than the maximum length of a file name // 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)) { if (FileUtility.IsValidFileName(fullFileName) && File.Exists(fullFileName)) {
@ -299,8 +304,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
Properties memento = ((IMementoCapable)content).CreateMemento(); Properties memento = ((IMementoCapable)content).CreateMemento();
string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); string fullFileName = GetMementoFileName(content.FileName);
string fullFileName = Path.Combine(directory, fileName);
if (FileUtility.IsValidFileName(fullFileName)) { if (FileUtility.IsValidFileName(fullFileName)) {
FileUtility.ObservedSave(new NamedFileOperationDelegate(memento.Save), fullFileName, FileErrorPolicy.Inform); FileUtility.ObservedSave(new NamedFileOperationDelegate(memento.Save), fullFileName, FileErrorPolicy.Inform);

7
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -296,9 +296,10 @@ namespace ICSharpCode.SharpDevelop.Project
static string GetPreferenceFileName(string projectFileName) static string GetPreferenceFileName(string projectFileName)
{ {
string directory = PropertyService.ConfigDirectory + "preferences"; string directory = PropertyService.ConfigDirectory + "preferences";
string fileName = projectFileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); return Path.Combine(directory,
string fullFileName = Path.Combine(directory, fileName + ".xml"); Path.GetFileName(projectFileName)
return fullFileName; + "." + projectFileName.ToLowerInvariant().GetHashCode().ToString("x")
+ ".xml");
} }
public static void SaveSolutionPreferences() public static void SaveSolutionPreferences()

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

@ -265,6 +265,8 @@ namespace ICSharpCode.Core
} }
} }
public static int MaxPathLength = 260;
/// <summary> /// <summary>
/// This method checks the file fileName if it is valid. /// This method checks the file fileName if it is valid.
/// </summary> /// </summary>
@ -273,7 +275,7 @@ namespace ICSharpCode.Core
// Fixme: 260 is the hardcoded maximal length for a path on my Windows XP system // 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. // 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; return false;
} }

Loading…
Cancel
Save