1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 02:07:41 +00:00
Sonarr/NzbDrone.Api/Logs/LogFileModule.cs
2013-07-28 16:13:14 -07:00

45 lines
No EOL
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Api.Logs
{
public class LogFileModule : NzbDroneRestModule<LogFileResource>
{
private readonly IAppFolderInfo _appFolderInfo;
private readonly IDiskProvider _diskProvider;
public LogFileModule(IAppFolderInfo appFolderInfo,
IDiskProvider diskProvider)
: base("log/files")
{
_appFolderInfo = appFolderInfo;
_diskProvider = diskProvider;
GetResourceAll = GetLogFiles;
}
private List<LogFileResource> GetLogFiles()
{
var result = new List<LogFileResource>();
var files = _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), SearchOption.TopDirectoryOnly);
for (int i = 0; i < files.Length; i++)
{
var file = files[i];
result.Add(new LogFileResource
{
Id = i + 1,
Filename = Path.GetFileName(file),
LastWriteTime = _diskProvider.GetLastFileWrite(file)
});
}
return result.OrderByDescending(l => l.LastWriteTime).ToList();
}
}
}