UnityEditor.XCodeEditor.XCProject.AddFolder C# (CSharp) Method

AddFolder() public method

public AddFolder ( string folderPath, UnityEditor.XCodeEditor.PBXGroup parent = null, string exclude = null, bool recursive = true, bool createBuildFile = true ) : bool
folderPath string
parent UnityEditor.XCodeEditor.PBXGroup
exclude string
recursive bool
createBuildFile bool
return bool
        public bool AddFolder( string folderPath, PBXGroup parent = null, string[] exclude = null, bool recursive = true, bool createBuildFile = true )
        {
            if( !Directory.Exists( folderPath ) )
                return false;
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo( folderPath );

            if( exclude == null )
                exclude = new string[] {};
            string regexExclude = string.Format( @"{0}", string.Join( "|", exclude ) );

            PBXDictionary results = new PBXDictionary();

            if( parent == null )
                parent = rootGroup;

            // Create group
            PBXGroup newGroup = GetGroup( sourceDirectoryInfo.Name, null /*relative path*/, parent );
            //			groups.Add( newGroup );

            foreach( string directory in Directory.GetDirectories( folderPath ) )
            {
                if( Regex.IsMatch( directory, regexExclude ) ) {
                    continue;
                }

            //				special_folders = ['.bundle', '.framework', '.xcodeproj']
                Debug.Log( "DIR: " + directory );
                if( directory.EndsWith( ".bundle" ) ) {
                    // Treath it like a file and copy even if not recursive
                    Debug.LogWarning( "This is a special folder: " + directory );
                    AddFile( directory, newGroup, "SOURCE_ROOT", createBuildFile );
                    Debug.Log( "fatto" );
                    continue;
                }

                if( recursive ) {
                    Debug.Log( "recursive" );
                    AddFolder( directory, newGroup, exclude, recursive, createBuildFile );
                }
            }
            // Adding files.
            foreach( string file in Directory.GetFiles( folderPath ) ) {
                if( Regex.IsMatch( file, regexExclude ) ) {
                    continue;
                }
                //Debug.Log( "--> " + file + ", " + newGroup );
                AddFile( file, newGroup, "SOURCE_ROOT", createBuildFile );
            }

            modified = true;
            return modified;
            //		def add_folder(self, os_path, parent=None, excludes=None, recursive=True, create_build_files=True):
            //        if not os.path.isdir(os_path):
            //            return []
            //
            //        if not excludes:
            //            excludes = []
            //
            //        results = []
            //
            //        if not parent:
            //            parent = self.root_group
            //        elif not isinstance(parent, PBXGroup):
            //            # assume it's an id
            //            parent = self.objects.get(parent, self.root_group)
            //
            //        path_dict = {os.path.split(os_path)[0]:parent}
            //        special_list = []
            //
            //        for (grp_path, subdirs, files) in os.walk(os_path):
            //            parent_folder, folder_name = os.path.split(grp_path)
            //            parent = path_dict.get(parent_folder, parent)
            //
            //            if [sp for sp in special_list if parent_folder.startswith(sp)]:
            //                continue
            //
            //            if folder_name.startswith('.'):
            //                special_list.append(grp_path)
            //                continue
            //
            //            if os.path.splitext(grp_path)[1] in XcodeProject.special_folders:
            //                # if this file has a special extension (bundle or framework mainly) treat it as a file
            //                special_list.append(grp_path)
            //
            //                new_files = self.verify_files([folder_name], parent=parent)
            //
            //                if new_files:
            //                    results.extend(self.add_file(grp_path, parent, create_build_files=create_build_files))
            //
            //                continue
            //
            //            # create group
            //            grp = self.get_or_create_group(folder_name, path=self.get_relative_path(grp_path) , parent=parent)
            //            path_dict[grp_path] = grp
            //
            //            results.append(grp)
            //
            //            file_dict = {}
            //
            //            for f in files:
            //                if f[0] == '.' or [m for m in excludes if re.match(m,f)]:
            //                    continue
            //
            //                kwds = {
            //                    'create_build_files': create_build_files,
            //                    'parent': grp,
            //                    'name': f
            //                }
            //
            //                f_path = os.path.join(grp_path, f)
            //
            //                file_dict[f_path] = kwds
            //
            //            new_files = self.verify_files([n.get('name') for n in file_dict.values()], parent=grp)
            //
            //            add_files = [(k,v) for k,v in file_dict.items() if v.get('name') in new_files]
            //
            //            for path, kwds in add_files:
            //                kwds.pop('name', None)
            //
            //                self.add_file(path, **kwds)
            //
            //            if not recursive:
            //                break
            //
            //        for r in results:
            //            self.objects[r.id] = r
            //
            //        return results
        }