Browse Source

Save docking layout into memory stream first, then write the contents to file.

This prevents corruption when there is an exception saving the layout.
pull/6/merge
Daniel Grunwald 13 years ago
parent
commit
e1b0e5249e
  1. 8
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

8
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

@ -320,8 +320,14 @@ namespace ICSharpCode.SharpDevelop.Gui
Directory.CreateDirectory(configPath); Directory.CreateDirectory(configPath);
string fileName = Path.Combine(configPath, current.FileName); string fileName = Path.Combine(configPath, current.FileName);
LoggingService.Info("Saving layout file: " + fileName); LoggingService.Info("Saving layout file: " + fileName);
// Save docking layout into memory stream first, then write the contents to file.
// This prevents corruption when there is an exception saving the layout.
var memoryStream = new MemoryStream();
dockingManager.SaveLayout(memoryStream);
memoryStream.Position = 0;
try { try {
dockingManager.SaveLayout(fileName); using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
memoryStream.CopyTo(stream);
} catch (IOException ex) { } catch (IOException ex) {
// ignore IO errors (maybe switching layout in two SharpDevelop instances at once?) // ignore IO errors (maybe switching layout in two SharpDevelop instances at once?)
LoggingService.Warn(ex); LoggingService.Warn(ex);

Loading…
Cancel
Save