mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-23 00:36:33 +03:00
add Save method
This commit is contained in:
@@ -11,6 +11,7 @@ namespace KeyKeeper.Services;
|
|||||||
internal class RecentFilesService : IRecentFilesService
|
internal class RecentFilesService : IRecentFilesService
|
||||||
{
|
{
|
||||||
private const string RecentFilesFilename = "recent-files.json";
|
private const string RecentFilesFilename = "recent-files.json";
|
||||||
|
private static readonly JsonSerializerOptions jsonOptions = new() { WriteIndented = true };
|
||||||
|
|
||||||
// files are stored in reverse chronological order
|
// files are stored in reverse chronological order
|
||||||
public ObservableCollection<RecentFile> RecentFiles { get; }
|
public ObservableCollection<RecentFile> RecentFiles { get; }
|
||||||
@@ -53,6 +54,18 @@ internal class RecentFilesService : IRecentFilesService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
var directory = Path.GetDirectoryName(recentFilesPath);
|
||||||
|
if (!string.IsNullOrEmpty(directory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = JsonSerializer.Serialize(RecentFiles, jsonOptions);
|
||||||
|
File.WriteAllText(recentFilesPath, payload);
|
||||||
|
}
|
||||||
|
|
||||||
public void Remember(string filename)
|
public void Remember(string filename)
|
||||||
{
|
{
|
||||||
RemoveIfExists(filename);
|
RemoveIfExists(filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user