mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
backup existing broken file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Logger;
|
||||
@@ -64,12 +65,24 @@ namespace Wox.Infrastructure.Storage
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadDefault()
|
||||
private void LoadDefault()
|
||||
{
|
||||
BackupOriginFile();
|
||||
_data = JsonConvert.DeserializeObject<T>("{}", _serializerSettings);
|
||||
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()
|
||||
{
|
||||
string serialized = JsonConvert.SerializeObject(_data, Formatting.Indented);
|
||||
|
||||
Reference in New Issue
Block a user