Пример #1
0
        private static void AddTwitterFilesToProject()
        {
            string _twitterNativeFolder = AssetsUtility.AssetPathToAbsolutePath(kRelativePathToTwitterNativeFiles);
            string _twitterConfileFile  = Path.Combine(_twitterNativeFolder, "Config.txt");

            // Re move the files if version has changed
            if (File.Exists(_twitterConfileFile))
            {
                string _fileVersion = File.ReadAllText(_twitterConfileFile);

                if (string.Compare(_fileVersion, EditorPrefs.GetString(kTwitterConfigKey, "0")) == 0)
                {
                    return;
                }

                EditorPrefs.SetString(kTwitterConfigKey, _fileVersion);
            }

            // Start moving files and framework
            string _projectPath           = AssetsUtility.GetProjectPath();
            string _twitterExternalFolder = Path.Combine(_projectPath, kExtenalFolderRelativePath + "/Twitter");

            if (Directory.Exists(_twitterExternalFolder))
            {
                Directory.Delete(_twitterExternalFolder, true);
            }

            Directory.CreateDirectory(_twitterExternalFolder);

            List <string> _twitterFilesList  = new List <string>();
            List <string> _twitterFolderList = new List <string>();

            // ***********************
            // Source code section
            // ***********************
            string _nativeCodeSourceFolder = Path.Combine(_twitterNativeFolder, "Source");
            string _nativeCodeDestFolder   = Path.Combine(_twitterExternalFolder, "Source");

            // Copying folder
            IOExtensions.CopyFilesRecursively(_nativeCodeSourceFolder, _nativeCodeDestFolder);

            // Adding source folder to modifier
            _twitterFolderList.Add("Twitter/Source:-fno-objc-arc");

            // ***********************
            // Framework Section
            // ***********************
            string[] _zippedFrameworkFiles = Directory.GetFiles(_twitterNativeFolder, "*.gz", SearchOption.AllDirectories);
            string   _destFrameworkFolder  = Path.Combine(_twitterExternalFolder, "Framework");

            if (!Directory.Exists(_destFrameworkFolder))
            {
                Directory.CreateDirectory(_destFrameworkFolder);
            }

            // Iterate through each zip files
            foreach (string _curZippedFile in _zippedFrameworkFiles)
            {
                Zip.DecompressToDirectory(_curZippedFile, _destFrameworkFolder);

                // Adding file to modifier
                _twitterFilesList.Add("Twitter/Framework/" + Path.GetFileNameWithoutExtension(_curZippedFile));
            }

            // ***********************
            // Xcode modifier Section
            // ***********************
            Dictionary <string, object> _xcodeModDict = new Dictionary <string, object>();

            _xcodeModDict["group"]      = "NativePlugins-Twitter";
            _xcodeModDict["libs"]       = new string[0];
            _xcodeModDict["frameworks"] = new string[] {
                "Accounts.framework:weak",
                "Social.framework:weak"
            };
            _xcodeModDict["headerpaths"] = new string[0];
            _xcodeModDict["files"]       = _twitterFilesList;
            _xcodeModDict["folders"]     = _twitterFolderList;
            _xcodeModDict["excludes"]    = new string[] {
                "^.*.meta$",
                "^.*.mdown$",
                "^.*.pdf$",
                "^.*.DS_Store"
            };
            _xcodeModDict["compiler_flags"] = new string[0];
            _xcodeModDict["linker_flags"]   = new string[0];

            File.WriteAllText(GetTwitterXcodeModFilePath(), _xcodeModDict.ToJSON());
        }
Пример #2
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

#if !XCODE_PROJECT_USES_SOFT_LINKS
            string groupFolderPath = Path.Combine(Path.Combine(projectRootPath, "Plugins"), mod.group);
#endif

//			Debug.Log( "Adding libraries..." );
            foreach (XCModFile libRef in mod.libs)
            {
                string completeLibPath = Path.Combine("usr/lib", libRef.filePath);
//				Debug.Log ("Adding library " + completeLibPath);
                this.AddFile(completeLibPath, modGroup, "SDKROOT", true, libRef.isWeak);
            }

//			Debug.Log( "Adding frameworks..." );
            PBXGroup frameworkGroup = this.GetGroup("Frameworks");
            foreach (string framework in mod.frameworks)
            {
                string[] filename     = framework.Split(':');
                bool     isWeak       = (filename.Length > 1) ? true : false;
                string   completePath = Path.Combine("System/Library/Frameworks", filename[0]);
                this.AddFile(completePath, frameworkGroup, "SDKROOT", true, isWeak);
            }

//			Debug.Log ( "Adding files..." );
            foreach (string file in mod.files)
            {
                string[] args             = file.Split(':');
                string   fileRelativePath = args[0];
                string   compilerFlags    = (args.Length > 1) ? args[1] : null;
                string   fileAbsolutePath = Path.Combine(mod.path, fileRelativePath);

#if XCODE_PROJECT_USES_SOFT_LINKS
                // Will create reference to this file
                this.AddFile(fileAbsolutePath, modGroup, compilerFlags: compilerFlags);
#else
                // Create a hard copy of the file, placed at build folder
                string finalFileAbsolutePath = Path.Combine(groupFolderPath, fileRelativePath);

                if (File.Exists(fileAbsolutePath))
                {
                    CopyFileFrom(fileAbsolutePath, finalFileAbsolutePath);
                }
                else if (Directory.Exists(fileAbsolutePath))
                {
                    IOExtensions.CopyFilesRecursively(fileAbsolutePath, finalFileAbsolutePath, true);
                }
                else
                {
                    continue;
                }

                // Now add this new copy to xcode project
                this.AddFile(finalFileAbsolutePath, modGroup, compilerFlags: compilerFlags);
#endif
            }

//			Debug.Log ( "Adding folders..." );
            foreach (string folder in mod.folders)
            {
                string[] args = folder.Split(':');
                string   folderRelativePath = args[0];
                string   compilerFlags      = (args.Length > 1) ? args[1] : null;
                string   folderAbsolutePath = Path.Combine(mod.path, folderRelativePath);

#if XCODE_PROJECT_USES_SOFT_LINKS
                // Will create reference to this folder
                this.AddFolder(folderAbsolutePath, modGroup, (string[])mod.excludes.ToArray(typeof(string)), compilerFlags: compilerFlags);
#else
                // Check if source folder exist
                if (!Directory.Exists(folderAbsolutePath))
                {
                    continue;
                }

                // Make a hard copy of this folder
                string finalFolderAbsolutePath = Path.Combine(groupFolderPath, folderRelativePath);

                IOExtensions.CopyFilesRecursively(folderAbsolutePath, finalFolderAbsolutePath, true);

                // Now add this new copy to xcode project
                this.AddFolder(finalFolderAbsolutePath, modGroup, (string[])mod.excludes.ToArray(typeof(string)), compilerFlags: compilerFlags);
#endif
            }

//			Debug.Log( "Adding headerpaths..." );
            foreach (string headerpath in mod.headerpaths)
            {
                string[] args      = headerpath.Split(':');
                bool     recursive = args.Length > 1 ? args[1].Equals("recursive") : false;

                if (args[0].Contains("$(inherited)"))
                {
//					Debug.Log ("not prepending a path to " + args[0]);
                    this.AddHeaderSearchPaths(args[0], recursive);
                }
                else
                {
#if XCODE_PROJECT_USES_SOFT_LINKS
                    string absoluteHeaderPath = Path.Combine(mod.path, args[0]);
#else
                    string absoluteHeaderPath = Path.Combine(Path.Combine("$(SRCROOT)/Plugins", mod.group), args[0]);
#endif
                    Debug.Log("Adding header path " + absoluteHeaderPath + " Recursive " + recursive);
                    this.AddHeaderSearchPaths(absoluteHeaderPath, recursive);
                }
            }

//			Debug.Log( "Adding compiler flags..." );
            foreach (string flag in mod.compiler_flags)
            {
                this.AddOtherCFlags(flag);
            }

//			Debug.Log( "Adding linker flags..." );
            foreach (string flag in mod.linker_flags)
            {
                this.AddOtherLinkerFlags(flag);
            }

            this.Consolidate();
        }