mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
backup existing broken file
This commit is contained in:
parent
e5c98e61c8
commit
a5f5098beb
1 changed files with 14 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue