public MovieFileMoveResult UpgradeMovieFile(MovieFile movieFile, LocalMovie localMovie, bool copyOnly = false) { _logger.Trace("Upgrading existing movie file."); var moveFileResult = new MovieFileMoveResult(); var existingFile = localMovie.Movie.MovieFileId > 0 ? localMovie.Movie.MovieFile : null; var rootFolder = _diskProvider.GetParentFolder(localMovie.Movie.Path); // If there are existing movie files and the root folder is missing, throw, so the old file isn't left behind during the import process. if (existingFile != null && !_diskProvider.FolderExists(rootFolder)) { throw new RootFolderNotFoundException($"Root folder '{rootFolder}' was not found."); } if (existingFile != null) { var movieFilePath = Path.Combine(localMovie.Movie.Path, existingFile.RelativePath); var subfolder = rootFolder.GetRelativePath(_diskProvider.GetParentFolder(movieFilePath)); if (_diskProvider.FileExists(movieFilePath)) { _logger.Debug("Removing existing movie file: {0}", existingFile); _recycleBinProvider.DeleteFile(movieFilePath, subfolder); } moveFileResult.OldFiles.Add(existingFile); _mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade); } if (copyOnly) { moveFileResult.MovieFile = _movieFileMover.CopyMovieFile(movieFile, localMovie); } else { moveFileResult.MovieFile = _movieFileMover.MoveMovieFile(movieFile, localMovie); } return(moveFileResult); }
public MovieFileMoveResult UpgradeMovieFile(MovieFile movieFile, LocalMovie localMovie, bool copyOnly = false) { _logger.Trace("Upgrading existing movie file."); var moveFileResult = new MovieFileMoveResult(); var existingFile = localMovie.Movie.MovieFile; if (existingFile != null) { var movieFilePath = Path.Combine(localMovie.Movie.Path, existingFile.RelativePath); if (_diskProvider.FileExists(movieFilePath)) { _logger.Debug("Removing existing movie file: {0}", existingFile); _recycleBinProvider.DeleteFile(movieFilePath); } moveFileResult.OldFiles.Add(existingFile); _mediaFileService.Delete(existingFile, DeleteMediaFileReason.Upgrade); } //Temporary for correctly getting path localMovie.Movie.MovieFileId = 1; localMovie.Movie.MovieFile = movieFile; if (copyOnly) { moveFileResult.MovieFile = _movieFileMover.CopyMovieFile(movieFile, localMovie); } else { moveFileResult.MovieFile = _movieFileMover.MoveMovieFile(movieFile, localMovie); } localMovie.Movie.MovieFileId = existingFile?.Id ?? 0; localMovie.Movie.MovieFile = existingFile; //_movieFileRenamer.RenameMoviePath(localMovie.Movie, false); return(moveFileResult); }