|
|
@ -4,7 +4,10 @@ using System.Net;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
|
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Messaging;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
using NzbDrone.Core.Tv.Events;
|
|
|
|
using NzbDrone.Core.Tv.Events;
|
|
|
@ -16,24 +19,29 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
void DeleteEpisodeFile(Series series, EpisodeFile episodeFile);
|
|
|
|
void DeleteEpisodeFile(Series series, EpisodeFile episodeFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MediaFileDeletionService : IDeleteMediaFiles, IHandleAsync<SeriesDeletedEvent>
|
|
|
|
public class MediaFileDeletionService : IDeleteMediaFiles,
|
|
|
|
|
|
|
|
IHandleAsync<SeriesDeletedEvent>,
|
|
|
|
|
|
|
|
IHandle<EpisodeFileDeletedEvent>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IRecycleBinProvider _recycleBinProvider;
|
|
|
|
private readonly IRecycleBinProvider _recycleBinProvider;
|
|
|
|
private readonly IMediaFileService _mediaFileService;
|
|
|
|
private readonly IMediaFileService _mediaFileService;
|
|
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public MediaFileDeletionService(IDiskProvider diskProvider,
|
|
|
|
public MediaFileDeletionService(IDiskProvider diskProvider,
|
|
|
|
IRecycleBinProvider recycleBinProvider,
|
|
|
|
IRecycleBinProvider recycleBinProvider,
|
|
|
|
IMediaFileService mediaFileService,
|
|
|
|
IMediaFileService mediaFileService,
|
|
|
|
ISeriesService seriesService,
|
|
|
|
ISeriesService seriesService,
|
|
|
|
|
|
|
|
IConfigService configService,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_recycleBinProvider = recycleBinProvider;
|
|
|
|
_recycleBinProvider = recycleBinProvider;
|
|
|
|
_mediaFileService = mediaFileService;
|
|
|
|
_mediaFileService = mediaFileService;
|
|
|
|
_seriesService = seriesService;
|
|
|
|
_seriesService = seriesService;
|
|
|
|
|
|
|
|
_configService = configService;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -105,5 +113,18 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[EventHandleOrder(EventHandleOrder.Last)]
|
|
|
|
|
|
|
|
public void Handle(EpisodeFileDeletedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var series = message.EpisodeFile.Series.Value;
|
|
|
|
|
|
|
|
var path = series.Path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_diskProvider.GetFiles(path, SearchOption.AllDirectories).Empty() &&
|
|
|
|
|
|
|
|
!_configService.CreateEmptySeriesFolders)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_diskProvider.DeleteFolder(path, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|