Пример #1
0
        public void DeleteNfoFiles(DeleteNfoParams deleteNfoParams)
        {
            if (this.Item == null)
            {
                throw new Exception("Item is NULL.");
            }

            // Load all directories
            string currentPathRoot = string.Empty;

            if (this.Item.Type != KodiNfoElementType.FileSystem)
            {
                string errorMessage = "Invalid Path Part '" + this.Item.DirectoryName + "'.";
                throw new Exception(errorMessage);
            }
            else
            {
                if (this.m_rootPath.StartsWith("\\\\"))
                {
                    currentPathRoot = "\\\\";
                }
                else
                {
                    currentPathRoot = this.m_rootPath.Split(new char[] { '\\', '/' })[0] + "\\";
                }
            }

            this.Item.ProcessDeleteNfoFiles(currentPathRoot, deleteNfoParams);
        }
Пример #2
0
        public void ProcessDeleteNfoFiles(string currentPathRoot, DeleteNfoParams deleteNfoParams)
        {
            string[] directories = null;
            if (this.Type != KodiNfoElementType.FileSystem)
            {
                directories = this.LoadDirectories(currentPathRoot);
                App.CountFoundDirectories += directories.Length;
            }
            else
            {
                directories = new string[] { this.DirectoryName };
                App.CountFoundDirectories += directories.Length;
            }

            foreach (var folder in directories)
            {
                this.SetInformation(Path.GetFileNameWithoutExtension(folder));
                string newPath = Path.Combine(currentPathRoot, folder);
                if (this.Item != null)
                {
                    this.Item.ProcessDeleteNfoFiles(newPath, deleteNfoParams);
                }
                else
                {
                    this.ProcessDeleteFolder(newPath, deleteNfoParams);
                }
            }
        }
Пример #3
0
        internal void ProcessDeleteFolder(string currentPathRoot, DeleteNfoParams deleteNfoParams)
        {
            string[] files = this.LoadFiles(currentPathRoot);
            App.CountFoundFiles += files.Length;
            foreach (var file in files)
            {
                this.ProcessDeleteFile(Path.Combine(currentPathRoot, file), deleteNfoParams);
            }

            string[] directories = this.LoadDirectories(currentPathRoot);
            App.CountFoundDirectories += directories.Length;
            foreach (var folder in directories)
            {
                this.ProcessDeleteFolder(Path.Combine(currentPathRoot, folder), deleteNfoParams);
            }
        }
Пример #4
0
        private void ProcessDeleteFile(string pathAndFile, DeleteNfoParams deleteNfoParams)
        {
            try
            {
                XDocument xd = XDocument.Load(pathAndFile);

                if (KodiNfoXml.CheckForMissingInformation(xd, deleteNfoParams))
                {
                    File.Delete(pathAndFile);
                    Log.WriteInformation(string.Format("DELETION of NFO file {0} SUCCEEDED", pathAndFile));
                    App.CountNfoFilesDeleted++;
                }
            }
            catch (Exception x)
            {
                Log.WriteError(string.Format("DELETION of NFO file {0} FAILED", pathAndFile));
                Log.WriteException(x);
                App.CountNfoFilesFailedDeleted++;
            }
        }
Пример #5
0
        internal static bool CheckForMissingInformation(XDocument xd, DeleteNfoParams deleteNfoParams)
        {
            bool bResult = false;

            if (!bResult && deleteNfoParams.Actor)
            {
                if (xd.Root.Elements("actor") != null && xd.Root.Elements("actor").Count() > 0)
                {
                    var items = xd.Root.Elements("actor");
                    if (items.Count() == 0)
                    {
                        bResult = true;
                    }
                    foreach (var actor in items)
                    {
                        var name = actor.Element("name");
                        var role = actor.Element("role");
                        if (name != null || role != null)
                        {
                            if (name != null && (string.IsNullOrEmpty(name.Value) || string.IsNullOrEmpty(role.Value)))
                            {
                                bResult = true;
                                break;
                            }
                            else if (role != null && (string.IsNullOrEmpty(role.Value) || string.IsNullOrWhiteSpace(role.Value)))
                            {
                                bResult = true;
                                break;
                            }
                        }
                        else if (name == null || role == null)
                        {
                            bResult = true;
                            break;
                        }
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            if (!bResult && deleteNfoParams.Director)
            {
                if (xd.Root.Elements("director") != null && xd.Root.Elements("director").Count() > 0)
                {
                    foreach (var director in xd.Root.Elements("director"))
                    {
                        if (string.IsNullOrEmpty(director.Value) || string.IsNullOrWhiteSpace(director.Value))
                        {
                            bResult = true;
                            break;
                        }
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            if (!bResult && deleteNfoParams.Writer)
            {
                if (xd.Root.Elements("writer") != null && xd.Root.Elements("writer").Count() > 0)
                {
                    foreach (var director in xd.Root.Elements("writer"))
                    {
                        if (string.IsNullOrEmpty(director.Value) || string.IsNullOrWhiteSpace(director.Value))
                        {
                            bResult = true;
                            break;
                        }
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            if (!bResult && deleteNfoParams.Producer)
            {
                if (xd.Root.Elements("producer") != null && xd.Root.Elements("producer").Count() > 0)
                {
                    foreach (var director in xd.Root.Elements("producer"))
                    {
                        if (string.IsNullOrEmpty(director.Value) || string.IsNullOrWhiteSpace(director.Value))
                        {
                            bResult = true;
                            break;
                        }
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            if (!bResult && deleteNfoParams.Genre)
            {
                if (xd.Root.Elements("genre") != null && xd.Root.Elements("genre").Count() > 0)
                {
                    foreach (var genre in xd.Root.Elements("genre"))
                    {
                        if (string.IsNullOrEmpty(genre.Value) || string.IsNullOrWhiteSpace(genre.Value))
                        {
                            bResult = true;
                            break;
                        }
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            if (!bResult && (xd.Root.Element("plot") == null || string.IsNullOrWhiteSpace(xd.Root.Element("plot").Value) || string.IsNullOrEmpty(xd.Root.Element("plot").Value)) && deleteNfoParams.PlotOutline)
            {
                bResult = true;
            }

            if (!bResult && (xd.Root.Element("outline") == null || string.IsNullOrWhiteSpace(xd.Root.Element("outline").Value) || string.IsNullOrEmpty(xd.Root.Element("outline").Value)) && deleteNfoParams.PlotOutline)
            {
                bResult = true;
            }

            if (!bResult && (xd.Root.Element("thumb") == null || string.IsNullOrWhiteSpace(xd.Root.Element("thumb").Value) || string.IsNullOrEmpty(xd.Root.Element("thumb").Value)) && deleteNfoParams.ThumbPoster)
            {
                bResult = true;
            }

            if (!bResult && (xd.Root.Element("title") == null || string.IsNullOrWhiteSpace(xd.Root.Element("title").Value) || string.IsNullOrEmpty(xd.Root.Element("title").Value)) && deleteNfoParams.TitleSortTitle)
            {
                bResult = true;
            }

            if (!bResult && (xd.Root.Element("sorttitle") == null || string.IsNullOrWhiteSpace(xd.Root.Element("sorttitle").Value) || string.IsNullOrEmpty(xd.Root.Element("sorttitle").Value)) && deleteNfoParams.TitleSortTitle)
            {
                bResult = true;
            }

            if (!bResult && (xd.Root.Element("rating") == null || string.IsNullOrWhiteSpace(xd.Root.Element("rating").Value) || string.IsNullOrEmpty(xd.Root.Element("rating").Value)) && deleteNfoParams.Rating)
            {
                bResult = true;
            }

            return(bResult);
        }