/// <summary>
 /// Triggers TvFolderUpdateProgressChange event
 /// </summary>
 public static void OnUpdateProgressChange(ContentRootFolder sender, bool newContent, int percent, string msg)
 {
     if (UpdateProgressChange != null)
     {
         UpdateProgressChange(sender, new OrgProgressChangesEventArgs(newContent, percent, msg));
     }
 }
        /// <summary>
        /// Recursively builds list of sub-directories in content folder
        /// </summary>
        /// <param name="folder">Current folder</param>
        /// <param name="subFolders">List of sub-directories</param>
        /// <param name="clearMoviesFound">Enables clearing of found flag on movie in this folder</param>
        /// <param name="clearShowsFound">Enables clearing of found flag on shows in this folder</param>
        private void BuildSubDirectories(ContentRootFolder folder, List <OrgPath> subFolders, bool clearMoviesFound, bool clearShowsFound)
        {
            // Clear found flag for all movies
            if (clearMoviesFound)
            {
                for (int i = 0; i < Organization.Movies.Count; i++)
                {
                    if (Organization.Movies[i].RootFolder == folder.FullPath)
                    {
                        Organization.Movies[i].Found = false;
                    }
                }
            }

            // Clear found flag on all movies
            if (clearShowsFound)
            {
                for (int i = 0; i < Organization.Shows.Count; i++)
                {
                    if (Organization.Shows[i].RootFolder == folder.FullPath)
                    {
                        Organization.Shows[i].Found = false;
                    }
                }
            }

            // Get each subfolder from the content folder that isn't a sub-content folder
            if (Directory.Exists(folder.FullPath))
            {
                string[] subFolderList = Directory.GetDirectories(folder.FullPath);

                foreach (string subFldr in subFolderList)
                {
                    bool isSubContentFolder = false;
                    foreach (ContentRootFolder subContent in folder.ChildFolders)
                    {
                        if (subFldr == subContent.FullPath)
                        {
                            isSubContentFolder = true;
                            break;
                        }
                    }

                    if (!isSubContentFolder)
                    {
                        subFolders.Add(new OrgPath(subFldr, false, true, folder, null));
                    }
                }


                // Recursively seach sub-content folders
                foreach (ContentRootFolder subContent in folder.ChildFolders)
                {
                    subContent.BuildSubDirectories(subContent, subFolders, clearMoviesFound, clearShowsFound);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Constructor for file from content folder (movie or tv)
 /// </summary>
 /// <param name="path">file's path</param>
 /// <param name="copy">whether file is allowed to be copied</param>
 /// <param name="allowDelete">whether file is allowed to be deleted</param>
 /// <param name="folder">content folder file belongs to</param>
 public OrgPath(string path, bool copy, bool allowDelete, ContentRootFolder folder, Content content)
 {
     this.Path = path;
     this.Copy = copy;
     this.AllowDelete = allowDelete;
     this.RootFolder = folder;
     this.Content = content;
     this.SimilarTo = -1;
 }
Beispiel #4
0
 /// <summary>
 /// Constructor for file from content folder (movie or tv)
 /// </summary>
 /// <param name="path">file's path</param>
 /// <param name="copy">whether file is allowed to be copied</param>
 /// <param name="allowDelete">whether file is allowed to be deleted</param>
 /// <param name="folder">content folder file belongs to</param>
 public OrgPath(string path, bool copy, bool allowDelete, ContentRootFolder folder, Content content)
 {
     this.Path        = path;
     this.Copy        = copy;
     this.AllowDelete = allowDelete;
     this.RootFolder  = folder;
     this.Content     = content;
     this.SimilarTo   = -1;
 }
        /// <summary>
        /// Recursively gets known files (files that are in a content folder) from a movie root folder and its children.
        /// </summary>
        /// <param name="folder">Root folders to look for files in</param>
        /// <param name="folderPath">Current folder path</param>
        /// <param name="files">List of files to add to</param>
        /// <param name="depth">Current depth from root folder</param>
        /// <param name="movie">Movie current path belongs to</param>
        private void GetKnownFiles(ContentRootFolder folder, string folderPath, List <OrgPath> files, int depth, Movie movie)
        {
            // Match to movie
            if (depth == 1)
            {
                foreach (Movie mov in Organization.Movies)
                {
                    if (mov.Path == folderPath)
                    {
                        movie = mov;
                        break;
                    }
                }
            }

            // Only get files from folders that allow organization
            if (folder.AllowOrganizing)
            {
                // Get files only from non-content sub-folders
                if (depth > 0)
                {
                    string[] fileList = Directory.GetFiles(folderPath);
                    foreach (string file in fileList)
                    {
                        files.Add(new OrgPath(file, true, folder.AllowOrganizing, folder, movie));
                    }
                }

                // Recursion on sub folders
                string[] subDirs = Directory.GetDirectories(folderPath);
                foreach (string subDir in subDirs)
                {
                    ContentRootFolder subDirContent = null;
                    foreach (ContentRootFolder subfolder in folder.ChildFolders)
                    {
                        if (subfolder.FullPath == subDir)
                        {
                            subDirContent = subfolder;
                            break;
                        }
                    }

                    if (subDirContent != null)
                    {
                        GetKnownFiles(subDirContent, subDirContent.FullPath, files, 0, movie);
                    }
                    else
                    {
                        GetKnownFiles(folder, subDir, files, depth + 1, movie);
                    }
                }
            }
        }
        /// <summary>
        /// Set all sub directories to child root folders
        /// </summary>
        public void SetAllSubDirsAsChildren()
        {
            // Get sub-dirs
            string[] subDirs = System.IO.Directory.GetDirectories(this.FullPath);
            for (int i = 0; i < subDirs.Length; i++)
            {
                subDirs[i] = Path.GetFileName(subDirs[i]);
            }

            // Remove child folders that no longer exists
            for (int i = this.ChildFolders.Count - 1; i >= 0; i--)
            {
                bool exists = false;
                foreach (string subDir in subDirs)
                {
                    if (System.IO.Path.Combine(this.FullPath, subDir) == this.ChildFolders[i].fullPath)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    this.ChildFolders.RemoveAt(i);
                }
            }

            // Add all sub-dirs as children
            foreach (string subDir in subDirs)
            {
                string newPath = System.IO.Path.Combine(this.FullPath, subDir);

                bool exists = false;
                foreach (ContentRootFolder child in this.ChildFolders)
                {
                    if (child.FullPath == newPath)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    ContentRootFolder newChild = new ContentRootFolder(this.ContentType, subDir, newPath);
                    this.ChildFolders.Add(newChild);
                }
            }
        }
 /// <summary>
 /// Constructor for cloning instance
 /// </summary>
 /// <param name="folder">instance to clone</param>
 public ContentRootFolder(ContentRootFolder folder)
     : this(folder.ContentType)
 {
     this.SubPath = folder.SubPath;
     this.FullPath = folder.FullPath;
     this.AllowOrganizing = folder.AllowOrganizing;
     this.Default = folder.Default;
     this.ChildFolders.Clear();
     foreach (ContentRootFolder subFolder in folder.ChildFolders)
         this.ChildFolders.Add(new ContentRootFolder(subFolder));
     this.Id = folder.Id;
     this.Temporary = folder.Temporary;
     this.AllSubFoldersChildRootFolder = folder.AllSubFoldersChildRootFolder;
 }
Beispiel #8
0
        /// <summary>
        /// Get content folder object from path string.
        /// </summary>
        /// <param name="folderPath">Path of content folder</param>
        /// <param name="folder">Resulting content folder matching path</param>
        /// <returns>True if folder was found</returns>
        public static bool GetContentFolderFromPath(string folderPath, out ContentRootFolder folder)
        {
            if (GetMovieFolderFromPath(folderPath, out folder))
            {
                return(true);
            }

            if (GetTvFolderFromPath(folderPath, out folder))
            {
                return(true);
            }

            folder = new ContentRootFolder(ContentType.TvShow);
            return(false);
        }
 /// <summary>
 /// Constructor for cloning instance
 /// </summary>
 /// <param name="folder">instance to clone</param>
 public ContentRootFolder(ContentRootFolder folder)
     : this(folder.ContentType)
 {
     this.SubPath         = folder.SubPath;
     this.FullPath        = folder.FullPath;
     this.AllowOrganizing = folder.AllowOrganizing;
     this.Default         = folder.Default;
     this.ChildFolders.Clear();
     foreach (ContentRootFolder subFolder in folder.ChildFolders)
     {
         this.ChildFolders.Add(new ContentRootFolder(subFolder));
     }
     this.Id        = folder.Id;
     this.Temporary = folder.Temporary;
     this.AllSubFoldersChildRootFolder = folder.AllSubFoldersChildRootFolder;
 }
        /// <summary>
        /// Recursively gets unknown files (files that are not in a content folder) from a movie root folder and its children.
        /// </summary>
        /// <param name="folder">Root folders to look for files in</param>
        /// <param name="files">List of files found to add to</param>
        private void GetUnknownFiles(ContentRootFolder folder, List <OrgPath> files)
        {
            // Only get files from folders that allow organization
            if (folder.AllowOrganizing)
            {
                string[] fileList = Directory.GetFiles(folder.FullPath);
                foreach (string file in fileList)
                {
                    files.Add(new OrgPath(file, true, folder.AllowOrganizing, folder, null));
                }
            }

            // Recursion on sub-content folders
            foreach (ContentRootFolder subfolder in folder.ChildFolders)
            {
                GetUnknownFiles(subfolder, files);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Recursively gets known files (files that are in a content folder) from a movie root folder and its children.
        /// </summary>
        /// <param name="folder">Root folders to look for files in</param>
        /// <param name="folderPath">Current folder path</param>
        /// <param name="files">List of files to add to</param>
        /// <param name="depth">Current depth from root folder</param>
        /// <param name="movie">Movie current path belongs to</param>
        private void GetKnownFiles(ContentRootFolder folder, string folderPath, List<OrgPath> files, int depth, Movie movie)
        {
            // Match to movie
            if (depth == 1)
            {
                foreach (Movie mov in Organization.Movies)
                    if (mov.Path == folderPath)
                    {
                        movie = mov;
                        break;
                    }
            }

            // Only get files from folders that allow organization
            if (folder.AllowOrganizing)
            {
                // Get files only from non-content sub-folders
                if (depth > 0)
                {
                    string[] fileList = Directory.GetFiles(folderPath);
                    foreach (string file in fileList)
                        files.Add(new OrgPath(file, true, folder.AllowOrganizing, folder, movie));
                }

                // Recursion on sub folders
                string[] subDirs = Directory.GetDirectories(folderPath);
                foreach (string subDir in subDirs)
                {
                    ContentRootFolder subDirContent = null;
                    foreach (ContentRootFolder subfolder in folder.ChildFolders)
                        if (subfolder.FullPath == subDir)
                        {
                            subDirContent = subfolder;
                            break;
                        }

                    if (subDirContent != null)
                        GetKnownFiles(subDirContent, subDirContent.FullPath, files, 0, movie);
                    else
                        GetKnownFiles(folder, subDir, files, depth + 1, movie);
                }
            }
        }
        /// <summary>
        /// Get root folder that matches path string, recursive search
        /// </summary>
        /// <param name="path">Path to match to</param>
        /// <param name="baseFolder">Current root folder being searches</param>
        /// <param name="matchedFolder">Resulting matched root folder</param>
        /// <returns>Whether match was found</returns>
        public static bool GetMatchingRootFolder(string path, ContentRootFolder baseFolder, out ContentRootFolder matchedFolder)
        {
            if (path == baseFolder.FullPath)
            {
                matchedFolder = baseFolder;
                return(true);
            }
            else
            {
                foreach (ContentRootFolder child in baseFolder.ChildFolders)
                {
                    if (GetMatchingRootFolder(path, child, out matchedFolder))
                    {
                        return(true);
                    }
                }
            }

            matchedFolder = null;
            return(false);
        }
Beispiel #13
0
 /// <summary>
 /// Gets Tv folder that matches path
 /// </summary>
 /// <param name="path">The path of folder to match to</param>
 /// <returns>whether folder was found</returns>
 public static bool GetTvFolderFromPath(string path, out ContentRootFolder folder)
 {
     return TvFolders.GetFolderFromPath(path, out folder);
 }
        /// <summary>
        /// Recursively builds list of sub-directories in content folder
        /// </summary>
        /// <param name="folder">Current folder</param>
        /// <param name="subFolders">List of sub-directories</param>
        /// <param name="clearMoviesFound">Enables clearing of found flag on movie in this folder</param>
        /// <param name="clearShowsFound">Enables clearing of found flag on shows in this folder</param>
        private void BuildSubDirectories(ContentRootFolder folder, List<OrgPath> subFolders, bool clearMoviesFound, bool clearShowsFound)
        {
            // Clear found flag for all movies
            if (clearMoviesFound)
            {
                for (int i = 0; i < Organization.Movies.Count; i++)
                    if (Organization.Movies[i].RootFolder == folder.FullPath)
                        Organization.Movies[i].Found = false;
            }

            // Clear found flag on all movies
            if (clearShowsFound)
            {
                for (int i = 0; i < Organization.Shows.Count; i++)
                    if (Organization.Shows[i].RootFolder == folder.FullPath)
                        Organization.Shows[i].Found = false;
            }

            // Get each subfolder from the content folder that isn't a sub-content folder
            if (Directory.Exists(folder.FullPath))
            {
                string[] subFolderList = Directory.GetDirectories(folder.FullPath);

                foreach (string subFldr in subFolderList)
                {
                    bool isSubContentFolder = false;
                    foreach (ContentRootFolder subContent in folder.ChildFolders)
                    {
                        if (subFldr == subContent.FullPath)
                        {
                            isSubContentFolder = true;
                            break;
                        }
                    }

                    if (!isSubContentFolder)
                        subFolders.Add(new OrgPath(subFldr, false, true, folder, null));
                }

            // Recursively seach sub-content folders
            foreach (ContentRootFolder subContent in folder.ChildFolders)
                subContent.BuildSubDirectories(subContent, subFolders, clearMoviesFound, clearShowsFound);
            }
        }
        /// <summary>
        /// Set all sub directories to child root folders
        /// </summary>
        public void SetAllSubDirsAsChildren()
        {
            // Get sub-dirs
            string[] subDirs = System.IO.Directory.GetDirectories(this.FullPath);
            for (int i = 0; i < subDirs.Length; i++)
                subDirs[i] = Path.GetFileName(subDirs[i]);

            // Remove child folders that no longer exists
            for (int i = this.ChildFolders.Count - 1; i >= 0; i--)
            {
                bool exists = false;
                foreach (string subDir in subDirs)
                    if (System.IO.Path.Combine(this.FullPath, subDir) == this.ChildFolders[i].fullPath)
                    {
                        exists = true;
                        break;
                    }

                if (!exists)
                    this.ChildFolders.RemoveAt(i);
            }

            // Add all sub-dirs as children
            foreach (string subDir in subDirs)
            {
                string newPath =  System.IO.Path.Combine(this.FullPath, subDir);

                bool exists = false;
                foreach(ContentRootFolder child in this.ChildFolders)
                   if(child.FullPath == newPath)
                   {
                       exists = true;
                       break;
                   }

                if(!exists)
                {
                    ContentRootFolder newChild = new ContentRootFolder(this.ContentType, subDir, newPath);
                    this.ChildFolders.Add(newChild);
                }
            }
        }
        /// <summary>
        /// Loads properties from XML elements
        /// </summary>
        /// <param name="showNode">The XML node containt property elements</param>
        /// <returns>Whether XML was loaded properly</returns>
        public bool Load(XmlNode foldersNode)
        {
            // Check that we're on the right node
            if (foldersNode.Name != ROOT_XML)
                return false;

            // Go through elements of node
            foreach (XmlNode propNode in foldersNode.ChildNodes)
            {
                // Match the current node to a known element name
                XmlElements element;
                if (!Enum.TryParse<XmlElements>(propNode.Name, out element))
                    continue;

                // Set appropiate property from value in element
                string value = propNode.InnerText;
                switch (element)
                {
                    case XmlElements.SubPath:
                        this.SubPath = value;
                        break;
                    case XmlElements.FullPath:
                        this.FullPath = value;
                        break;
                    case XmlElements.AllowOrganizing:
                        bool allowOrg;
                        if (bool.TryParse(value, out allowOrg))
                            this.AllowOrganizing = allowOrg;
                        break;
                    case XmlElements.Default:
                        bool def;
                        if (bool.TryParse(value, out def))
                            this.Default = def;
                        break;
                    case XmlElements.ChildFolders:
                        this.ChildFolders = new ObservableCollection<ContentRootFolder>();
                        foreach (XmlNode subContentNode in propNode.ChildNodes)
                        {
                            ContentRootFolder subFolder = new ContentRootFolder(this.ContentType);
                            subFolder.Load(subContentNode);
                            this.ChildFolders.Add(subFolder);
                        }
                        break;
                    case XmlElements.Temporary:
                        bool temp;
                        if (bool.TryParse(value, out temp))
                            this.Temporary = temp;
                        break;
                    case XmlElements.AllSubFoldersChildRootFolder:
                        bool allSubsChild;
                        if (bool.TryParse(value, out allSubsChild))
                            this.AllSubFoldersChildRootFolder = allSubsChild;
                        break;
                }
            }

            return true;
        }
 /// <summary>
 /// Triggers TvFolderUpdateProgressChange event
 /// </summary>
 public static void OnUpdateProgressComplete(ContentRootFolder sender)
 {
     UpdateProgressComplete?.Invoke(sender, new EventArgs());
 }
Beispiel #18
0
 /// <summary>
 /// Gets movie folder that matches path
 /// </summary>
 /// <param name="path">The path of folder to match to</param>
 /// <returns>whether folder was found</returns>
 public static bool GetMovieFolderFromPath(string path, out ContentRootFolder folder)
 {
     return(MovieFolders.GetFolderFromPath(path, out folder));
 }
Beispiel #19
0
        /// <summary>
        /// Get content folder object from path string.
        /// </summary>
        /// <param name="folderPath">Path of content folder</param>
        /// <param name="folder">Resulting content folder matching path</param>
        /// <returns>True if folder was found</returns>
        public static bool GetContentFolderFromPath(string folderPath, out ContentRootFolder folder)
        {
            if (GetMovieFolderFromPath(folderPath, out folder))
                return true;

            if (GetTvFolderFromPath(folderPath, out folder))
                return true;

            folder = new ContentRootFolder(ContentType.TvShow);
            return false;
        }
Beispiel #20
0
        /// <summary>
        /// Loads settings from XML.
        /// </summary>
        public static void Load()
        {
            string basePath = Organization.GetBasePath(false);

            if (!Directory.Exists(basePath))
            {
                return;
            }

            // Initialize file types to defautls
            VideoFileTypes = new ObservableCollection <string>();
            foreach (string type in DefaultVideoFileTypes)
            {
                VideoFileTypes.Add(type);
            }
            DeleteFileTypes = new ObservableCollection <string>();
            foreach (string type in DefaultDeleteFileTypes)
            {
                DeleteFileTypes.Add(type);
            }
            IgnoreFileTypes = new ObservableCollection <string>();
            foreach (string type in DefaultIgnoreFileTypes)
            {
                IgnoreFileTypes.Add(type);
            }

            // Load settings XML
            string path = Path.Combine(basePath, ROOT_XML + ".xml");

            if (File.Exists(path))
            {
                // Load XML
                XmlTextReader reader = new XmlTextReader(path);
                XmlDocument   xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);

                foreach (XmlNode propNode in xmlDoc.DocumentElement.ChildNodes)
                {
                    XmlElements element;
                    if (!Enum.TryParse <XmlElements>(propNode.Name, out element))
                    {
                        continue;
                    }

                    string value = propNode.InnerText;
                    switch (element)
                    {
                    case XmlElements.ScanDirectories:
                        ScanDirectories = new ObservableCollection <OrgFolder>();
                        foreach (XmlNode scanDirNode in propNode.ChildNodes)
                        {
                            OrgFolder folder = new OrgFolder();
                            folder.Load(scanDirNode);
                            ScanDirectories.Add(folder);
                        }
                        break;

                    case XmlElements.TvFileFormat:
                        TvFileFormat.Load(propNode);
                        break;

                    case XmlElements.MovieFileFormat:
                        MovieFileFormat.Load(propNode);
                        break;

                    case XmlElements.MovieFolderColletion:
                        MovieFolders.Load(propNode);
                        break;

                    case XmlElements.TvFolderCollection:
                        TvFolders.Load(propNode);
                        break;

                    case XmlElements.VideoFileTypes:
                        VideoFileTypes = new ObservableCollection <string>();
                        foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                        {
                            string videoType = fileTypeNode.InnerText;
                            if (videoType.StartsWith("."))
                            {
                                videoType = videoType.Substring(1, videoType.Length - 1);
                            }
                            VideoFileTypes.Add(videoType);
                        }
                        break;

                    case XmlElements.DeleteFileTypes:
                        DeleteFileTypes = new ObservableCollection <string>();
                        foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                        {
                            string delType = fileTypeNode.InnerText;
                            if (delType.StartsWith("."))
                            {
                                delType = delType.Substring(1, delType.Length - 1);
                            }
                            DeleteFileTypes.Add(delType);
                        }
                        break;

                    case XmlElements.IgnoreFileTypes:
                        IgnoreFileTypes = new ObservableCollection <string>();
                        foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                        {
                            string ignoreType = fileTypeNode.InnerText;
                            if (ignoreType.StartsWith("."))
                            {
                                ignoreType = ignoreType.Substring(1, ignoreType.Length - 1);
                            }
                            IgnoreFileTypes.Add(ignoreType);
                        }
                        break;

                    case XmlElements.AutoMoveSetups:
                        AutoMoveSetups = new ObservableCollection <AutoMoveFileSetup>();
                        foreach (XmlNode setupNode in propNode.ChildNodes)
                        {
                            AutoMoveFileSetup setup = new AutoMoveFileSetup();
                            setup.Load(setupNode);
                            AutoMoveSetups.Add(setup);
                        }
                        break;

                    case XmlElements.Gui:
                        GuiControl.Load(propNode);
                        break;

                    case XmlElements.General:
                        General.Load(propNode);
                        break;

                    case XmlElements.MovieFolders:
                        MovieFolders.Clear();
                        foreach (XmlNode movieFolderNode in propNode.ChildNodes)
                        {
                            ContentRootFolder folder = new ContentRootFolder(ContentType.Movie);
                            folder.Load(movieFolderNode);
                            MovieFolders.Add(folder);
                        }
                        break;

                    case XmlElements.TvFolders:
                        TvFolders.Clear();
                        foreach (XmlNode tvFolderNode in propNode.ChildNodes)
                        {
                            ContentRootFolder folder = new ContentRootFolder(ContentType.TvShow);
                            folder.Load(tvFolderNode);
                            TvFolders.Add(folder);
                        }
                        break;
                    }
                }
            }
            OnSettingsModified(true);
        }
Beispiel #21
0
        /// <summary>
        /// Recursively gets unknown files (files that are not in a content folder) from a movie root folder and its children.
        /// </summary>
        /// <param name="folder">Root folders to look for files in</param>
        /// <param name="files">List of files found to add to</param>
        private void GetUnknownFiles(ContentRootFolder folder, List<OrgPath> files)
        {
            // Only get files from folders that allow organization
            if (folder.AllowOrganizing)
            {
                string[] fileList = Directory.GetFiles(folder.FullPath);
                foreach (string file in fileList)
                    files.Add(new OrgPath(file, true, folder.AllowOrganizing, folder, null));
            }

            // Recursion on sub-content folders
            foreach (ContentRootFolder subfolder in folder.ChildFolders)
                GetUnknownFiles(subfolder, files);
        }
        /// <summary>
        /// Clear default flag on all folders except for one (the new default).
        /// </summary>
        /// <param name="exception">Folder to allow default flag to be on.</param>
        /// <param name="folders">List of content folders to clear default on</param>
        private void ClearDefault(ContentRootFolder exception, ObservableCollection<ContentRootFolder> folders)
        {
            // Go thorough all content folders in list
            foreach (ContentRootFolder folder in folders)
            {
                // Clear default flag if not exception
                if (folder != exception)
                    folder.Default = false;

                // Recursion of sub-content folders
                if (folder.ChildFolders.Count > 0)
                    ClearDefault(exception, folder.ChildFolders);
            }
        }
        /// <summary>
        /// Recursive search to remove folder
        /// </summary>
        /// <param name="selFolder">Folder to remove</param>
        /// <param name="folders">List of folders to look for folder to remove in</param>
        /// <returns>True if folder was removed</returns>
        private bool RemoveFolder(ContentRootFolder selFolder, ObservableCollection<ContentRootFolder> folders)
        {
            // Loop through folders
            if (folders.Contains(selFolder))
            {
                folders.Remove(selFolder);
                return true;
            }

            for (int i = 0; i < folders.Count; i++)
            {
                // Check sub-folders
                if (RemoveFolder(selFolder, folders[i].ChildFolders))
                    return true;
            }

            // Folder not removed yet
            return false;
        }
 /// <summary>
 /// Triggers TvFolderUpdateProgressChange event
 /// </summary>
 public static void OnUpdateProgressComplete(ContentRootFolder sender)
 {
     UpdateProgressComplete?.Invoke(sender, new EventArgs());
 }
 /// <summary>
 /// Add item to root folder combo box
 /// </summary>
 /// <param name="rootFolder"></param>
 private void AddRootFolderFilterItems(ContentRootFolder rootFolder)
 {
     this.FolderFilters.Add("Non-recursive: " + rootFolder.FullPath);
     foreach (ContentRootFolder child in rootFolder.ChildFolders)
         AddRootFolderFilterItems(child);
 }
        private void AddChild()
        {
            if (this.SelectedRootFolder != null)
            {
                // Get list of sub-directories in content folder
                string[] subDirs = this.SelectedRootFolder.GetFolderSubDirectoryNamesThatArentChildren().ToArray();

                // open selection form to allow user to chose a sub-folder
                SelectionWindow selForm = new SelectionWindow("Select Folder", subDirs);
                selForm.ShowDialog();

                // If selection is valid set sub-folder as sub-content folder
                if (!string.IsNullOrEmpty(selForm.Results))
                {
                    ContentRootFolder newChild = new ContentRootFolder(this.ContentType, selForm.Results, System.IO.Path.Combine(this.SelectedRootFolder.FullPath, selForm.Results));
                    newChild.PropertyChanged += cloneFolder_PropertyChanged;
                    this.SelectedRootFolder.ChildFolders.Add(newChild);
                }
                UpdateAvailableFolders();
            }
        }
        private void AddFolder()
        {
            // Open folder browser
            VistaFolderBrowserDialog folderSel = new VistaFolderBrowserDialog();

            // Add folder if valid folder selected
            if (folderSel.ShowDialog() == true && System.IO.Directory.Exists(folderSel.SelectedPath))
            {
                ContentRootFolder folder = new ContentRootFolder(this.ContentType, folderSel.SelectedPath, folderSel.SelectedPath);
                if (RootFolders.Count == 0)
                    folder.Default = true;
                folder.PropertyChanged += cloneFolder_PropertyChanged;
                RootFolders.Add(folder);

                UpdateAvailableFolders();
            }
        }
 /// <summary>
 /// Triggers TvFolderUpdateProgressChange event
 /// </summary>
 public static void OnUpdateProgressChange(ContentRootFolder sender, bool newContent, int percent, string msg)
 {
     if (UpdateProgressChange != null)
         UpdateProgressChange(sender, new OrgProgressChangesEventArgs(newContent, percent, msg));
 }
Beispiel #29
0
 /// <summary>
 /// Gets TV folder that is set as default
 /// </summary>
 /// <returns></returns>
 public static bool GetTvFolderForContent(Content content, out ContentRootFolder rootFolder)
 {
     rootFolder = TvFolders.GetFolderForContent(content);
     return rootFolder != null;
 }
Beispiel #30
0
 /// <summary>
 /// Gets TV folder that is set as default
 /// </summary>
 /// <returns></returns>
 public static bool GetTvFolderForContent(Content content, out ContentRootFolder rootFolder)
 {
     rootFolder = TvFolders.GetFolderForContent(content);
     return(rootFolder != null);
 }
Beispiel #31
0
        /// <summary>
        /// Loads settings from XML.
        /// </summary>
        public static void Load()
        {
            string basePath = Organization.GetBasePath(false);
            if (!Directory.Exists(basePath))
                return;

            // Initialize file types to defautls
            VideoFileTypes = new ObservableCollection<string>();
            foreach (string type in DefaultVideoFileTypes)
                VideoFileTypes.Add(type);
            DeleteFileTypes = new ObservableCollection<string>();
            foreach (string type in DefaultDeleteFileTypes)
                DeleteFileTypes.Add(type);
            IgnoreFileTypes = new ObservableCollection<string>();
            foreach (string type in DefaultIgnoreFileTypes)
                IgnoreFileTypes.Add(type);

            // Load settings XML
            string path = Path.Combine(basePath, ROOT_XML + ".xml");
            if (File.Exists(path))
            {
                // Load XML
                XmlTextReader reader = new XmlTextReader(path);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);

                foreach (XmlNode propNode in xmlDoc.DocumentElement.ChildNodes)
                {
                    XmlElements element;
                    if (!Enum.TryParse<XmlElements>(propNode.Name, out element))
                        continue;

                    string value = propNode.InnerText;
                    switch (element)
                    {
                        case XmlElements.ScanDirectories:
                            ScanDirectories = new ObservableCollection<OrgFolder>();
                            foreach (XmlNode scanDirNode in propNode.ChildNodes)
                            {
                                OrgFolder folder = new OrgFolder();
                                folder.Load(scanDirNode);
                                ScanDirectories.Add(folder);
                            }
                            break;
                        case XmlElements.TvFileFormat:
                            TvFileFormat.Load(propNode);
                            break;
                        case XmlElements.MovieFileFormat:
                            MovieFileFormat.Load(propNode);
                            break;
                        case XmlElements.MovieFolderColletion:
                            MovieFolders.Load(propNode);
                            break;
                        case XmlElements.TvFolderCollection:
                            TvFolders.Load(propNode);
                            break;
                        case XmlElements.VideoFileTypes:
                            VideoFileTypes = new ObservableCollection<string>();
                            foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                            {
                                string videoType = fileTypeNode.InnerText;
                                if (videoType.StartsWith("."))
                                    videoType = videoType.Substring(1, videoType.Length - 1);
                                VideoFileTypes.Add(videoType);
                            }
                            break;
                        case XmlElements.DeleteFileTypes:
                            DeleteFileTypes = new ObservableCollection<string>();
                            foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                            {
                                string delType = fileTypeNode.InnerText;
                                if (delType.StartsWith("."))
                                    delType = delType.Substring(1, delType.Length - 1);
                                DeleteFileTypes.Add(delType);
                            }
                            break;
                        case XmlElements.IgnoreFileTypes:
                            IgnoreFileTypes = new ObservableCollection<string>();
                            foreach (XmlNode fileTypeNode in propNode.ChildNodes)
                            {
                                string ignoreType = fileTypeNode.InnerText;
                                if (ignoreType.StartsWith("."))
                                    ignoreType = ignoreType.Substring(1, ignoreType.Length - 1);
                                IgnoreFileTypes.Add(ignoreType);
                            }
                            break;
                        case XmlElements.AutoMoveSetups:
                            AutoMoveSetups = new ObservableCollection<AutoMoveFileSetup>();
                            foreach (XmlNode setupNode in propNode.ChildNodes)
                            {
                                AutoMoveFileSetup setup = new AutoMoveFileSetup();
                                setup.Load(setupNode);
                                AutoMoveSetups.Add(setup);
                            }
                            break;
                        case XmlElements.Gui:
                            GuiControl.Load(propNode);
                            break;
                        case XmlElements.General:
                            General.Load(propNode);
                            break;
                        case XmlElements.MovieFolders:
                            MovieFolders.Clear();
                            foreach (XmlNode movieFolderNode in propNode.ChildNodes)
                            {
                                ContentRootFolder folder = new ContentRootFolder(ContentType.Movie);
                                folder.Load(movieFolderNode);
                                MovieFolders.Add(folder);
                            }
                            break;
                        case XmlElements.TvFolders:
                            TvFolders.Clear();
                            foreach (XmlNode tvFolderNode in propNode.ChildNodes)
                            {
                                ContentRootFolder folder = new ContentRootFolder(ContentType.TvShow);
                                folder.Load(tvFolderNode);
                                TvFolders.Add(folder);
                            }
                            break;
                    }
                }

            }
            OnSettingsModified(true);
        }
        /// <summary>
        /// Loads properties from XML elements
        /// </summary>
        /// <param name="showNode">The XML node containt property elements</param>
        /// <returns>Whether XML was loaded properly</returns>
        public bool Load(XmlNode foldersNode)
        {
            // Check that we're on the right node
            if (foldersNode.Name != ROOT_XML)
            {
                return(false);
            }

            // Go through elements of node
            foreach (XmlNode propNode in foldersNode.ChildNodes)
            {
                // Match the current node to a known element name
                XmlElements element;
                if (!Enum.TryParse <XmlElements>(propNode.Name, out element))
                {
                    continue;
                }

                // Set appropiate property from value in element
                string value = propNode.InnerText;
                switch (element)
                {
                case XmlElements.SubPath:
                    this.SubPath = value;
                    break;

                case XmlElements.FullPath:
                    this.FullPath = value;
                    break;

                case XmlElements.AllowOrganizing:
                    bool allowOrg;
                    if (bool.TryParse(value, out allowOrg))
                    {
                        this.AllowOrganizing = allowOrg;
                    }
                    break;

                case XmlElements.Default:
                    bool def;
                    if (bool.TryParse(value, out def))
                    {
                        this.Default = def;
                    }
                    break;

                case XmlElements.ChildFolders:
                    this.ChildFolders = new ObservableCollection <ContentRootFolder>();
                    foreach (XmlNode subContentNode in propNode.ChildNodes)
                    {
                        ContentRootFolder subFolder = new ContentRootFolder(this.ContentType);
                        subFolder.Load(subContentNode);
                        this.ChildFolders.Add(subFolder);
                    }
                    break;

                case XmlElements.Temporary:
                    bool temp;
                    if (bool.TryParse(value, out temp))
                    {
                        this.Temporary = temp;
                    }
                    break;

                case XmlElements.AllSubFoldersChildRootFolder:
                    bool allSubsChild;
                    if (bool.TryParse(value, out allSubsChild))
                    {
                        this.AllSubFoldersChildRootFolder = allSubsChild;
                    }
                    break;
                }
            }

            return(true);
        }
        /// <summary>
        /// Get root folder that matches path string, recursive search
        /// </summary>
        /// <param name="path">Path to match to</param>
        /// <param name="baseFolder">Current root folder being searches</param>
        /// <param name="matchedFolder">Resulting matched root folder</param>
        /// <returns>Whether match was found</returns>
        public static bool GetMatchingRootFolder(string path, ContentRootFolder baseFolder, out ContentRootFolder matchedFolder)
        {
            if (path == baseFolder.FullPath)
            {
                matchedFolder = baseFolder;
                return true;
            }
            else
                foreach (ContentRootFolder child in baseFolder.ChildFolders)
                {
                    if (GetMatchingRootFolder(path, child, out matchedFolder))
                        return true;
                }

            matchedFolder = null;
            return false;
        }
        private void UpdateMovieFolderItem(ContentRootFolder folder)
        {
            MenuItem item = new MenuItem();
            item.Header = folder.FullPath;
            item.Command = new RelayCommand(param => this.SetMovieFolder(folder.FullPath));
            this.MovieFolderItems.Add(item);

            foreach (ContentRootFolder subFolder in folder.ChildFolders)
                UpdateMovieFolderItem(subFolder);
        }