Exemplo n.º 1
0
    private static void ModifyBuildSetting(ref string projectContent, ProjectSettingType settingType,
                                           string newValue, ModifyType modifyType)
    {
        foreach (string configurationGuid in buildConfigurationGuids)
        {
            string pattern = "/\\* Begin XCBuildConfiguration section \\*/(?:\n|.)+?" + configurationGuid +
                             " /\\* (\\w+?) \\*/ = \\{(?:.|\n)+?buildSettings = \\{\n((?:.|\n)+?)name = \\1;";

            Match m = Regex.Match(projectContent, pattern);

            if (!m.Success)
            {
                Debug.Log("No build setting section!");
            }
            else
            {
                string settingContent = m.Groups[2].Value;
                string settingKey     = settingKeyDict[settingType];
                pattern = Regex.Escape(settingKey) + " = \\(?\n?((?:.|\n)+?)\\)?;";

                Match contentMatch = Regex.Match(settingContent, pattern);
                if (!contentMatch.Success)
                {
                    string addString = "\t\t\t\t" + settingKey + " = ";
                    if (settingType == ProjectSettingType.LibrarySearchPath || settingType == ProjectSettingType.FrameworkSearchPath)
                    {
                        addString = addString + "(\n\t\t\t\t\t\"$(inherited)\",\n\t\t\t\t\t" + newValue + ",\n\t\t\t\t);\n";
                    }
                    else
                    {
                        addString = addString + newValue + ";\n";
                    }
                    projectContent = projectContent.Substring(0, m.Groups[2].Index) +
                                     addString + projectContent.Substring(m.Groups[2].Index);
                }
                else
                {
                    string contentValue = contentMatch.Groups[1].Value;
                    pattern = Regex.Escape(newValue);
                    Match valueMatch = Regex.Match(contentValue, pattern);
                    if (!valueMatch.Success)
                    {
                        string addString = newValue;
                        if (modifyType == ModifyType.Append)
                        {
                            addString = contentMatch.Groups[1].Value + addString + ",\n";
                        }
                        projectContent = projectContent.Substring(0, m.Groups[2].Index) +
                                         settingContent.Substring(0, contentMatch.Groups[1].Index) +
                                         addString + settingContent.Substring(contentMatch.Groups[1].Index + contentMatch.Groups[1].Length)
                                         + projectContent.Substring(m.Groups[2].Index + m.Groups[2].Length);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    /*
     * public static void ModifyXcodeProject(string fileFolderPath, string projectFilePath)
     * {
     *      string projectName = DEPLOY_PROJECT_NAME + ".xcodeproj";
     *      string xcodeProjectFilePath = System.IO.Path.Combine(projectFilePath,projectName);
     *      string projectSettingFileName = System.IO.Path.Combine(xcodeProjectFilePath,PROJECT_SETTING_FILE_NAME);
     *      FileStream stream = File.Open(projectSettingFileName,FileMode.Open,FileAccess.Read);
     *      StreamReader reader = new StreamReader(stream);
     *      string content = reader.ReadToEnd();
     *      reader.Close();
     *
     *      InitializeBuildPhaseAndConfigurationGuid(content, DEPLOY_TARGET_NAME);
     *
     *      if(Directory.Exists(fileFolderPath))
     *      {
     *              string groupName = fileFolderPath.Substring(fileFolderPath.LastIndexOf("/") + 1);
     *              //string groupName = System.IO.Path.GetFileName(fileFolderPath);
     *              //AddGroup(ref content, groupName);
     *              string groupGuid = AddGroup(ref content, groupName);
     *              AddFileToGroup(ref content, ROOT_GROUP_NAME, groupGuid, groupName);
     *              string[] files = Directory.GetFiles(fileFolderPath);
     *              foreach(string filePath in files)
     *              {
     *                      string fileExtension = System.IO.Path.GetExtension(filePath);
     *                      string fileName = System.IO.Path.GetFileName(filePath);
     *                      if(extesionFileTypeDict.ContainsKey(fileExtension))
     *                      {
     *                              ProjectFileType fileType = extesionFileTypeDict[System.IO.Path.GetExtension(fileName)];
     *                              string referenceFileGuid = AddFileReference(ref content, fileName, fileType);
     *                              AddFileToGroup(ref content, groupName, referenceFileGuid, fileName);
     *                              string buildFileGuid = AddBuildFile(ref content, fileName, referenceFileGuid, fileType);
     *                              AddBuildFileToPhase(ref content, buildFileGuid, fileName, fileTypeDict[fileType].PhaseType);
     *                              if(fileExtension.Equals(".a"))
     *                              {
     *                                      AddLibrarySearchConfiguration(ref content, groupName);
     *                              }
     *                      }
     *              }
     *
     *              stream = File.Open(projectSettingFileName,FileMode.Create,FileAccess.Write);
     *              StreamWriter writer = new StreamWriter(stream);
     *              writer.Write(content);
     *              writer.Close();
     *      }
     *      else
     *      {
     *              Debug.Log("There is no folder!");
     *      }
     *
     *      Debug.Log("Success!");
     * }
     */
    public static void ModifyBuildSetting(string projectFilePath, ProjectSettingType settingType,
                                          string newValue, ModifyType modifyType)
    {
        string       projectSettingFileName = GetXcodeProjectFilePath(projectFilePath);
        FileStream   stream  = File.Open(projectSettingFileName, FileMode.Open, FileAccess.Read);
        StreamReader reader  = new StreamReader(stream);
        string       content = reader.ReadToEnd();

        reader.Close();

        projectContent = content;
        targetName     = DEPLOY_TARGET_NAME;

        InitializeConfigurationGuid();

        ModifyBuildSetting(ref content, settingType, newValue, modifyType);

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

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