When loading setting set FilePath for new SettingsBase

This commit is contained in:
Jaex 2016-01-28 09:42:39 +02:00
parent df60a0db7e
commit ffead0104a
2 changed files with 5 additions and 5 deletions

View file

@ -36,7 +36,7 @@ public abstract class SettingsBase<T> where T : SettingsBase<T>, new()
private static readonly SerializationType SerializationType = SerializationType.Json;
[Browsable(false)]
public string FilePath { get; private set; }
public string FilePath { get; set; }
[Browsable(false)]
public string ApplicationVersion { get; set; }

View file

@ -57,9 +57,9 @@ public static bool Save(object obj, string filePath, SerializationType type, boo
{
lock (obj)
{
string tempFilePath = filePath + ".temp";
Helpers.CreateDirectoryIfNotExist(filePath);
Helpers.CreateDirectoryIfNotExist(filePath, true);
string tempFilePath = filePath + ".temp";
using (FileStream fs = new FileStream(tempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
@ -118,7 +118,7 @@ public static void Save(object obj, Stream stream, SerializationType type)
}
}
public static T Load<T>(string path, SerializationType type, bool checkBackup = true) where T : new()
public static T Load<T>(string path, SerializationType type, bool checkBackup = true) where T : SettingsBase<T>, new()
{
string typeName = typeof(T).Name;
@ -157,7 +157,7 @@ public static T Load<T>(string path, SerializationType type, bool checkBackup =
DebugHelper.WriteLine("{0} not found. Loading new instance.", typeName);
return new T();
return new T() { FilePath = path };
}
public static T Load<T>(Stream stream, SerializationType type)