Ejemplo n.º 1
0
    private static string AddGroup(ref string projectContent, ProjectGroupInformation groupInfo)
    {
        string pattern = "([A-Z0-9]+) /\\* " + Regex.Escape(groupInfo.GroupName) + " \\*/ = \\{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \\(\n((?:.|\n)+?)\\);";
        Match  match   = Regex.Match(projectContent, pattern);

        if (match.Success)
        {
            Debug.Log("The group is Already exists.");
            return(match.Groups[1].Value);
        }
        else
        {
            pattern = "/\\* Begin PBXGroup section \\*/((?:.|\n)+?)/\\* End PBXGroup section \\*/";
            match   = Regex.Match(projectContent, pattern);

            string groupGuid = GenerateGUID();

            string addString = string.Empty;
            if (string.IsNullOrEmpty(groupInfo.GroupPath))
            {
                addString = string.Format("{0}{1} /* {2} */ = {3}{0}\tisa = PBXGroup;{0}\tchildren = ({0}\t);{0}\tname = {2};{0}\tsourceTree =  \"<group>\";{0}{4};",
                                          "\n\t\t\t\t", groupGuid, groupInfo.GroupName, "{", "}");
            }
            else
            {
                string path = groupInfo.IsRoot ? FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, groupInfo.GroupPath) : groupInfo.GroupPath;

                addString = string.Format("{0}{1} /* {2} */ = {4}{0}\tisa = PBXGroup;{0}\tchildren = ({0}\t);{0}\tname={2};{0}\tpath = {3};{0}\tsourceTree =  \"<group>\";{0}{5};",
                                          "\n\t\t\t\t", groupGuid, groupInfo.GroupName, path, "{", "}");
            }
            projectContent = projectContent.Substring(0, match.Groups[1].Index) + addString + projectContent.Substring(match.Groups[1].Index);
            return(groupGuid);
        }
    }
Ejemplo n.º 2
0
    private static void AddFileToGroup(ref string projectContent, string groupName, string fileGuid, string fileName)
    {
        string pattern = "/\\* " + Regex.Escape(groupName) + " \\*/ = \\{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \\(\n((?:.|\n)+?)\\);";
        Match  match   = Regex.Match(projectContent, pattern);

        Debug.Log(groupName);
        if (!match.Success)
        {
            Debug.Log("1");
            ProjectGroupInformation groupInfo = new ProjectGroupInformation()
            {
                GroupName = groupName
            };
            string groupGuid = AddGroup(ref projectContent, groupInfo);
            AddFileToGroup(ref projectContent, "CustomTemplate", groupGuid, groupInfo.GroupName);
            match = Regex.Match(projectContent, pattern);

            Debug.Log(match.Groups[1].Value);
        }

        string childrenContent = match.Groups[1].Value;
        Match  m = Regex.Match(childrenContent, Regex.Escape(fileGuid));

        if (m.Success)
        {
            Debug.Log("This file is already a member of the " + groupName + " group.");
            return;
        }
        else
        {
            string addLine = "\t\t\t\t" + fileGuid + " /* " + fileName + " */,\n";
            projectContent = projectContent.Substring(0, match.Groups[1].Index) + addLine + projectContent.Substring(match.Groups[1].Index);
        }
    }
Ejemplo n.º 3
0
    public static List <ProjectItemInformation> GetItemsFromDirectory(string directoryPath, string parentGroupName, bool isRoot)
    {
        string[] files = System.IO.Directory.GetFiles(directoryPath);

        List <ProjectItemInformation> fileInfos = new List <ProjectItemInformation>();

        foreach (string file in files)
        {
            string extension = System.IO.Path.GetExtension(file);
            if (!extension.Equals(".meta") && !extension.Equals(".DS_Store"))
            {
                if (extension.Equals(".a") || extension.Equals(".h") || extension.Equals(".m") || extension.Equals(".mm"))
                {
                    SourceFileInformation sourceInfo = new SourceFileInformation();
                    sourceInfo.FileName        = System.IO.Path.GetFileName(file);
                    sourceInfo.FilePath        = file;
                    sourceInfo.ParentGroupName = parentGroupName;
                    fileInfos.Add(sourceInfo);
                }
            }
        }

        string[] directories = System.IO.Directory.GetDirectories(directoryPath);

        List <ProjectItemInformation> directoryInfos = new List <ProjectItemInformation>();

        foreach (string directory in directories)
        {
            string extension = System.IO.Path.GetExtension(directory);
            if (!extension.Equals(".meta") && !extension.Equals(".DS_Store"))
            {
                if (System.IO.Path.GetExtension(directory).Equals(".framework"))
                {
                    FrameworkFileInformation frameworkInfo = new FrameworkFileInformation();
                    frameworkInfo.FileName = System.IO.Path.GetFileName(directory);

                    Debug.Log(frameworkInfo.FileName);

                    frameworkInfo.FilePath        = directory;
                    frameworkInfo.FrameworkType   = FrameworkType.Custom;
                    frameworkInfo.ParentGroupName = parentGroupName;
                    directoryInfos.Add(frameworkInfo);
                }
                else if (System.IO.Path.GetExtension(directory).Equals(".bundle"))
                {
                    ResourceFileInformation resourceInfo = new ResourceFileInformation();

                    resourceInfo.FileName        = System.IO.Path.GetFileName(directory);
                    resourceInfo.FilePath        = directory;
                    resourceInfo.ParentGroupName = parentGroupName;
                    directoryInfos.Add(resourceInfo);
                }
                else
                {
                    ProjectGroupInformation groupInfo = new ProjectGroupInformation();
                    groupInfo.GroupName = System.IO.Path.GetFileName(directory);
                    if (isRoot)
                    {
                        groupInfo.GroupPath = directory;
                        groupInfo.IsRoot    = true;
                    }
                    else
                    {
                        groupInfo.GroupPath = groupInfo.GroupName;
                        groupInfo.IsRoot    = false;
                    }
                    groupInfo.ParentGroupName = parentGroupName;
                    directoryInfos.Add(groupInfo);
                    directoryInfos.AddRange(GetItemsFromDirectory(directory, groupInfo.GroupName, false));
                }
            }
        }

        List <ProjectItemInformation> result = new List <ProjectItemInformation>();

        result.AddRange(fileInfos);
        result.AddRange(directoryInfos);
        return(result);
    }
Ejemplo n.º 4
0
    public static void ModifyXcodeProject(List <ProjectItemInformation> items, string projectFilePath)
    {
        string       projectSettingFileName = GetXcodeProjectFilePath(projectFilePath);
        FileStream   stream  = File.Open(projectSettingFileName, FileMode.Open, FileAccess.Read);
        StreamReader reader  = new StreamReader(stream);
        string       content = reader.ReadToEnd();

        reader.Close();

        projectPath    = projectFilePath;
        projectContent = content;
        targetName     = DEPLOY_TARGET_NAME;

        buildPhaseDict.Clear();
        InitializeConfigurationGuid();

        foreach (ProjectItemInformation item in items)        //(string fileName in files)
        {
            if (item is ProjectGroupInformation)
            {
                ProjectGroupInformation info = item as ProjectGroupInformation;
                string referenceGroupGuid    = AddGroup(ref content, info);
                AddFileToGroup(ref content, info.ParentGroupName, referenceGroupGuid, info.GroupName);
            }
            else
            {
                ProjectFileInformation info = item as ProjectFileInformation;
                info.Initialize();

                if (info is FrameworkFileInformation)
                {
                    FrameworkFileInformation frameworkInfo = info as FrameworkFileInformation;
                    if (frameworkInfo.FrameworkType == FrameworkType.Custom)
                    {
                        AddFrameworkConfiguration(ref content, frameworkInfo.FilePath);
                        frameworkInfo.FilePath = frameworkInfo.FileName;
                    }
                }

                if (info is ResourceFileInformation)
                {
                    info.FilePath = FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, info.FilePath);
                }
                else if (info is SourceFileInformation)
                {
                    info.FilePath = FileOperateHelper.GetRelativePathFromAbsolutePath(System.IO.Path.Combine(projectPath, "Classes"), info.FilePath);
                }

                string referenceFileGuid = AddFileReference(ref content, info);
                AddFileToGroup(ref content, info.ParentGroupName, referenceFileGuid, info.FileName);
                if (info.Phase != null)
                {
                    string buildFileGuid = AddBuildFile(ref content, info, referenceFileGuid);
                    AddBuildFileToPhase(ref content, buildFileGuid, info.FileName, info.Phase);
                }
            }
        }

        stream = File.Open(projectSettingFileName, FileMode.Create, FileAccess.Write);
        StreamWriter writer = new StreamWriter(stream);

        writer.Write(content);
        writer.Close();

        Debug.Log("Success!");
    }