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); } }
private static void AddFrameworkConfiguration(ref string projectContent, string frameworkPath) { string directoryPath = System.IO.Path.GetDirectoryName(frameworkPath); string relativePath = FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, directoryPath); string newValue = "\"\\\"$(SRCROOT)/" + relativePath + "\\\"\""; //Debug.Log("the new value is: " + newValue); ModifyBuildSetting(ref projectContent, ProjectSettingType.FrameworkSearchPath, newValue, ModifyType.Append); }
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!"); }