Skip to content

Commit 8d6984f

Browse files
committed
Many edits.
1 parent 7592764 commit 8d6984f

16 files changed

+803
-245
lines changed

PBXBuildFile.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace UnityEditor.XCodeEditor
66
{
7-
public class PBXBuildFile : PBXType
7+
public class PBXBuildFile : PBXObject
88
{
99
const string SETTINGS_KEY = "settings";
1010
const string ATTRIBUTES_KEY = "ATTRIBUTES";
@@ -28,6 +28,10 @@ public PBXBuildFile( string fileRef, bool weak = false ) : base()
2828
// return bf
2929
}
3030

31+
public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
32+
{
33+
Debug.Log( "constructor child" );
34+
}
3135

3236
public bool SetWeakLink( bool weak = false )
3337
{

PBXBuildPhase.cs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44

55
namespace UnityEditor.XCodeEditor
66
{
7-
public class PBXBuildPhase : PBXType
7+
public class PBXBuildPhase : PBXObject
88
{
99
protected const string FILES_KEY = "files";
1010

11+
public PBXBuildPhase()
12+
{
13+
Debug.Log( "base" );
14+
}
15+
16+
public PBXBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
17+
{
18+
Debug.Log( "constructor " + GetType().Name );
19+
}
20+
1121
public bool AddBuildFile( PBXBuildFile file )
1222
{
1323
if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
@@ -16,7 +26,7 @@ public bool AddBuildFile( PBXBuildFile file )
1626
if( !ContainsKey( FILES_KEY ) )
1727
this.Add( FILES_KEY, new PBXList() );
1828

19-
((PBXList)this[ FILES_KEY ]).Add( file.id );
29+
((PBXList)this[ FILES_KEY ]).Add( file.guid );
2030
return true;
2131
}
2232

@@ -43,7 +53,7 @@ public bool HasBuildFile( string id )
4353
return ((PBXList)this[ FILES_KEY ]).Contains( id );
4454
}
4555

46-
// class PBXBuildPhase(PBXType):
56+
// class PBXBuildPhase(PBXObject):
4757
// def add_build_file(self, bf):
4858
// if bf.get('isa') != 'PBXBuildFile':
4959
// return False
@@ -67,34 +77,49 @@ public bool HasBuildFile( string id )
6777
// self['files'] = PBXList()
6878
// return False
6979
//
70-
// if not PBXType.IsGuid(id):
80+
// if not PBXObject.IsGuid(id):
7181
// id = id.id
7282
//
7383
// return id in self['files']
7484
}
7585

7686
public class PBXFrameworksBuildPhase : PBXBuildPhase
7787
{
78-
88+
public PBXFrameworksBuildPhase( string guid, PBXDictionary dictionary ) //: base ( guid, dictionary )
89+
{
90+
Debug.Log( "constructor child" + GetType().Name );
91+
}
7992
}
8093

8194
public class PBXResourcesBuildPhase : PBXBuildPhase
8295
{
83-
96+
public PBXResourcesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
97+
{
98+
Debug.Log( "constructor child" + GetType().Name );
99+
}
84100
}
85101

86102
public class PBXShellScriptBuildPhase : PBXBuildPhase
87103
{
88-
104+
public PBXShellScriptBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
105+
{
106+
Debug.Log( "constructor child" + GetType().Name );
107+
}
89108
}
90109

91110
public class PBXSourcesBuildPhase : PBXBuildPhase
92111
{
93-
112+
public PBXSourcesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
113+
{
114+
Debug.Log( "constructor child" + GetType().Name );
115+
}
94116
}
95117

96118
public class PBXCopyFilesBuildPhase : PBXBuildPhase
97119
{
98-
120+
public PBXCopyFilesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
121+
{
122+
Debug.Log( "constructor child" + GetType().Name );
123+
}
99124
}
100125
}

PBXDictionary.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@ public class PBXDictionary : Dictionary<string, object>
88
{
99

1010
}
11+
12+
public class PBXDictionary<T> : Dictionary<string, T>
13+
{
14+
public PBXDictionary()
15+
{
16+
17+
}
18+
19+
public PBXDictionary( PBXDictionary genericDictionary )
20+
{
21+
foreach( KeyValuePair<string, object> currentItem in genericDictionary ) {
22+
if( ((string)((PBXDictionary)currentItem.Value)[ "isa" ]).CompareTo( typeof(T).Name ) == 0 ) {
23+
T instance = (T)System.Activator.CreateInstance( typeof(T), currentItem.Key, (PBXDictionary)currentItem.Value );
24+
this.Add( currentItem.Key, instance );
25+
}
26+
}
27+
}
28+
}
1129
}

PBXFileReference.cs

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,110 @@
44

55
namespace UnityEditor.XCodeEditor
66
{
7-
public class PBXFileReference : PBXType
7+
public class PBXFileReference : PBXObject
88
{
9+
protected const string PATH_KEY = "path";
10+
protected const string NAME_KEY = "name";
11+
protected const string SOURCETREE_KEY = "sourceTree";
12+
protected const string EXPLICIT_FILE_TYPE_KEY = "explicitFileType";
13+
protected const string LASTKNOWN_FILE_TYPE_KEY = "lastKnownFileType";
14+
protected const string ENCODING_KEY = "fileEncoding";
15+
916
public string buildPhase;
10-
public readonly Dictionary<string, string> types = new Dictionary<string, string> {
11-
{"a", "archive.ar" }
12-
// {".a", {"archive.ar", "PBXFrameworksBuildPhase"}},
13-
// {".app", {"wrapper.application", null }}
17+
public readonly Dictionary<TreeEnum, string> trees = new Dictionary<TreeEnum, string> {
18+
{ TreeEnum.ABSOLUTE, "<absolute>" },
19+
{ TreeEnum.GROUP, "<group>" },
20+
{ TreeEnum.BUILT_PRODUCTS_DIR, "BUILT_PRODUCTS_DIR" },
21+
{ TreeEnum.DEVELOPER_DIR, "DEVELOPER_DIR" },
22+
{ TreeEnum.SDKROOT, "SDKROOT" },
23+
{ TreeEnum.SOURCE_ROOT, "SOURCE_ROOT" }
1424
};
15-
// '.a':('archive.ar', 'PBXFrameworksBuildPhase'),
16-
// '.app': ('wrapper.application', None),
17-
// '.s': ('sourcecode.asm', 'PBXSourcesBuildPhase'),
18-
// '.c': ('sourcecode.c.c', 'PBXSourcesBuildPhase'),
19-
// '.cpp': ('sourcecode.cpp.cpp', 'PBXSourcesBuildPhase'),
20-
// '.framework': ('wrapper.framework','PBXFrameworksBuildPhase'),
21-
// '.h': ('sourcecode.c.h', None),
22-
// '.icns': ('image.icns','PBXResourcesBuildPhase'),
23-
// '.m': ('sourcecode.c.objc', 'PBXSourcesBuildPhase'),
24-
// '.mm': ('sourcecode.cpp.objcpp', 'PBXSourcesBuildPhase'),
25-
// '.nib': ('wrapper.nib', 'PBXResourcesBuildPhase'),
26-
// '.plist': ('text.plist.xml', 'PBXResourcesBuildPhase'),
27-
// '.png': ('image.png', 'PBXResourcesBuildPhase'),
28-
// '.rtf': ('text.rtf', 'PBXResourcesBuildPhase'),
29-
// '.tiff': ('image.tiff', 'PBXResourcesBuildPhase'),
30-
// '.txt': ('text', 'PBXResourcesBuildPhase'),
31-
// '.xcodeproj': ('wrapper.pb-project', None),
32-
// '.xib': ('file.xib', 'PBXResourcesBuildPhase'),
33-
// '.strings': ('text.plist.strings', 'PBXResourcesBuildPhase'),
34-
// '.bundle': ('wrapper.plug-in', 'PBXResourcesBuildPhase'),
35-
// '.dylib': ('compiled.mach-o.dylib', 'PBXFrameworksBuildPhase')
36-
// }
25+
26+
public static readonly Dictionary<string, string> typeNames = new Dictionary<string, string> {
27+
{ ".a", "archive.ar" },
28+
{ ".app", "wrapper.application" },
29+
{ ".s", "sourcecode.asm" },
30+
{ ".c", "sourcecode.c.c" },
31+
{ ".cpp", "sourcecode.cpp.cpp" },
32+
{ ".framework", "wrapper.framework" },
33+
{ ".h", "sourcecode.c.h" },
34+
{ ".icns", "image.icns" },
35+
{ ".m", "sourcecode.c.objc" },
36+
{ ".mm", "sourcecode.cpp.objcpp" },
37+
{ ".nib", "wrapper.nib" },
38+
{ ".plist", "text.plist.xml" },
39+
{ ".png", "image.png" },
40+
{ ".rtf", "text.rtf" },
41+
{ ".tiff", "image.tiff" },
42+
{ ".txt", "text" },
43+
{ ".xcodeproj", "wrapper.pb-project" },
44+
{ ".xib", "file.xib" },
45+
{ ".strings", "text.plist.strings" },
46+
{ ".bundle", "wrapper.plug-in" },
47+
{ ".dylib", "compiled.mach-o.dylib" }
48+
};
49+
50+
public static readonly Dictionary<string, string> typePhases = new Dictionary<string, string> {
51+
{ ".a", "PBXFrameworksBuildPhase" },
52+
{ ".app", null },
53+
{ ".s", "PBXSourcesBuildPhase" },
54+
{ ".c", "PBXSourcesBuildPhase" },
55+
{ ".cpp", "PBXSourcesBuildPhase" },
56+
{ ".framework", "PBXFrameworksBuildPhase" },
57+
{ ".h", null },
58+
{ ".icns", "PBXResourcesBuildPhase" },
59+
{ ".m", "PBXSourcesBuildPhase" },
60+
{ ".mm", "PBXSourcesBuildPhase" },
61+
{ ".nib", "PBXResourcesBuildPhase" },
62+
{ ".plist", "PBXResourcesBuildPhase" },
63+
{ ".png", "PBXResourcesBuildPhase" },
64+
{ ".rtf", "PBXResourcesBuildPhase" },
65+
{ ".tiff", "PBXResourcesBuildPhase" },
66+
{ ".txt", "PBXResourcesBuildPhase" },
67+
{ ".xcodeproj", null },
68+
{ ".xib", "PBXResourcesBuildPhase" },
69+
{ ".strings", "PBXResourcesBuildPhase" },
70+
{ ".bundle", "PBXResourcesBuildPhase" },
71+
{ ".dylib", "PBXFrameworksBuildPhase" }
72+
};
3773

3874
public PBXFileReference() : base()
3975
{
4076

4177
}
4278

79+
public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT ) : this()
80+
{
81+
this.Add( PATH_KEY, filePath );
82+
this.Add( NAME_KEY, System.IO.Path.GetFileName( filePath ) );
83+
this.Add( SOURCETREE_KEY, (string)( System.IO.Path.IsPathRooted( filePath ) ? trees[TreeEnum.ABSOLUTE] : trees[tree] ) );
84+
Debug.Log( "constructorX" );
85+
this.GuessFileType();
86+
}
87+
88+
private void GuessFileType()
89+
{
90+
Debug.Log( "constructor1" );
91+
this.Remove( EXPLICIT_FILE_TYPE_KEY );
92+
Debug.Log( "constructor2" );
93+
this.Remove( LASTKNOWN_FILE_TYPE_KEY );
94+
Debug.Log( "constructor3" );
95+
string extension = System.IO.Path.GetExtension( (string)this[ PATH_KEY ] );
96+
Debug.Log( "constructor4 " + extension );
97+
this.Add( LASTKNOWN_FILE_TYPE_KEY, PBXFileReference.typeNames[ extension ] );
98+
Debug.Log( "constructor5" );
99+
this.buildPhase = PBXFileReference.typePhases[ extension ];
100+
Debug.Log( "constructor6" );
101+
}
102+
103+
private void SetFileType( string fileType )
104+
{
105+
this.Remove( EXPLICIT_FILE_TYPE_KEY );
106+
this.Remove( LASTKNOWN_FILE_TYPE_KEY );
107+
108+
this.Add( EXPLICIT_FILE_TYPE_KEY, fileType );
109+
}
110+
43111
// class PBXFileReference(PBXType):
44112
// def __init__(self, d=None):
45113
// PBXType.__init__(self, d)
@@ -115,4 +183,13 @@ public PBXFileReference() : base()
115183
//
116184
// return fr
117185
}
186+
187+
public enum TreeEnum {
188+
ABSOLUTE,
189+
GROUP,
190+
BUILT_PRODUCTS_DIR,
191+
DEVELOPER_DIR,
192+
SDKROOT,
193+
SOURCE_ROOT
194+
}
118195
}

0 commit comments

Comments
 (0)