private static ProjectFileInformation GetStoreKitFrameworkFileInformation(string projectFilePath)
    {
        FrameworkFileInformation result = new FrameworkFileInformation();

        result.FrameworkType = FrameworkType.StoreKit;
        result.FileType      = ProjectFileType.Framework;
        return(result);

        //XcodeModifyHelper.ModifyXcodeProject(new List<string>(){"StoreKit.framework"},projectFilePath, ProjectFileType.Framework);
    }
Beispiel #2
0
    private static string AddBuildFile(ref string projectContent, ProjectFileInformation fileInfo, string refFileGuid)
    {
        string pattern = "/\\* Begin PBXBuildFile section \\*/\n((?:.|\n)+?)/\\* End PBXBuildFile section \\*/";
        Match  match   = Regex.Match(projectContent, pattern);

        if (!match.Success)
        {
            Debug.Log("Couldn't find PBXBuildFile section.");
            return(null);
        }
        else
        {
            string buildFileContent = match.Groups[1].Value;
            string buildFilePattern = "([A-Z0-9]+).+?fileRef = " + Regex.Escape(refFileGuid);
            Match  m = Regex.Match(buildFileContent, buildFilePattern);
            if (m.Success)
            {
                Debug.Log("This build file already exists: " + fileInfo.FileName);
                return(m.Groups[1].Value);
            }
            else
            {
                string guid    = GenerateGUID();
                string addLine = "\t\t" + guid + " /* " + fileInfo.FileName + " in " + fileInfo.FileType +
                                 " */ = {isa = PBXBuildFile; fileRef = " + refFileGuid +
                                 " /* " + fileInfo.FileName + " */; ";
                FrameworkFileInformation frameworkInfo = fileInfo as FrameworkFileInformation;
                if (frameworkInfo != null && frameworkInfo.IsWeak)
                {
                    addLine = addLine + "settings = {ATTRIBUTES = (Weak, ); }; ";
                }

                addLine        = addLine + "};\n";
                projectContent = projectContent.Substring(0, match.Groups[1].Index) + addLine + projectContent.Substring(match.Groups[1].Index);
                return(guid);
            }
        }
    }
Beispiel #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);
    }
Beispiel #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!");
    }