Example #1
0
        public void DeleteFolder(string path)
        {
            _logger.Info("Attempting to send '{0}' to recycling bin", path);
            var recyclingBin = _configService.RecycleBin;

            if (string.IsNullOrWhiteSpace(recyclingBin))
            {
                _logger.Info("Recycling Bin has not been configured, deleting permanently. {0}", path);
                _diskProvider.DeleteFolder(path, true);
                _logger.Debug("Folder has been permanently deleted: {0}", path);
            }

            else
            {
                var destination = Path.Combine(recyclingBin, new DirectoryInfo(path).Name);

                _logger.Debug("Moving '{0}' to '{1}'", path, destination);
                _diskTransferService.TransferFolder(path, destination, TransferMode.Move);

                _logger.Debug("Setting last accessed: {0}", path);
                _diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow);
                foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories))
                {
                    if (OsInfo.IsWindows)
                    {
                        //TODO: Better fix than this for non-Windows?
                        _diskProvider.FileSetLastWriteTime(file, DateTime.UtcNow);
                    }
                }

                _logger.Debug("Folder has been moved to the recycling bin: {0}", destination);
            }
        }
        private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, string fileTime)
        {
            DateTime airDate;

            if (DateTime.TryParse(fileDate + ' ' + fileTime, out airDate))
            {
                // avoiding false +ve checks and set date skewing by not using UTC (Windows)
                DateTime oldDateTime = _diskProvider.FileGetLastWriteUtc(filePath);

                if (!DateTime.Equals(airDate, oldDateTime))
                {
                    try
                    {
                        _diskProvider.FileSetLastWriteTime(filePath, airDate);
                        _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, airDate);

                        return(true);
                    }

                    catch (Exception ex)
                    {
                        _logger.WarnException("Unable to set date of file [" + filePath + "]", ex);
                    }
                }
            }

            else
            {
                _logger.Debug("Could not create valid date to change file [{0}]", filePath);
            }

            return(false);
        }
        private bool ChangeFileDate(string filePath, DateTime date)
        {
            DateTime oldDateTime;

            if (DateTime.TryParse(_diskProvider.FileGetLastWrite(filePath).ToLongDateString(), out oldDateTime))
            {
                if (!DateTime.Equals(date, oldDateTime))
                {
                    try
                    {
                        _diskProvider.FileSetLastWriteTime(filePath, date);
                        _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, date);

                        return(true);
                    }

                    catch (Exception ex)
                    {
                        _logger.Warn(ex, "Unable to set date of file [" + filePath + "]");
                    }
                }
            }

            return(false);
        }
Example #4
0
        private void DownloadCover(Author author, MediaCover cover, DateTime lastModified)
        {
            var fileName = GetCoverPath(author.Id, MediaCoverEntity.Author, cover.CoverType, cover.Extension);

            _logger.Info("Downloading {0} for {1} {2}", cover.CoverType, author, cover.Url);
            _httpClient.DownloadFile(cover.Url, fileName, USER_AGENT);

            try
            {
                _diskProvider.FileSetLastWriteTime(fileName, lastModified);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex, "Unable to set modified date for {0} image for author {1}", cover.CoverType, author);
            }
        }
Example #5
0
 private void SetLastWriteTime(string file, DateTime dateTime)
 {
     // Swallow any IOException that may be thrown due to "Invalid parameter"
     try
     {
         _diskProvider.FileSetLastWriteTime(file, dateTime);
     }
     catch (IOException)
     {
     }
 }
        private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, string fileTime)
        {
            DateTime airDate;

            if (DateTime.TryParse(fileDate + ' ' + fileTime, out airDate))
            {
                // avoiding false +ve checks and set date skewing by not using UTC (Windows)
                DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath);

                if (OsInfo.IsNotWindows && airDate < EpochTime)
                {
                    _logger.Debug("Setting date of file to 1970-01-01 as actual airdate is before that time and will not be set properly");
                    airDate = EpochTime;
                }

                if (!DateTime.Equals(airDate, oldDateTime))
                {
                    try
                    {
                        _diskProvider.FileSetLastWriteTime(filePath, airDate);
                        _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, airDate);

                        return(true);
                    }

                    catch (Exception ex)
                    {
                        _logger.Warn(ex, "Unable to set date of file [" + filePath + "]");
                    }
                }
            }

            else
            {
                _logger.Debug("Could not create valid date to change file [{0}]", filePath);
            }

            return(false);
        }
Example #7
0
        private bool ChangeFileDate(TrackFile trackFile, Artist artist, List <Track> tracks)
        {
            var trackFilePath = trackFile.Path;

            switch (_configService.FileDate)
            {
            case FileDateType.AlbumReleaseDate:
            {
                var album = _albumService.GetAlbum(trackFile.AlbumId);

                if (!album.ReleaseDate.HasValue)
                {
                    _logger.Debug("Could not create valid date to change file [{0}]", trackFilePath);
                    return(false);
                }

                var relDate = album.ReleaseDate.Value;

                // avoiding false +ve checks and set date skewing by not using UTC (Windows)
                DateTime oldDateTime = _diskProvider.FileGetLastWrite(trackFilePath);

                if (OsInfo.IsNotWindows && relDate < EpochTime)
                {
                    _logger.Debug("Setting date of file to 1970-01-01 as actual airdate is before that time and will not be set properly");
                    relDate = EpochTime;
                }

                if (!DateTime.Equals(relDate, oldDateTime))
                {
                    try
                    {
                        _diskProvider.FileSetLastWriteTime(trackFilePath, relDate);
                        _logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", trackFilePath, oldDateTime, relDate);

                        return(true);
                    }

                    catch (Exception ex)
                    {
                        _logger.Warn(ex, "Unable to set date of file [" + trackFilePath + "]");
                    }
                }

                return(false);
            }
            }

            return(false);
        }