mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
backup existing broken file
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
@@ -64,12 +65,24 @@ namespace Wox.Infrastructure.Storage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadDefault()
|
private void LoadDefault()
|
||||||
{
|
{
|
||||||
|
BackupOriginFile();
|
||||||
_data = JsonConvert.DeserializeObject<T>("{}", _serializerSettings);
|
_data = JsonConvert.DeserializeObject<T>("{}", _serializerSettings);
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BackupOriginFile()
|
||||||
|
{
|
||||||
|
var timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fffffff", CultureInfo.CurrentUICulture);
|
||||||
|
var directory = Path.GetDirectoryName(FilePath).NonNull();
|
||||||
|
var originName = Path.GetFileNameWithoutExtension(FilePath);
|
||||||
|
var backupName = $"{originName}-{timestamp}{FileSuffix}";
|
||||||
|
var backupPath = Path.Combine(directory, backupName);
|
||||||
|
File.Copy(FilePath, backupPath, true);
|
||||||
|
// todo give user notification for the backup process
|
||||||
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
||||||
|
|||||||
Reference in New Issue
Block a user