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