public static void WriteDict(StringBuilder sb, PBXElementDict el, int indent, bool compact,
                                     PropertyCommentChecker checker, GUIDToCommentMap comments)
        {
            sb.Append("{");

            if (el.Contains("isa"))
            {
                WriteDictKeyValue(sb, "isa", el["isa"], indent + 1, compact, checker, comments);
            }
            var keys = new List <string>(el.values.Keys);

            keys.Sort(StringComparer.Ordinal);
            foreach (var key in keys)
            {
                if (key != "isa")
                {
                    WriteDictKeyValue(sb, key, el[key], indent + 1, compact, checker, comments);
                }
            }
            if (!compact)
            {
                sb.Append("\n");
                sb.Append(GetIndent(indent));
            }
            sb.Append("}");
        }
        public static void WriteDictKeyValue(StringBuilder sb, string key, PBXElement value, int indent, bool compact,
                                             PropertyCommentChecker checker, GUIDToCommentMap comments)
        {
            if (!compact)
            {
                sb.Append("\n");
                sb.Append(GetIndent(indent));
            }
            WriteStringImpl(sb, key, checker.CheckKeyInDict(key), comments);
            sb.Append(" = ");

            if (value is PBXElementString)
            {
                WriteStringImpl(sb, value.AsString(), checker.CheckStringValueInDict(key, value.AsString()), comments);
            }
            else if (value is PBXElementDict)
            {
                WriteDict(sb, value.AsDict(), indent, compact, checker.NextLevel(key), comments);
            }
            else if (value is PBXElementArray)
            {
                WriteArray(sb, value.AsArray(), indent, compact, checker.NextLevel(key), comments);
            }
            sb.Append(";");
            if (compact)
            {
                sb.Append(" ");
            }
        }
 static void WriteStringImpl(StringBuilder sb, string s, bool comment, GUIDToCommentMap comments)
 {
     if (comment)
     {
         comments.WriteStringBuilder(sb, s);
     }
     else
     {
         sb.Append(PBXStream.QuoteStringIfNeeded(s));
     }
 }
Exemple #4
0
        public string WriteToString()
        {
            var commentMap      = BuildCommentMap();
            var emptyChecker    = new PropertyCommentChecker();
            var emptyCommentMap = new GUIDToCommentMap();

            // since we need to add custom comments, the serialization is much more complex
            StringBuilder objectsSb = new StringBuilder();

            if (m_ObjectVersion != null) // objectVersion comes right before objects
            {
                objectsSb.AppendFormat("objectVersion = {0};\n\t", m_ObjectVersion);
            }
            objectsSb.Append("objects = {");
            foreach (string sectionName in m_SectionOrder)
            {
                if (m_Section.ContainsKey(sectionName))
                {
                    m_Section[sectionName].WriteSection(objectsSb, commentMap);
                }
                else if (m_UnknownSections.ContainsKey(sectionName))
                {
                    m_UnknownSections[sectionName].WriteSection(objectsSb, commentMap);
                }
            }
            foreach (var kv in m_UnknownObjects.values)
            {
                Serializer.WriteDictKeyValue(objectsSb, kv.Key, kv.Value, 2, false, emptyChecker, emptyCommentMap);
            }
            objectsSb.Append("\n\t};");

            StringBuilder contentSb = new StringBuilder();

            contentSb.Append("// !$*UTF8*$!\n");
            Serializer.WriteDict(contentSb, m_RootElements, 0, false,
                                 new PropertyCommentChecker(new string[] { "rootObject/*" }), commentMap);
            contentSb.Append("\n");
            string content = contentSb.ToString();

            content = content.Replace("objects = OBJMARKER;", objectsSb.ToString());
            return(content);
        }
        public static void WriteArray(StringBuilder sb, PBXElementArray el, int indent, bool compact,
                                      PropertyCommentChecker checker, GUIDToCommentMap comments)
        {
            sb.Append("(");
            foreach (var value in el.values)
            {
                if (!compact)
                {
                    sb.Append("\n");
                    sb.Append(GetIndent(indent + 1));
                }

                if (value is PBXElementString)
                {
                    WriteStringImpl(sb, value.AsString(), checker.CheckStringValueInArray(value.AsString()), comments);
                }
                else if (value is PBXElementDict)
                {
                    WriteDict(sb, value.AsDict(), indent + 1, compact, checker.NextLevel("*"), comments);
                }
                else if (value is PBXElementArray)
                {
                    WriteArray(sb, value.AsArray(), indent + 1, compact, checker.NextLevel("*"), comments);
                }
                sb.Append(",");
                if (compact)
                {
                    sb.Append(" ");
                }
            }

            if (!compact)
            {
                sb.Append("\n");
                sb.Append(GetIndent(indent));
            }
            sb.Append(")");
        }
Exemple #6
0
 private void BuildCommentMapForBuildFiles(GUIDToCommentMap comments, List <string> guids, string sectName)
 {
     foreach (var guid in guids)
     {
         var buildFile = BuildFilesGet(guid);
         if (buildFile != null)
         {
             var fileRef = FileRefsGet(buildFile.fileRef);
             if (fileRef != null)
             {
                 comments.Add(guid, String.Format("{0} in {1}", fileRef.name, sectName));
             }
             else
             {
                 var reference = references[buildFile.fileRef];
                 if (reference != null)
                 {
                     comments.Add(guid, String.Format("{0} in {1}", reference.path, sectName));
                 }
             }
         }
     }
 }
Exemple #7
0
        public override void WriteSection(StringBuilder sb, GUIDToCommentMap comments)
        {
            if (m_Entries.Count == 0)
            {
                return;            // do not write empty sections
            }
            sb.AppendFormat("\n\n/* Begin {0} section */", m_Name);
            var keys = new List <string>(m_Entries.Keys);

            keys.Sort(StringComparer.Ordinal);
            foreach (string key in keys)
            {
                T obj = m_Entries[key];
                obj.UpdateProps();
                sb.Append("\n\t\t");
                comments.WriteStringBuilder(sb, obj.guid);
                sb.Append(" = ");
                Serializer.WriteDict(sb, obj.GetPropertiesWhenSerializing(), 2,
                                     obj.shouldCompact, obj.checker, comments);
                sb.Append(";");
            }
            sb.AppendFormat("\n/* End {0} section */", m_Name);
        }
Exemple #8
0
        private GUIDToCommentMap BuildCommentMap()
        {
            GUIDToCommentMap comments = new GUIDToCommentMap();

            // buildFiles are handled below
            // filerefs are handled below
            foreach (var e in groups.GetObjects())
            {
                comments.Add(e.guid, e.name);
            }
            foreach (var e in containerItems.GetObjects())
            {
                comments.Add(e.guid, "PBXContainerItemProxy");
            }
            foreach (var e in references.GetObjects())
            {
                comments.Add(e.guid, e.path);
            }
            foreach (var e in sources.GetObjects())
            {
                comments.Add(e.guid, "Sources");
                BuildCommentMapForBuildFiles(comments, e.files, "Sources");
            }
            foreach (var e in resources.GetObjects())
            {
                comments.Add(e.guid, "Resources");
                BuildCommentMapForBuildFiles(comments, e.files, "Resources");
            }
            foreach (var e in frameworks.GetObjects())
            {
                comments.Add(e.guid, "Frameworks");
                BuildCommentMapForBuildFiles(comments, e.files, "Frameworks");
            }
            foreach (var e in embedFrameworks.GetObjects())
            {
                comments.Add(e.guid, "Embed Frameworks");
                BuildCommentMapForBuildFiles(comments, e.files, "Embed Frameworks");
            }
            foreach (var e in copyFiles.GetObjects())
            {
                string sectName = e.name;
                if (sectName == null)
                {
                    sectName = "CopyFiles";
                }
                comments.Add(e.guid, sectName);
                BuildCommentMapForBuildFiles(comments, e.files, sectName);
            }
            foreach (var e in shellScripts.GetObjects())
            {
                comments.Add(e.guid, "ShellScript");
            }
            foreach (var e in targetDependencies.GetObjects())
            {
                comments.Add(e.guid, "PBXTargetDependency");
            }
            foreach (var e in nativeTargets.GetObjects())
            {
                comments.Add(e.guid, e.name);
                comments.Add(e.buildConfigList, String.Format("Build configuration list for PBXNativeTarget \"{0}\"", e.name));
            }
            foreach (var e in variantGroups.GetObjects())
            {
                comments.Add(e.guid, e.name);
            }
            foreach (var e in buildConfigs.GetObjects())
            {
                comments.Add(e.guid, e.name);
            }
            foreach (var e in project.GetObjects())
            {
                comments.Add(e.guid, "Project object");
                comments.Add(e.buildConfigList, "Build configuration list for PBXProject \"Unity-iPhone\""); // FIXME: project name is hardcoded
            }
            foreach (var e in fileRefs.GetObjects())
            {
                comments.Add(e.guid, e.name);
            }
            if (m_RootElements.Contains("rootObject") && m_RootElements["rootObject"] is PBXElementString)
            {
                comments.Add(m_RootElements["rootObject"].AsString(), "Project object");
            }

            return(comments);
        }
Exemple #9
0
 public abstract void WriteSection(StringBuilder sb, GUIDToCommentMap comments);