public static void AddOrUpdateForAllBuildProducts(IIgorModule ModuleInst, string ProjectPath, string Key, string Value) { if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(ProjectPath), "XCodeProj doesn't exist at path " + ProjectPath)) { XCProject CurrentProject = new XCProject(ProjectPath); CurrentProject.Backup(); foreach (KeyValuePair <string, XCBuildConfiguration> CurrentConfig in CurrentProject.buildConfigurations) { object BuildSettingsObj = CurrentConfig.Value.data["buildSettings"]; PBXDictionary BuildSettingsDict = (PBXDictionary)BuildSettingsObj; if (BuildSettingsDict.ContainsKey(Key)) { BuildSettingsDict[Key] = Value; IgorDebug.Log(ModuleInst, "Updated KeyValuePair (Key: " + Key + " Value: " + Value + ") to build target GUID " + CurrentConfig.Key); } else { BuildSettingsDict.Add(Key, Value); IgorDebug.Log(ModuleInst, "Added new KeyValuePair (Key: " + Key + " Value: " + Value + ") to build target GUID " + CurrentConfig.Key); } } CurrentProject.Save(); } }
public XCProject( string filePath ) : this() { if( !System.IO.Directory.Exists( filePath ) ) { Debug.LogWarning( "Path does not exists." ); return; } if( filePath.EndsWith( ".xcodeproj" ) ) { Debug.Log( "Opening project " + filePath ); this.projectRootPath = Path.GetDirectoryName( filePath ); this.filePath = filePath; } else { Debug.Log( "Looking for xcodeproj files in " + filePath ); string[] projects = System.IO.Directory.GetDirectories( filePath, "*.xcodeproj" ); if( projects.Length == 0 ) { Debug.LogWarning( "Error: missing xcodeproj file" ); return; } this.projectRootPath = filePath; this.filePath = projects[ 0 ]; } // Convert to absolute this.projectRootPath = Path.GetFullPath(this.projectRootPath); projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) ); StreamReader sr = projectFileInfo.OpenText(); string contents = sr.ReadToEnd(); sr.Close(); PBXParser parser = new PBXParser(); _datastore = parser.Decode( contents ); if( _datastore == null ) { throw new System.Exception( "Project file not found at file path " + filePath ); } if( !_datastore.ContainsKey( "objects" ) ) { Debug.Log( "Errore " + _datastore.Count ); return; } _objects = (PBXDictionary)_datastore["objects"]; modified = false; _rootObjectKey = (string)_datastore["rootObject"]; if( !string.IsNullOrEmpty( _rootObjectKey ) ) { // _rootObject = (PBXDictionary)_objects[ _rootObjectKey ]; _project = new PBXProject( _rootObjectKey, (PBXDictionary)_objects[ _rootObjectKey ] ); // _rootGroup = (PBXDictionary)_objects[ (string)_rootObject[ "mainGroup" ] ]; _rootGroup = new PBXGroup( _rootObjectKey, (PBXDictionary)_objects[ _project.mainGroupID ] ); } else { Debug.LogWarning( "error: project has no root object" ); _project = null; _rootGroup = null; } }
public PBXObject( string guid, PBXDictionary dictionary ) : this( guid ) { if( !dictionary.ContainsKey( ISA_KEY ) || ((string)dictionary[ ISA_KEY ]).CompareTo( this.GetType().Name ) != 0 ) Debug.LogError( "PBXDictionary is not a valid ISA object" ); foreach( KeyValuePair<string, object> item in dictionary ) { _data[ item.Key ] = item.Value; } }
public XCProject( string filePath ) : this() { if( !System.IO.Directory.Exists( filePath ) ) { Debug.LogWarning( "XCode project path does not exist: " + filePath ); return; } if( filePath.EndsWith( ".xcodeproj" ) ) { Debug.Log( "Opening project " + filePath ); this.projectRootPath = Path.GetDirectoryName( filePath ); this.filePath = filePath; } else { Debug.Log( "Looking for xcodeproj files in " + filePath ); string[] projects = System.IO.Directory.GetDirectories( filePath, "*.xcodeproj" ); if( projects.Length == 0 ) { Debug.LogWarning( "Error: missing xcodeproj file" ); return; } this.projectRootPath = filePath; //if the path is relative to the project, we need to make it absolute if (!System.IO.Path.IsPathRooted(projectRootPath)) projectRootPath = Application.dataPath.Replace("Assets", "") + projectRootPath; //Debug.Log ("projectRootPath adjusted to " + projectRootPath); this.filePath = projects[ 0 ]; } projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) ); string contents = projectFileInfo.OpenText().ReadToEnd(); PBXParser parser = new PBXParser(); _datastore = parser.Decode( contents ); if( _datastore == null ) { throw new System.Exception( "Project file not found at file path " + filePath ); } if( !_datastore.ContainsKey( "objects" ) ) { Debug.Log( "Errore " + _datastore.Count ); return; } _objects = (PBXDictionary)_datastore["objects"]; modified = false; _rootObjectKey = (string)_datastore["rootObject"]; if( !string.IsNullOrEmpty( _rootObjectKey ) ) { _project = new PBXProject( _rootObjectKey, (PBXDictionary)_objects[ _rootObjectKey ] ); _rootGroup = new PBXGroup( _rootObjectKey, (PBXDictionary)_objects[ _project.mainGroupID ] ); } else { Debug.LogWarning( "error: project has no root object" ); _project = null; _rootGroup = null; } }
static void InjectingTeamIdToPbxProjFile(string file) { UnityEngine.Debug.Log("InjectingTeamIdToPbxProjFile start"); XCProject project = new XCProject(file); if (project == null) { UnityEngine.Debug.LogError("Didn't manage to open project.pbxproj at " + file); return; } string teamId = null; try { teamId = PsdkiOSPostProcessUtils.GetTeamIdFromMobileProvision(); } catch (System.Exception e) { UnityEngine.Debug.LogException(e); } if (teamId == null) { UnityEngine.Debug.LogError("NULL iOS TeamIdentifier !!"); if (UnityEditorInternal.InternalEditorUtility.inBatchMode) { EditorApplication.Exit(-1); } } string targetGuid = null; foreach (var nt in project.nativeTargets) { targetGuid = nt.Key; break; } string rootObjectGuid = project.rootGroup.guid; PBXDictionary addedFile = project.AddFile("Unity-iPhone/tabtale.entitlements", null, "SDKROOT", false, true); foreach (PBXFileReference fr in addedFile.Values) { if (fr.ContainsKey("sourceTree")) { fr.data["sourceTree"] = "<group>"; } } UnityEngine.Debug.Log("targetguid: " + targetGuid); UnityEngine.Debug.Log("root Object guid: " + rootObjectGuid); PBXDictionary rootDict = project.GetObject(rootObjectGuid) as PBXDictionary; if (rootDict == null) { UnityEngine.Debug.LogError("null rootDict"); if (UnityEditorInternal.InternalEditorUtility.inBatchMode) { EditorApplication.Exit(-1); } return; } if (!rootDict.ContainsKey("attributes")) { UnityEngine.Debug.LogError("root dict does not contain attributes !"); if (UnityEditorInternal.InternalEditorUtility.inBatchMode) { EditorApplication.Exit(-1); } return; } PBXDictionary attributes = rootDict["attributes"] as PBXDictionary; if (!attributes.ContainsKey("TargetAttributes")) { attributes.Add("TargetAttributes", new PBXDictionary()); } PBXDictionary targetAttributes = attributes["TargetAttributes"] as PBXDictionary; if (!targetAttributes.ContainsKey(targetGuid)) { targetAttributes.Add(targetGuid, new PBXDictionary()); } PBXDictionary targetGuidScope = targetAttributes[targetGuid] as PBXDictionary; if (!targetGuidScope.ContainsKey("DevelopmentTeam")) { targetGuidScope.Add("DevelopmentTeam", teamId); } else { targetGuidScope["DevelopmentTeam"] = teamId; } if (!targetGuidScope.ContainsKey("SystemCapabilities")) { targetGuidScope.Add("SystemCapabilities", new PBXDictionary()); } PBXDictionary systemCapabilities = targetGuidScope["SystemCapabilities"] as PBXDictionary; if (!systemCapabilities.ContainsKey("com.apple.Keychain")) { systemCapabilities.Add("com.apple.Keychain", new PBXDictionary()); } PBXDictionary appleKeychain = systemCapabilities["com.apple.Keychain"] as PBXDictionary; if (!appleKeychain.ContainsKey("enabled")) { appleKeychain.Add("enabled", 1); } else { appleKeychain ["enabled"] = 1; } string jsonPath = System.IO.Path.Combine(Application.streamingAssetsPath, "psdk_ios.json"); if (File.Exists(jsonPath)) { string jsonStr = System.IO.File.ReadAllText(jsonPath); Dictionary <string, object> json = (Dictionary <string, object>)TabTale.Plugins.PSDK.Json.Deserialize(jsonStr); if (json.ContainsKey("crossDevicePersistency")) { Dictionary <string, object> cdpDict = (Dictionary <string, object>)json["crossDevicePersistency"]; if (cdpDict.ContainsKey("included")) { if ((bool)cdpDict["included"]) { if (!systemCapabilities.ContainsKey("com.apple.iCloud")) { systemCapabilities.Add("com.apple.iCloud", new PBXDictionary()); } PBXDictionary appleICloud = systemCapabilities["com.apple.iCloud"] as PBXDictionary; if (!appleICloud.ContainsKey("enabled")) { appleICloud.Add("enabled", 1); } else { appleICloud ["enabled"] = 1; } string strToAdd = "<key>com.apple.developer.icloud-container-identifiers</key>\n\t<array/>\n\t<key>com.apple.developer.ubiquity-kvstore-identifier</key>\n\t<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>"; string ent = File.ReadAllText(projectRootPath + "/Unity-iPhone/tabtale.entitlements"); if (!ent.Contains("<key>com.apple.developer.icloud-container-identifiers</key>")) { int entryPoint = ent.IndexOf("</dict>") - 1; ent = ent.Insert(entryPoint, strToAdd); } File.WriteAllText(projectRootPath + "/Unity-iPhone/tabtale.entitlements", ent); } } } } foreach (var item in project.buildConfigurations) { if (!item.Value.buildSettings.ContainsKey("CODE_SIGN_ENTITLEMENTS")) { item.Value.buildSettings.Add("CODE_SIGN_ENTITLEMENTS", "Unity-iPhone/tabtale.entitlements"); } else { item.Value.buildSettings["CODE_SIGN_ENTITLEMENTS"] = "Unity-iPhone/tabtale.entitlements"; } } project.Save(); UnityEngine.Debug.Log("InjectingTeamIdToPbxProjFile end seccssfully"); }
public static void SetDevTeamID(IIgorModule ModuleInst, string ProjectPath, string DevTeamID) { if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(ProjectPath), "XCodeProj doesn't exist at path " + ProjectPath)) { XCProject CurrentProject = new XCProject(ProjectPath); CurrentProject.Backup(); string ProjectGUID = CurrentProject.project.guid; object ProjectSectionObj = CurrentProject.GetObject(ProjectGUID); if (IgorAssert.EnsureTrue(ModuleInst, ProjectSectionObj != null, "Can't find Project Section in XCodeProj.")) { PBXDictionary ProjectSection = (PBXDictionary)ProjectSectionObj; object AttributesSectionObj = ProjectSection["attributes"]; if (IgorAssert.EnsureTrue(ModuleInst, AttributesSectionObj != null, "Can't find Attributes Section in Project Section.")) { object TargetAttributesObj = ((PBXDictionary)AttributesSectionObj)["TargetAttributes"]; if (IgorAssert.EnsureTrue(ModuleInst, TargetAttributesObj != null, "Can't find TargetAttributes Section in Attributes Section.")) { PBXDictionary TargetAttributes = (PBXDictionary)TargetAttributesObj; object TargetsObj = ProjectSection["targets"]; if (IgorAssert.EnsureTrue(ModuleInst, TargetsObj != null, "Can't find Targets Section in Project Section.")) { PBXList TargetsList = ((PBXList)TargetsObj); if (IgorAssert.EnsureTrue(ModuleInst, TargetsList.Count > 0, "No build targets defined in XCodeProj.")) { string PrimaryBuildTargetGUID = (string)(TargetsList[0]); PBXDictionary PrimaryBuildTargetToDevTeam = new PBXDictionary(); PBXDictionary DevTeamIDDictionary = new PBXDictionary(); DevTeamIDDictionary.Add("DevelopmentTeam", DevTeamID); PrimaryBuildTargetToDevTeam.Add(PrimaryBuildTargetGUID, DevTeamIDDictionary); if (TargetAttributes.ContainsKey(PrimaryBuildTargetGUID)) { object ExistingPrimaryBuildTargetObj = TargetAttributes[PrimaryBuildTargetGUID]; if (ExistingPrimaryBuildTargetObj != null) { PBXDictionary ExistingPrimaryBuildTarget = (PBXDictionary)ExistingPrimaryBuildTargetObj; if (!ExistingPrimaryBuildTarget.ContainsKey("DevelopmentTeam")) { ExistingPrimaryBuildTarget.Append(DevTeamIDDictionary); IgorDebug.Log(ModuleInst, "Added Development Team to XCodeProj."); } else { IgorDebug.Log(ModuleInst, "Development Team already set up in XCodeProj."); } } else { IgorDebug.LogError(ModuleInst, "Primary build target already has a key in TargetAttributes, but the value stored is invalid."); } } else { TargetAttributes.Append(PrimaryBuildTargetToDevTeam); IgorDebug.Log(ModuleInst, "Added Development Team to XCodeProj."); } CurrentProject.Save(); } } } } } } }