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