mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-06 05:05:42 +13:00
When loading setting set FilePath for new SettingsBase
This commit is contained in:
parent
df60a0db7e
commit
ffead0104a
2 changed files with 5 additions and 5 deletions
|
@ -36,7 +36,7 @@ namespace ShareX.HelpersLib
|
||||||
private static readonly SerializationType SerializationType = SerializationType.Json;
|
private static readonly SerializationType SerializationType = SerializationType.Json;
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public string FilePath { get; private set; }
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public string ApplicationVersion { get; set; }
|
public string ApplicationVersion { get; set; }
|
||||||
|
|
|
@ -57,9 +57,9 @@ public static bool Save(object obj, string filePath, SerializationType type, boo
|
||||||
{
|
{
|
||||||
lock (obj)
|
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))
|
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;
|
string typeName = typeof(T).Name;
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public static void Save(object obj, Stream stream, SerializationType type)
|
||||||
|
|
||||||
DebugHelper.WriteLine("{0} not found. Loading new instance.", typeName);
|
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)
|
public static T Load<T>(Stream stream, SerializationType type)
|
||||||
|
|
Loading…
Reference in a new issue