From c5319bb4ae9606e07d62525a022e5a67f85a7d43 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 4 Aug 2014 23:41:56 -0400 Subject: update playlist xml saving --- .../Configuration/ConfigurationHelper.cs | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Common/Configuration/ConfigurationHelper.cs') diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs index 64c2e87de..8c904b0db 100644 --- a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs +++ b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs @@ -36,21 +36,25 @@ namespace MediaBrowser.Common.Configuration configuration = Activator.CreateInstance(type); } - // Take the object we just got and serialize it back to bytes - var newBytes = xmlSerializer.SerializeToBytes(configuration); - - // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) + using (var stream = new MemoryStream()) { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); - } + xmlSerializer.SerializeToStream(configuration, stream); - return configuration; - } + // Take the object we just got and serialize it back to bytes + var newBytes = stream.ToArray(); + + // If the file didn't exist before, or if something has changed, re-save + if (buffer == null || !buffer.SequenceEqual(newBytes)) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + // Save it after load in case we got new items + File.WriteAllBytes(path, newBytes); + } + + return configuration; + } + } /// /// Reads an xml configuration file from the file system -- cgit v1.2.3