mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-29 03:16:30 +03:00
add Save method
This commit is contained in:
@@ -11,6 +11,7 @@ namespace KeyKeeper.Services;
|
||||
internal class RecentFilesService : IRecentFilesService
|
||||
{
|
||||
private const string RecentFilesFilename = "recent-files.json";
|
||||
private static readonly JsonSerializerOptions jsonOptions = new() { WriteIndented = true };
|
||||
|
||||
// files are stored in reverse chronological order
|
||||
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)
|
||||
{
|
||||
RemoveIfExists(filename);
|
||||
|
||||
Reference in New Issue
Block a user