private static string GetPhaseGuid(ProjectPhaseInformation phaseInfo) { if (!buildPhaseDict.ContainsKey(phaseInfo.PhaseType)) { string pattern = "([A-Z0-9]+) /\\* " + Regex.Escape(targetName) + " \\*/ = \\{\n[ \t]+isa = PBXNativeTarget;(?:.|\n)+?buildConfigurationList = ([A-Z0-9]+)(?:.|\n)+?buildPhases = \\(\n((?:.|\n)+?)\\);"; Match match = Regex.Match(projectContent, pattern); if (!match.Success) { Debug.Log("Can't recover: Unable to find the build phases from your target: " + targetName); return(string.Empty); } else { string phasesContent = match.Groups[3].Value; string phaseGuid = FindPhaseGuid(phasesContent, phaseInfo.PhaseName); if (phaseGuid == null) { Debug.Log("Can't recover: Unable to find the " + phaseInfo.PhaseName + " phase from your target: " + targetName); return(string.Empty); } else { buildPhaseDict.Add(phaseInfo.PhaseType, phaseGuid); } } } return(buildPhaseDict[phaseInfo.PhaseType]); }
private static void AddBuildFileToPhase(ref string projectContent, string buildFileGuid, string fileName, ProjectPhaseInformation phaseInfo) { //Debug.Log(fileName); //Debug.Log(fileName + " : " + phaseInfo.PhaseType.ToString()); //Debug.Log (phaseInfo.PhaseName); string phaseName = phaseInfo.PhaseName; if (System.IO.Path.GetExtension(fileName).Equals(".h")) { return; } string phaseGuid = GetPhaseGuid(phaseInfo); //buildPhaseDict[phaseInfo.PhaseType]; string pattern = Regex.Escape(phaseGuid) + " /\\* " + Regex.Escape(phaseName) + " \\*/ = \\{(?:.|\n)+?files = \\(((?:.|\n)+?)\\)"; Match match = Regex.Match(projectContent, pattern); if (!match.Success) { Debug.Log("Couldn't find the " + phaseName + " phase."); return; } else { string phaseContent = match.Groups[1].Value; Match m = Regex.Match(phaseContent, Regex.Escape(buildFileGuid)); if (m.Success) { Debug.Log("The file has already been added."); return; } else { string addLine = "\t\t\t\t" + buildFileGuid + " /* " + fileName + " in " + phaseName + " */,\n"; projectContent = projectContent.Substring(0, match.Groups[1].Index) + addLine + projectContent.Substring(match.Groups[1].Index); } } }