timelapse/Timelapse/Data/RecentFileService.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2021-12-28 07:25:39 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Timelapse.Api;
namespace Timelapse.Data
{
public class RecentFileService
{
public static RecentFileService RFS;
public static string RecentFile=Path.Combine(Extensions.UserData,"recent.txt");
public RecentFileService()
{
if(File.Exists(RecentFile))
{
Files = File.ReadAllLines(RecentFile).ToList();
}else{
Files = new List<string>();
}
}
public void Add(string file)
{
if(Files.Contains(file))
{
Files.Remove(file);
}
Files.Add(file);
File.WriteAllLines(RecentFile,Files);
}
static List<string> Files;
public Task<RecentFile[]> GetRecentFilesAsync()
{
var rng = new Random();
return Task.FromResult(Files.Select(name => new RecentFile
{
Fullpath=name
}).ToArray());
}
}
}