2010-10-17 10:22:48 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using NLog;
|
2010-10-20 18:49:23 -07:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-04-03 20:50:12 -07:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2010-10-17 10:22:48 -07:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
2011-04-09 18:34:36 -07:00
|
|
|
public class SyncProvider
|
2010-10-17 10:22:48 -07:00
|
|
|
{
|
2011-04-09 19:44:01 -07:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
private readonly DiskProvider _diskProvider;
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2010-10-17 10:22:48 -07:00
|
|
|
|
2011-04-20 00:44:13 -07:00
|
|
|
public SyncProvider(SeriesProvider seriesProvider, DiskProvider diskProvider)
|
2010-10-17 10:22:48 -07:00
|
|
|
{
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-03-08 23:40:48 -08:00
|
|
|
_diskProvider = diskProvider;
|
2010-10-17 10:22:48 -07:00
|
|
|
}
|
|
|
|
|
2011-03-08 23:40:48 -08:00
|
|
|
public List<String> GetUnmappedFolders(string path)
|
|
|
|
{
|
|
|
|
Logger.Debug("Generating list of unmapped folders");
|
|
|
|
if (String.IsNullOrEmpty(path))
|
2011-04-09 19:28:54 -07:00
|
|
|
throw new ArgumentException("Invalid path provided", "path");
|
|
|
|
|
|
|
|
var results = new List<String>();
|
2011-03-08 23:40:48 -08:00
|
|
|
|
|
|
|
if (!_diskProvider.FolderExists(path))
|
|
|
|
{
|
|
|
|
Logger.Debug("Path supplied does not exist: {0}", path);
|
2011-04-09 19:28:54 -07:00
|
|
|
return results;
|
2011-03-08 23:40:48 -08:00
|
|
|
}
|
|
|
|
|
2011-04-09 19:28:54 -07:00
|
|
|
|
2011-03-08 23:40:48 -08:00
|
|
|
foreach (string seriesFolder in _diskProvider.GetDirectories(path))
|
|
|
|
{
|
|
|
|
var cleanPath = Parser.NormalizePath(new DirectoryInfo(seriesFolder).FullName);
|
|
|
|
|
|
|
|
if (!_seriesProvider.SeriesPathExists(cleanPath))
|
|
|
|
results.Add(cleanPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger.Debug("{0} unmapped folders detected.", results.Count);
|
|
|
|
return results;
|
|
|
|
}
|
2010-10-17 10:22:48 -07:00
|
|
|
}
|
2011-04-09 19:44:01 -07:00
|
|
|
}
|