├── IOS
├── Editor
│ ├── XUPorter
│ │ ├── .gitignore
│ │ ├── XCConfigurationList.cs
│ │ ├── PBX Editor
│ │ │ ├── PBXVariantGroup.cs
│ │ │ ├── PBXProject.cs
│ │ │ ├── PBXList.cs
│ │ │ ├── PBXSortedDictionary.cs
│ │ │ ├── PBXGroup.cs
│ │ │ ├── PBXBuildPhase.cs
│ │ │ ├── PBXDictionary.cs
│ │ │ ├── PBXBuildFile.cs
│ │ │ ├── PBXObject.cs
│ │ │ ├── PBXFileReference.cs
│ │ │ └── PBXParser.cs
│ │ ├── XCodePostProcess.cs
│ │ ├── XCPlist.cs
│ │ ├── XCMod.cs
│ │ ├── XCBuildConfiguration.cs
│ │ ├── MiniJSON
│ │ │ └── MiniJSON.cs
│ │ ├── XCProject.cs
│ │ └── Plist
│ │ │ └── Plist.cs
│ ├── XUPorter.meta
│ ├── DMIosBuilder.cs.meta
│ ├── GarbageCodeTool.cs.meta
│ ├── DMIosBuilder.cs
│ └── GarbageCodeTool.cs
└── Editor.meta
└── README.md
/IOS/Editor/XUPorter/.gitignore:
--------------------------------------------------------------------------------
1 | *.meta
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # unityiOSBulid
2 | unity C# iOS打包相关
3 | 包括
4 | * XUPorter简单改造代码
5 | * C#代码混淆类`GarbageCodeTool.cs`
6 |
--------------------------------------------------------------------------------
/IOS/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 93b1be8f69ee15a4a838a60360b48efe
3 | folderAsset: yes
4 | timeCreated: 1460111368
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: accb573e018af434f917dbe000527e1e
3 | folderAsset: yes
4 | timeCreated: 1460111368
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/IOS/Editor/DMIosBuilder.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 54a9e07d778c97a4f81fb40c7ea16289
3 | timeCreated: 1460111371
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/IOS/Editor/GarbageCodeTool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 97be3ffd20afe4f0fb4bfc46b1fe8092
3 | timeCreated: 1547100252
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/XCConfigurationList.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace UnityEditor.XCodeEditor
9 | {
10 | public class XCConfigurationList : PBXObject
11 | {
12 | // XCBuildConfigurationList buildConfigurations;
13 | // bool defaultConfigurationIsVisible = false;
14 | // string defaultConfigurationName;
15 |
16 | public XCConfigurationList( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
17 | }
18 | }
19 | }
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXVariantGroup.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace UnityEditor.XCodeEditor
9 | {
10 | public class PBXVariantGroup : PBXGroup
11 | {
12 | #region Constructor
13 |
14 | public PBXVariantGroup( string name, string path = null, string tree = "SOURCE_ROOT" )
15 | : base(name, path, tree)
16 | {
17 | }
18 |
19 | public PBXVariantGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
20 | {
21 | }
22 |
23 | #endregion
24 | }
25 | }
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXProject.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace UnityEditor.XCodeEditor
9 | {
10 | public class PBXProject : PBXObject
11 | {
12 | protected string MAINGROUP_KEY = "mainGroup";
13 | protected string KNOWN_REGIONS_KEY = "knownRegions";
14 |
15 | protected bool _clearedLoc = false;
16 |
17 | public PBXProject() : base() {
18 | }
19 |
20 | public PBXProject( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
21 | }
22 |
23 | public string mainGroupID {
24 | get {
25 | return (string)_data[ MAINGROUP_KEY ];
26 | }
27 | }
28 |
29 | public PBXList knownRegions {
30 | get {
31 | return (PBXList)_data[ KNOWN_REGIONS_KEY ];
32 | }
33 | }
34 |
35 | public void AddRegion(string region) {
36 | if (!_clearedLoc)
37 | {
38 | // Only include localizations we explicitly specify
39 | knownRegions.Clear();
40 | _clearedLoc = true;
41 | }
42 |
43 | knownRegions.Add(region);
44 | }
45 | }
46 | }
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXList.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_EDITOR && UNITY_IPHONE
2 |
3 | using UnityEngine;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | namespace UnityEditor.XCodeEditor
8 | {
9 | public class PBXList : ArrayList
10 | {
11 | public PBXList()
12 | {
13 |
14 | }
15 |
16 | public PBXList( object firstValue )
17 | {
18 | this.Add( firstValue );
19 | }
20 |
21 | ///
22 | /// This allows us to use the form:
23 | /// "if (x)" or "if (!x)"
24 | ///
25 | public static implicit operator bool( PBXList x ) {
26 | //if null or empty, treat us as false/null
27 | return (x == null) ? false : (x.Count == 0);
28 | }
29 |
30 | ///
31 | /// I find this handy. return our fields as comma-separated values
32 | ///
33 | public string ToCSV() {
34 | // TODO use a char sep argument to allow specifying separator
35 | string ret = string.Empty;
36 | foreach (string item in this) {
37 | ret += "\"";
38 | ret += item;
39 | ret += "\", ";
40 | }
41 | return ret;
42 | }
43 |
44 | ///
45 | /// Concatenate and format so appears as "{,,,}"
46 | ///
47 | public override string ToString() {
48 | return "{" + this.ToCSV() + "} ";
49 | }
50 | }
51 | }
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXSortedDictionary.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace UnityEditor.XCodeEditor
9 | {
10 | public class PBXSortedDictionary : SortedDictionary
11 | {
12 |
13 | public void Append( PBXDictionary dictionary )
14 | {
15 | foreach( var item in dictionary) {
16 | this.Add( item.Key, item.Value );
17 | }
18 | }
19 |
20 | public void Append( PBXDictionary dictionary ) where T : PBXObject
21 | {
22 | foreach( var item in dictionary) {
23 | this.Add( item.Key, item.Value );
24 | }
25 | }
26 | }
27 |
28 | public class PBXSortedDictionary : SortedDictionary where T : PBXObject
29 | {
30 | public PBXSortedDictionary()
31 | {
32 |
33 | }
34 |
35 | public PBXSortedDictionary( PBXDictionary genericDictionary )
36 | {
37 | foreach( KeyValuePair currentItem in genericDictionary ) {
38 | if( ((string)((PBXDictionary)currentItem.Value)[ "isa" ]).CompareTo( typeof(T).Name ) == 0 ) {
39 | T instance = (T)System.Activator.CreateInstance( typeof(T), currentItem.Key, (PBXDictionary)currentItem.Value );
40 | this.Add( currentItem.Key, instance );
41 | }
42 | }
43 | }
44 |
45 | public void Add( T newObject )
46 | {
47 | this.Add( newObject.guid, newObject );
48 | }
49 |
50 | public void Append( PBXDictionary dictionary )
51 | {
52 | foreach( KeyValuePair item in dictionary) {
53 | this.Add( item.Key, (T)item.Value );
54 | }
55 | }
56 |
57 | }
58 | }
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/XCodePostProcess.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using UnityEditor;
6 | using UnityEditor.Callbacks;
7 | using UnityEditor.XCodeEditor;
8 | using System.IO;
9 | using System.Collections;
10 | using System.Collections.Generic;
11 |
12 |
13 | public static class XCodePostProcess
14 | {
15 | private static void ParseFrameWork( string strPathVal, List< string > listVal )
16 | {
17 | string[] dirs = System.IO.Directory.GetDirectories( strPathVal );
18 |
19 | for( int lCnt = 0; lCnt < dirs.Length; ++lCnt )
20 | {
21 | if( dirs[lCnt].EndsWith( ".framework" ) )
22 | {
23 | if( ! listVal.Contains( dirs[lCnt] ) )
24 | {
25 | listVal.Add( dirs[lCnt] );
26 | }
27 | }
28 | else
29 | {
30 | ParseFrameWork( dirs[lCnt], listVal );
31 | }
32 |
33 | }
34 | }
35 |
36 | public static string s_projModePath = null;
37 |
38 |
39 | [PostProcessBuild(100)]
40 | public static void OnPostProcessBuild( BuildTarget target, string pathToBuiltProject )
41 | {
42 | if( string.IsNullOrEmpty( s_projModePath ) )
43 | {
44 | return;
45 | }
46 |
47 | Debug.Log( "Export Path => " + pathToBuiltProject );
48 |
49 | if ( target != BuildTarget.iOS )
50 | {
51 | Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
52 | return;
53 | }
54 |
55 | // Create a new project object from build target
56 | XCProject project = new XCProject( pathToBuiltProject );
57 |
58 | List< string > ListFrameworks = new List< string >();
59 |
60 | XCMod mod = new XCMod( s_projModePath );
61 |
62 | foreach( string folderPath in mod.folders )
63 | {
64 | ParseFrameWork( folderPath, ListFrameworks );
65 | }
66 |
67 | for( int lCnt = 0; lCnt < ListFrameworks.Count; ++lCnt )
68 | {
69 | mod.files.Add( ListFrameworks[lCnt] );
70 | }
71 |
72 | project.ApplyMod( mod );
73 |
74 | // project.overwriteBuildSetting("CODE_SIGN_IDENTITY[sdk=iphoneos*]", "iPhone Distribution", "Release");
75 |
76 | project.Save();
77 |
78 | s_projModePath = null;
79 | }
80 |
81 | public static void Log(string message)
82 | {
83 | UnityEngine.Debug.Log("PostProcess: "+message);
84 | }
85 |
86 | }
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXGroup.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_EDITOR && UNITY_IPHONE
2 |
3 | using UnityEngine;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | namespace UnityEditor.XCodeEditor
8 | {
9 | public class PBXGroup : PBXObject
10 | {
11 | protected const string NAME_KEY = "name";
12 | protected const string CHILDREN_KEY = "children";
13 | protected const string PATH_KEY = "path";
14 | protected const string SOURCETREE_KEY = "sourceTree";
15 |
16 | #region Constructor
17 |
18 | public PBXGroup( string name, string path = null, string tree = "SOURCE_ROOT" ) : base()
19 | {
20 | this.Add( CHILDREN_KEY, new PBXList() );
21 | this.Add( NAME_KEY, name );
22 |
23 | if( path != null ) {
24 | this.Add( PATH_KEY, path );
25 | this.Add( SOURCETREE_KEY, tree );
26 | }
27 | else {
28 | this.Add( SOURCETREE_KEY, "" );
29 | }
30 | }
31 |
32 | public PBXGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
33 | {
34 |
35 | }
36 |
37 | #endregion
38 | #region Properties
39 |
40 | public PBXList children {
41 | get {
42 | if( !ContainsKey( CHILDREN_KEY ) ) {
43 | this.Add( CHILDREN_KEY, new PBXList() );
44 | }
45 | return (PBXList)_data[CHILDREN_KEY];
46 | }
47 | }
48 |
49 | public string name {
50 | get {
51 | if( !ContainsKey( NAME_KEY ) ) {
52 | return null;
53 | }
54 | return (string)_data[NAME_KEY];
55 | }
56 | }
57 |
58 | public string path {
59 | get {
60 | if( !ContainsKey( PATH_KEY ) ) {
61 | return null;
62 | }
63 | return (string)_data[PATH_KEY];
64 | }
65 | }
66 |
67 | public string sourceTree {
68 | get {
69 | return (string)_data[SOURCETREE_KEY];
70 | }
71 | }
72 |
73 | #endregion
74 |
75 |
76 | public string AddChild( PBXObject child )
77 | {
78 | if( child is PBXFileReference || child is PBXGroup ) {
79 | children.Add( child.guid );
80 | return child.guid;
81 | }
82 |
83 | return null;
84 | }
85 |
86 | public void RemoveChild( string id )
87 | {
88 | if( !IsGuid( id ) )
89 | return;
90 |
91 | children.Remove( id );
92 | }
93 |
94 | public bool HasChild( string id )
95 | {
96 | if( !ContainsKey( CHILDREN_KEY ) ) {
97 | this.Add( CHILDREN_KEY, new PBXList() );
98 | return false;
99 | }
100 |
101 | if( !IsGuid( id ) )
102 | return false;
103 |
104 | return ((PBXList)_data[ CHILDREN_KEY ]).Contains( id );
105 | }
106 |
107 | public string GetName()
108 | {
109 | return (string)_data[ NAME_KEY ];
110 | }
111 | }
112 | }
113 |
114 | #endif
115 |
116 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXBuildPhase.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_EDITOR && UNITY_IPHONE
2 |
3 | using UnityEngine;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | namespace UnityEditor.XCodeEditor
8 | {
9 | public class PBXBuildPhase : PBXObject
10 | {
11 | protected const string FILES_KEY = "files";
12 |
13 | public PBXBuildPhase() :base()
14 | {
15 | }
16 |
17 | public PBXBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
18 | {
19 | }
20 |
21 | public bool AddBuildFile( PBXBuildFile file )
22 | {
23 | if( !ContainsKey( FILES_KEY ) ){
24 | this.Add( FILES_KEY, new PBXList() );
25 | }
26 | ((PBXList)_data[ FILES_KEY ]).Add( file.guid );
27 | return true;
28 | }
29 |
30 | public void RemoveBuildFile( string id )
31 | {
32 | if( !ContainsKey( FILES_KEY ) ) {
33 | this.Add( FILES_KEY, new PBXList() );
34 | return;
35 | }
36 |
37 | ((PBXList)_data[ FILES_KEY ]).Remove( id );
38 | }
39 |
40 | public bool HasBuildFile( string id )
41 | {
42 | if( !ContainsKey( FILES_KEY ) ) {
43 | this.Add( FILES_KEY, new PBXList() );
44 | return false;
45 | }
46 |
47 | if( !IsGuid( id ) )
48 | return false;
49 |
50 | return ((PBXList)_data[ FILES_KEY ]).Contains( id );
51 | }
52 |
53 | public PBXList files {
54 | get {
55 | if( !ContainsKey( FILES_KEY ) ) {
56 | this.Add( FILES_KEY, new PBXList() );
57 | }
58 | return (PBXList)_data[ FILES_KEY ];
59 | }
60 | }
61 | }
62 |
63 | public class PBXFrameworksBuildPhase : PBXBuildPhase
64 | {
65 | public PBXFrameworksBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
66 | {
67 | }
68 | }
69 |
70 | public class PBXResourcesBuildPhase : PBXBuildPhase
71 | {
72 | public PBXResourcesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
73 | {
74 | }
75 | }
76 |
77 | public class PBXShellScriptBuildPhase : PBXBuildPhase
78 | {
79 | public PBXShellScriptBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
80 | {
81 | }
82 | }
83 |
84 | public class PBXSourcesBuildPhase : PBXBuildPhase
85 | {
86 | public PBXSourcesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
87 | {
88 | }
89 | }
90 |
91 | public class PBXCopyFilesBuildPhase : PBXBuildPhase
92 | {
93 | //Embed Frameworks PBXCopyFilesBuildPhase constructor
94 | //to make sure "isa" = "PBXCopyFilesBuildPhase"
95 | public PBXCopyFilesBuildPhase( int buildActionMask ) :base()
96 | {
97 | this.Add("buildActionMask", buildActionMask);
98 | this.Add("dstPath", "");
99 | this.Add("dstSubfolderSpec", 10);
100 | this.Add("name", "Embed Frameworks");
101 | this.Add("runOnlyForDeploymentPostprocessing", 0);
102 | }
103 |
104 | public PBXCopyFilesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
105 | {
106 | }
107 | }
108 | }
109 |
110 | #endif
111 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXDictionary.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_EDITOR && UNITY_IPHONE
2 |
3 | using UnityEngine;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | namespace UnityEditor.XCodeEditor
8 | {
9 | public class PBXDictionary : Dictionary
10 | {
11 |
12 | public void Append( PBXDictionary dictionary )
13 | {
14 | foreach( var item in dictionary) {
15 | this.Add( item.Key, item.Value );
16 | }
17 | }
18 |
19 | public void Append( PBXDictionary dictionary ) where T : PBXObject
20 | {
21 | foreach( var item in dictionary) {
22 | this.Add( item.Key, item.Value );
23 | }
24 | }
25 |
26 | public void Append( PBXSortedDictionary dictionary )
27 | {
28 | foreach( var item in dictionary) {
29 | this.Add( item.Key, item.Value );
30 | }
31 | }
32 |
33 | public void Append( PBXSortedDictionary dictionary ) where T : PBXObject
34 | {
35 | foreach( var item in dictionary) {
36 | this.Add( item.Key, item.Value );
37 | }
38 | }
39 |
40 | ///
41 | /// This allows us to use the form:
42 | /// "if (x)" or "if (!x)"
43 | ///
44 | public static implicit operator bool( PBXDictionary x ) {
45 | //if null or empty, treat us as false/null
46 | return (x == null) ? false : (x.Count == 0);
47 | }
48 |
49 | ///
50 | /// I find this handy. return our fields as comma-separated values
51 | ///
52 | public string ToCSV() {
53 | // TODO use a char sep argument to allow specifying separator
54 | string ret = string.Empty;
55 | foreach (KeyValuePair item in this) {
56 | ret += "<";
57 | ret += item.Key;
58 | ret += ", ";
59 | ret += item.Value;
60 | ret += ">, ";
61 | }
62 | return ret;
63 | }
64 |
65 | ///
66 | /// Concatenate and format so appears as "{,,,}"
67 | ///
68 | public override string ToString() {
69 | return "{" + this.ToCSV() + "}";
70 | }
71 |
72 | }
73 |
74 | public class PBXDictionary : Dictionary where T : PBXObject
75 | {
76 | public PBXDictionary()
77 | {
78 |
79 | }
80 |
81 | public PBXDictionary( PBXDictionary genericDictionary )
82 | {
83 | foreach( KeyValuePair currentItem in genericDictionary ) {
84 | if( ((string)((PBXDictionary)currentItem.Value)[ "isa" ]).CompareTo( typeof(T).Name ) == 0 ) {
85 | T instance = (T)System.Activator.CreateInstance( typeof(T), currentItem.Key, (PBXDictionary)currentItem.Value );
86 | this.Add( currentItem.Key, instance );
87 | }
88 | }
89 | }
90 |
91 | public PBXDictionary( PBXSortedDictionary genericDictionary )
92 | {
93 | foreach( KeyValuePair currentItem in genericDictionary ) {
94 | if( ((string)((PBXDictionary)currentItem.Value)[ "isa" ]).CompareTo( typeof(T).Name ) == 0 ) {
95 | T instance = (T)System.Activator.CreateInstance( typeof(T), currentItem.Key, (PBXDictionary)currentItem.Value );
96 | this.Add( currentItem.Key, instance );
97 | }
98 | }
99 | }
100 |
101 | public void Add( T newObject )
102 | {
103 | this.Add( newObject.guid, newObject );
104 | }
105 |
106 | public void Append( PBXDictionary dictionary )
107 | {
108 | foreach( KeyValuePair item in dictionary) {
109 | this.Add( item.Key, (T)item.Value );
110 | }
111 | }
112 |
113 | }
114 | }
115 |
116 | #endif
117 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXBuildFile.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_EDITOR && UNITY_IPHONE
2 |
3 | using UnityEngine;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | namespace UnityEditor.XCodeEditor
8 | {
9 | public class PBXBuildFile : PBXObject
10 | {
11 | private const string FILE_REF_KEY = "fileRef";
12 | private const string SETTINGS_KEY = "settings";
13 | private const string ATTRIBUTES_KEY = "ATTRIBUTES";
14 | private const string WEAK_VALUE = "Weak";
15 | private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
16 |
17 | public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
18 | {
19 | this.Add( FILE_REF_KEY, fileRef.guid );
20 | SetWeakLink( weak );
21 |
22 | if (!string.IsNullOrEmpty(fileRef.compilerFlags))
23 | {
24 | foreach (var flag in fileRef.compilerFlags.Split(','))
25 | AddCompilerFlag(flag);
26 | }
27 | }
28 |
29 | public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
30 | {
31 | }
32 |
33 | public string fileRef
34 | {
35 | get {
36 | return (string)_data[ FILE_REF_KEY ];
37 | }
38 | }
39 |
40 | public bool SetWeakLink( bool weak = false )
41 | {
42 | PBXDictionary settings = null;
43 | PBXList attributes = null;
44 |
45 | if( !_data.ContainsKey( SETTINGS_KEY ) ) {
46 | if( weak ) {
47 | attributes = new PBXList();
48 | attributes.Add( WEAK_VALUE );
49 |
50 | settings = new PBXDictionary();
51 | settings.Add( ATTRIBUTES_KEY, attributes );
52 |
53 | _data.Add( SETTINGS_KEY, settings );
54 | }
55 | return true;
56 | }
57 |
58 | settings = _data[ SETTINGS_KEY ] as PBXDictionary;
59 | if( !settings.ContainsKey( ATTRIBUTES_KEY ) ) {
60 | if( weak ) {
61 | attributes = new PBXList();
62 | attributes.Add( WEAK_VALUE );
63 | settings.Add( ATTRIBUTES_KEY, attributes );
64 | return true;
65 | }
66 | else {
67 | return false;
68 | }
69 | }
70 | else {
71 | attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
72 | }
73 |
74 | if( weak ) {
75 | attributes.Add( WEAK_VALUE );
76 | }
77 | else {
78 | attributes.Remove( WEAK_VALUE );
79 | }
80 |
81 | settings.Add( ATTRIBUTES_KEY, attributes );
82 | this.Add( SETTINGS_KEY, settings );
83 |
84 | return true;
85 | }
86 |
87 | //CodeSignOnCopy
88 | public bool AddCodeSignOnCopy()
89 | {
90 | if( !_data.ContainsKey( SETTINGS_KEY ) )
91 | _data[ SETTINGS_KEY ] = new PBXDictionary();
92 |
93 | var settings = _data[ SETTINGS_KEY ] as PBXDictionary;
94 | if( !settings.ContainsKey( ATTRIBUTES_KEY ) ) {
95 | var attributes = new PBXList();
96 | attributes.Add( "CodeSignOnCopy" );
97 | attributes.Add( "RemoveHeadersOnCopy" );
98 | settings.Add( ATTRIBUTES_KEY, attributes );
99 | }
100 | else {
101 | var attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
102 | attributes.Add( "CodeSignOnCopy" );
103 | attributes.Add( "RemoveHeadersOnCopy" );
104 | }
105 | return true;
106 | }
107 |
108 |
109 | public bool AddCompilerFlag( string flag )
110 | {
111 | if( !_data.ContainsKey( SETTINGS_KEY ) )
112 | _data[ SETTINGS_KEY ] = new PBXDictionary();
113 |
114 | if( !((PBXDictionary)_data[ SETTINGS_KEY ]).ContainsKey( COMPILER_FLAGS_KEY ) ) {
115 | ((PBXDictionary)_data[ SETTINGS_KEY ]).Add( COMPILER_FLAGS_KEY, flag );
116 | return true;
117 | }
118 |
119 | string[] flags = ((string)((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ]).Split( ' ' );
120 | foreach( string item in flags ) {
121 | if( item.CompareTo( flag ) == 0 )
122 | return false;
123 | }
124 |
125 | ((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ] = ( string.Join( " ", flags ) + " " + flag );
126 | return true;
127 | }
128 |
129 | }
130 | }
131 |
132 | #endif
133 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/PBX Editor/PBXObject.cs:
--------------------------------------------------------------------------------
1 |
2 | #if UNITY_EDITOR && UNITY_IPHONE
3 |
4 | using UnityEngine;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace UnityEditor.XCodeEditor
9 | {
10 | public class PBXObject
11 | {
12 | protected const string ISA_KEY = "isa";
13 |
14 | protected string _guid;
15 | protected PBXDictionary _data;
16 |
17 | #region Properties
18 |
19 | public string guid {
20 | get {
21 | if( string.IsNullOrEmpty( _guid ) )
22 | _guid = GenerateGuid();
23 |
24 | return _guid;
25 | }
26 | }
27 |
28 | public PBXDictionary data {
29 | get {
30 | if( _data == null )
31 | _data = new PBXDictionary();
32 |
33 | return _data;
34 | }
35 | }
36 |
37 |
38 | #endregion
39 | #region Constructors
40 |
41 | public PBXObject()
42 | {
43 | _data = new PBXDictionary();
44 | _data[ ISA_KEY ] = this.GetType().Name;
45 | _guid = GenerateGuid();
46 | }
47 |
48 | public PBXObject( string guid ) : this()
49 | {
50 | if( IsGuid( guid ) )
51 | _guid = guid;
52 | }
53 |
54 | public PBXObject( string guid, PBXDictionary dictionary ) : this( guid )
55 | {
56 | if( !dictionary.ContainsKey( ISA_KEY ) || ((string)dictionary[ ISA_KEY ]).CompareTo( this.GetType().Name ) != 0 )
57 | Debug.LogError( "PBXDictionary is not a valid ISA object" );
58 |
59 | foreach( KeyValuePair item in dictionary ) {
60 | _data[ item.Key ] = item.Value;
61 | }
62 | }
63 |
64 | #endregion
65 | #region Static methods
66 |
67 | public static bool IsGuid( string aString )
68 | {
69 | // Note: Unity3d generates mixed-case GUIDs, Xcode use uppercase GUIDs only.
70 | return System.Text.RegularExpressions.Regex.IsMatch( aString, @"^[A-Fa-f0-9]{24}$" );
71 | }
72 |
73 | public static string GenerateGuid()
74 | {
75 | return System.Guid.NewGuid().ToString("N").Substring( 8 ).ToUpper();
76 | }
77 |
78 |
79 | #endregion
80 | #region Data manipulation
81 |
82 | public void Add( string key, object obj )
83 | {
84 | _data.Add( key, obj );
85 | }
86 |
87 | public bool Remove( string key )
88 | {
89 | return _data.Remove( key );
90 | }
91 |
92 | public bool ContainsKey( string key )
93 | {
94 | return _data.ContainsKey( key );
95 | }
96 |
97 | #endregion
98 | #region syntactic sugar
99 | ///
100 | /// This allows us to use the form:
101 | /// "if (x)" or "if (!x)"
102 | ///
103 | public static implicit operator bool( PBXObject x ) {
104 | //if null or no data, treat us as false/null
105 | return (x == null) ? false : (x.data.Count == 0);
106 | }
107 |
108 | ///
109 | /// I find this handy. return our fields as comma-separated values
110 | ///
111 | public string ToCSV() {
112 | return "\"" + data + "\", ";
113 | }
114 |
115 | ///
116 | /// Concatenate and format so appears as "{,,,}"
117 | ///
118 | public override string ToString() {
119 | return "{" + this.ToCSV() + "} ";
120 | }
121 | #endregion
122 | }
123 |
124 | public class PBXNativeTarget : PBXObject
125 | {
126 | public PBXNativeTarget() : base() {
127 | }
128 |
129 | public PBXNativeTarget( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
130 | }
131 | }
132 |
133 | public class PBXContainerItemProxy : PBXObject
134 | {
135 | public PBXContainerItemProxy() : base() {
136 | }
137 |
138 | public PBXContainerItemProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
139 | }
140 | }
141 |
142 | public class PBXReferenceProxy : PBXObject
143 | {
144 | public PBXReferenceProxy() : base() {
145 | }
146 |
147 | public PBXReferenceProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
148 | }
149 | }
150 | }
151 |
152 | #endif
153 |
--------------------------------------------------------------------------------
/IOS/Editor/XUPorter/XCPlist.cs:
--------------------------------------------------------------------------------
1 |
2 |
3 | #if UNITY_EDITOR && UNITY_IPHONE
4 |
5 | using UnityEngine;
6 | using System.Collections;
7 | using System.Collections.Generic;
8 | using System.IO;
9 |
10 | namespace UnityEditor.XCodeEditor
11 | {
12 | public class XCPlist
13 | {
14 | string plistPath;
15 | bool plistModified;
16 |
17 | // URLTypes constant --- plist
18 | const string BundleUrlTypes = "CFBundleURLTypes";
19 | const string BundleTypeRole = "CFBundleTypeRole";
20 | const string BundleUrlName = "CFBundleURLName";
21 | const string BundleUrlSchemes = "CFBundleURLSchemes";
22 |
23 | // URLTypes constant --- projmods
24 | const string PlistUrlType = "urltype";
25 | const string PlistRole = "role";
26 | const string PlistEditor = "Editor";
27 | const string PlistName = "name";
28 | const string PlistSchemes = "schemes";
29 |
30 | public XCPlist(string plistPath)
31 | {
32 | this.plistPath = plistPath;
33 | }
34 |
35 | public void Process(Hashtable plist)
36 | {
37 | if( null == plist )
38 | {
39 | return;
40 | }
41 |
42 | Dictionary dict = (Dictionary)PlistCS.Plist.readPlist(plistPath);
43 | foreach( DictionaryEntry entry in plist)
44 | {
45 | this.AddPlistItems((string)entry.Key, entry.Value, dict);
46 | }
47 | if (plistModified)
48 | {
49 | PlistCS.Plist.writeXml(dict, plistPath);
50 | }
51 | }
52 |
53 | // http://stackoverflow.com/questions/20618809/hashtable-to-dictionary
54 | public static Dictionary HashtableToDictionary (Hashtable table)
55 | {
56 | Dictionary dict = new Dictionary();
57 | foreach(DictionaryEntry kvp in table)
58 | dict.Add((K)kvp.Key, (V)kvp.Value);
59 | return dict;
60 | }
61 |
62 | public void AddPlistItems(string key, object value, Dictionary dict)
63 | {
64 | Debug.Log ("AddPlistItems: key=" + key);
65 |
66 | if (key.CompareTo(PlistUrlType) == 0)
67 | {
68 | processUrlTypes((ArrayList)value, dict);
69 | }
70 | else
71 | {
72 | dict[key] = HashtableToDictionary((Hashtable)value);
73 | plistModified = true;
74 | }
75 | }
76 |
77 | private void processUrlTypes(ArrayList urltypes, Dictionary dict)
78 | {
79 | List