From ea36c6ed47aab8bfc9b83fcf4654a8f5fa4cc303 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 18 Nov 2013 22:25:02 -0800 Subject: [PATCH] Create missing series folders on disk scan (if enabled) New: Option to create missing series folders during disk scans --- src/NzbDrone.Common/DiskProvider.cs | 15 ++++++++++++ .../Configuration/ConfigService.cs | 8 +++++++ .../Configuration/IConfigService.cs | 1 + .../MediaFiles/DiskScanService.cs | 15 +++++++++++- .../Series/Edit/EditSeriesViewTemplate.html | 6 ++--- .../MediaManagement/Sorting/ViewTemplate.html | 23 ++++++++++++++++++- 6 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Common/DiskProvider.cs b/src/NzbDrone.Common/DiskProvider.cs index ecaabb46d..5d0dd04a1 100644 --- a/src/NzbDrone.Common/DiskProvider.cs +++ b/src/NzbDrone.Common/DiskProvider.cs @@ -37,6 +37,7 @@ public interface IDiskProvider void FolderSetLastWriteTimeUtc(string path, DateTime dateTime); bool IsFileLocked(string path); string GetPathRoot(string path); + string GetParentFolder(string path); void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType); bool IsParent(string parentPath, string childPath); void SetFolderWriteTime(string path, DateTime time); @@ -366,6 +367,20 @@ public string GetPathRoot(string path) return Path.GetPathRoot(path); } + public string GetParentFolder(string path) + { + Ensure.That(() => path).IsValidPath(); + + var parent = Directory.GetParent(path); + + if (parent == null) + { + return null; + } + + return parent.FullName; + } + public void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType) { try diff --git a/src/NzbDrone.Core/Configuration/ConfigService.cs b/src/NzbDrone.Core/Configuration/ConfigService.cs index c480dd7cf..341605d68 100644 --- a/src/NzbDrone.Core/Configuration/ConfigService.cs +++ b/src/NzbDrone.Core/Configuration/ConfigService.cs @@ -282,6 +282,14 @@ public Boolean EnableFailedDownloadHandling set { SetValue("EnableFailedDownloadHandling", value); } } + public Boolean CreateEmptySeriesFolders + { + //TODO: only create if the parent folder exists (check first) + get { return GetValueBoolean("CreateEmptySeriesFolders", false); } + + set { SetValue("CreateEmptySeriesFolders", value); } + } + public string DownloadClientWorkingFolders { get { return GetValue("DownloadClientWorkingFolders", "_UNPACK_|_FAILED_"); } diff --git a/src/NzbDrone.Core/Configuration/IConfigService.cs b/src/NzbDrone.Core/Configuration/IConfigService.cs index 8df4fbaa2..654f07f73 100644 --- a/src/NzbDrone.Core/Configuration/IConfigService.cs +++ b/src/NzbDrone.Core/Configuration/IConfigService.cs @@ -42,6 +42,7 @@ public interface IConfigService Boolean AutoRedownloadFailed { get; set; } Boolean RemoveFailedDownloads { get; set; } Boolean EnableFailedDownloadHandling { get; set; } + Boolean CreateEmptySeriesFolders { get; set; } void SaveValues(Dictionary configValues); } } diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index 80df872a2..e0816dd1e 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -2,6 +2,7 @@ using System.Linq; using NLog; using NzbDrone.Common; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.EpisodeImport; @@ -25,17 +26,21 @@ public class DiskScanService : private readonly IMakeImportDecision _importDecisionMaker; private readonly IImportApprovedEpisodes _importApprovedEpisodes; private readonly ICommandExecutor _commandExecutor; + private readonly IConfigService _configService; private readonly Logger _logger; public DiskScanService(IDiskProvider diskProvider, IMakeImportDecision importDecisionMaker, IImportApprovedEpisodes importApprovedEpisodes, - ICommandExecutor commandExecutor, Logger logger) + ICommandExecutor commandExecutor, + IConfigService configService, + Logger logger) { _diskProvider = diskProvider; _importDecisionMaker = importDecisionMaker; _importApprovedEpisodes = importApprovedEpisodes; _commandExecutor = commandExecutor; + _configService = configService; _logger = logger; } @@ -46,6 +51,14 @@ private void Scan(Series series) if (!_diskProvider.FolderExists(series.Path)) { + if (_configService.CreateEmptySeriesFolders && + _diskProvider.FolderExists(_diskProvider.GetParentFolder(series.Path))) + { + _logger.Debug("Creating missing series folder: {0}", series.Path); + _diskProvider.CreateFolder(series.Path); + return; + } + _logger.Debug("Series folder doesn't exist: {0}", series.Path); return; } diff --git a/src/UI/Series/Edit/EditSeriesViewTemplate.html b/src/UI/Series/Edit/EditSeriesViewTemplate.html index 43e99398b..7fe6660b9 100644 --- a/src/UI/Series/Edit/EditSeriesViewTemplate.html +++ b/src/UI/Series/Edit/EditSeriesViewTemplate.html @@ -25,9 +25,9 @@
- - - + + +
diff --git a/src/UI/Settings/MediaManagement/Sorting/ViewTemplate.html b/src/UI/Settings/MediaManagement/Sorting/ViewTemplate.html index a09c0f37d..7bb516f42 100644 --- a/src/UI/Settings/MediaManagement/Sorting/ViewTemplate.html +++ b/src/UI/Settings/MediaManagement/Sorting/ViewTemplate.html @@ -1,5 +1,26 @@ 
- Season Folder + Folders + +
+ + +
+