Exemple #1
0
        public void Start(string path, string[] extensions, string fileNamePattern, string fileNamePatternCollection, ActionType actionType)
        {
            _directoriesProcessed  = new List <string>();
            _collectionDirectories = new Dictionary <string, bool>();
            var files = _storage.Directory.GetFiles(path, SearchOption.AllDirectories, extensions);

            foreach (var file in files)
            {
                var preTag = _storage.File.ReadTag(file);
                if (preTag != null)
                {
                    var tag = preTag.Tag;
                    if (!(string.IsNullOrEmpty(tag?.Album) || string.IsNullOrEmpty(tag.Title)))
                    {
                        var  fileExtension       = Path.GetExtension(file);
                        bool isPartOfACollection = IsPartOfCollection(file, extensions);

                        var newFileName = _tagFileProcessor.CalculateFileName(tag, path, fileExtension,
                                                                              ((isPartOfACollection) ? fileNamePatternCollection : fileNamePattern), isPartOfACollection);
                        if (!string.Equals(file.ToLower(), newFileName.ToLower()))
                        {
                            _storage.File.Create(newFileName, _storage.File.Read(file));
                            if (actionType == ActionType.Move)
                            {
                                _storage.File.Delete(file);
                            }
                            if (_directoriesProcessed.All(d => d != Path.GetDirectoryName(file)))
                            {
                                ProcessNonMusicContents(Path.GetDirectoryName(file), Path.GetDirectoryName(newFileName),
                                                        extensions, actionType);
                            }
                        }
                    }
                }
            }
            CleanupEmptyDirectories(path);
        }