GameLoader.GameSuggestions.ScanRecursive C# (CSharp) Method

ScanRecursive() private static method

Check a folder for valid game folders, and adds them to the list And if not at the max level yet, scans sub folders
private static ScanRecursive ( int current, int max, List libraryLocations, DirectoryInfo folder ) : void
current int How deep we currently are
max int How deep we can go max
libraryLocations List A list of all the current game locations
folder System.IO.DirectoryInfo The folder to scan
return void
        private static void ScanRecursive(int current, int max, List<string> libraryLocations, DirectoryInfo folder)
        {
            // Make sure we are not too deep
            if (max >= current)
            {
                // Get all the sub folders and iterate over them
                DirectoryInfo[] folders;
                try
                {
                    folders = folder.GetDirectories();
                }
                    // Make sure we have access to read the folder
                catch (UnauthorizedAccessException)
                {
                    return;
                }
                // Avoid any other errors
                catch (IOException)
                {
                    return;
                }

                foreach (DirectoryInfo f in folders)
                {
                    // Check for special windows directories
                    if (f.Name.StartsWith("$"))
                    {
                        continue;
                    }
                    // Check if the directory is a hidden directory
                    // because we shouldn't search those
                    if ((f.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        continue;
                    }
                    // Another data directory which we should skip
                    if (f.Name.Equals("Common Files"))
                    {
                        continue;
                    }
                    // Check if we can a match on the folder
                    if (!CheckFolder(f, libraryLocations))
                    {
                        // We didn't, so we should scan the subfolders
                        ScanRecursive(current + 1, max, libraryLocations, f);
                    }
                }
            }
        }