FindFileReference() public method

Finds the file reference.
public FindFileReference ( String name ) : PBXFileReference
name String The name.
return PBXFileReference
Exemplo n.º 1
0
        /// <summary>
        ///   Removes the file.
        /// </summary>
        /// <param name = "groups">The groups.</param>
        /// <param name = "file">The file.</param>
        /// <returns></returns>
        public PBXFileReference RemoveFile(String groups, String file)
        {
            lock (this.syncRoot) {
                // Prepare the group that contains the file
                PBXGroup         group         = this.GetGroup(groups);
                PBXFileReference fileReference = null;
                PBXFileElement   result        = null;

                // Extract information
                String name      = Path.GetFileName(file);
                String parentDir = Path.GetDirectoryName(file);

                // If the file is localized, search for the variant group
                if (Path.GetExtension(parentDir).Equals(".lproj"))
                {
                    PBXVariantGroup variantGroup = group.FindVariantGroup(name);
                    if (variantGroup != null)
                    {
                        // The file is named like the language
                        name = Path.GetFileNameWithoutExtension(parentDir);
                    }
                    group  = variantGroup;
                    result = variantGroup;
                }

                if (group != null)
                {
                    // Search for the file and remove it
                    fileReference = group.FindFileReference(name);
                    if (fileReference != null)
                    {
                        group.RemoveChild(fileReference);
                    }
                }

                if (result == null)
                {
                    result = fileReference;
                }
                return(fileReference);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Adds the file.
        /// </summary>
        /// <param name = "groups">The groups.</param>
        /// <param name = "file">The file.</param>
        /// <param name = "sourceTree">The source tree.</param>
        /// <returns></returns>
        public PBXFileElement AddFile(String groups, String file, PBXSourceTree sourceTree)
        {
            lock (this.syncRoot) {
                // Prepare the group that will contain the file
                PBXGroup         group         = this.GetGroup(groups);
                PBXFileReference fileReference = null;
                PBXFileElement   result        = null;

                // Extract information
                String name    = Path.GetFileName(file);
                String path    = Path.GetFullPath(file);
                String rootDir = Path.GetFullPath(this.Dir);
                if (!String.IsNullOrEmpty(this.BaseDir))
                {
                    rootDir = Path.Combine(rootDir, this.BaseDir);
                    rootDir = Path.GetFullPath(rootDir);
                }
                String parentDir = Path.GetDirectoryName(file);

                // If the file is localized, then add it to a variant group
                if (Path.GetExtension(parentDir).Equals(".lproj"))
                {
                    // The variant group may exists to search for it
                    PBXVariantGroup variantGroup = group.FindVariantGroup(name);
                    if (variantGroup == null)
                    {
                        variantGroup = new PBXVariantGroup(name);
                        group.AddChild(variantGroup);
                    }

                    // The file is named like the language
                    name   = Path.GetFileNameWithoutExtension(parentDir);
                    group  = variantGroup;
                    result = variantGroup;
                }

                // Check if the file already exists
                fileReference = group.FindFileReference(name);
                if (fileReference == null)
                {
                    // Create a file reference
                    fileReference = new PBXFileReference(name);

                    // Set the source tree if none specified
                    if (sourceTree != PBXSourceTree.None)
                    {
                        fileReference.SourceTree = sourceTree;
                    }
                    else
                    {
                        if (path.StartsWith(rootDir))
                        {
                            path = path.Substring(rootDir.Length + 1);
                            fileReference.SourceTree = PBXSourceTree.Group;
                        }
                        else
                        {
                            fileReference.SourceTree = PBXSourceTree.Absolute;
                        }
                    }
                    fileReference.Path = path;
                    fileReference.LastKnownFileType = GetFileType(file);

                    // Add it to the group
                    group.AddChild(fileReference);
                }

                return(result ?? fileReference);
            }
        }