mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-19 11:06:28 +03:00
add Load method
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using KeyKeeper.Models;
|
||||
|
||||
namespace KeyKeeper.Services;
|
||||
@@ -24,6 +26,33 @@ internal class RecentFilesService : IRecentFilesService
|
||||
recentFilesPath = Path.Combine(appDataDirectory, RecentFilesFilename);
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
RecentFiles.Clear();
|
||||
|
||||
if (!File.Exists(recentFilesPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var content = File.ReadAllText(recentFilesPath);
|
||||
var loadedFiles = JsonSerializer.Deserialize<List<RecentFile>>(content) ?? new List<RecentFile>();
|
||||
|
||||
foreach (var recentFile in loadedFiles
|
||||
.OrderByDescending(file => file.LastOpened)
|
||||
.Take(maxEntries))
|
||||
{
|
||||
RecentFiles.Add(recentFile);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore broken data and continue with empty recent files
|
||||
}
|
||||
}
|
||||
|
||||
public void Remember(string filename)
|
||||
{
|
||||
RemoveIfExists(filename);
|
||||
|
||||
Reference in New Issue
Block a user