Skip to content

Commit 2d343f2

Browse files
committed
AddFolder working
1 parent 69198b2 commit 2d343f2

12 files changed

+343
-161
lines changed

PBXBuildFile.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace UnityEditor.XCodeEditor
66
{
77
public class PBXBuildFile : PBXObject
88
{
9-
const string SETTINGS_KEY = "settings";
10-
const string ATTRIBUTES_KEY = "ATTRIBUTES";
11-
const string WEAK_VALUE = "Weak";
12-
const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
9+
private const string SETTINGS_KEY = "settings";
10+
private const string ATTRIBUTES_KEY = "ATTRIBUTES";
11+
private const string WEAK_VALUE = "Weak";
12+
private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
1313

1414
public PBXBuildFile( string fileRef, bool weak = false ) : base()
1515
{
@@ -30,12 +30,12 @@ public PBXBuildFile( string fileRef, bool weak = false ) : base()
3030

3131
public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
3232
{
33-
Debug.Log( "constructor child" );
33+
// Debug.Log( "constructor child" );
3434
}
3535

3636
public bool SetWeakLink( bool weak = false )
3737
{
38-
PBXDictionary settings = this[SETTINGS_KEY] as PBXDictionary;
38+
PBXDictionary settings = _data[SETTINGS_KEY] as PBXDictionary;
3939
PBXList attributes = null;
4040

4141
if( settings == null ) {

PBXBuildPhase.cs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@ public class PBXBuildPhase : PBXObject
88
{
99
protected const string FILES_KEY = "files";
1010

11-
public PBXBuildPhase()
11+
public PBXBuildPhase() :base()
1212
{
13-
Debug.Log( "base" );
13+
// Debug.Log( "base" );
1414
}
1515

16-
public PBXBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
16+
public PBXBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
1717
{
18-
Debug.Log( "constructor " + GetType().Name );
18+
// Debug.Log( "constructor " + GetType().Name );
1919
}
2020

2121
public bool AddBuildFile( PBXBuildFile file )
2222
{
23-
if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
24-
return false;
23+
// if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
24+
// return false;
2525

26-
if( !ContainsKey( FILES_KEY ) )
26+
if( !ContainsKey( FILES_KEY ) ){
27+
Debug.Log( "key not present" );
2728
this.Add( FILES_KEY, new PBXList() );
28-
29-
((PBXList)this[ FILES_KEY ]).Add( file.guid );
29+
}
30+
Debug.Log( "key: " + _data[ FILES_KEY ] );
31+
Debug.Log( "Adding: " + file.guid );
32+
((PBXList)_data[ FILES_KEY ]).Add( file.guid );
3033
return true;
3134
}
3235

@@ -37,7 +40,7 @@ public void RemoveBuildFile( string id )
3740
return;
3841
}
3942

40-
((PBXList)this[ FILES_KEY ]).Remove( id );
43+
((PBXList)_data[ FILES_KEY ]).Remove( id );
4144
}
4245

4346
public bool HasBuildFile( string id )
@@ -50,7 +53,7 @@ public bool HasBuildFile( string id )
5053
if( !IsGuid( id ) )
5154
return false;
5255

53-
return ((PBXList)this[ FILES_KEY ]).Contains( id );
56+
return ((PBXList)_data[ FILES_KEY ]).Contains( id );
5457
}
5558

5659
// class PBXBuildPhase(PBXObject):
@@ -85,41 +88,41 @@ public bool HasBuildFile( string id )
8588

8689
public class PBXFrameworksBuildPhase : PBXBuildPhase
8790
{
88-
public PBXFrameworksBuildPhase( string guid, PBXDictionary dictionary ) //: base ( guid, dictionary )
91+
public PBXFrameworksBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
8992
{
90-
Debug.Log( "constructor child" + GetType().Name );
93+
// Debug.Log( "constructor child" + GetType().Name );
9194
}
9295
}
9396

9497
public class PBXResourcesBuildPhase : PBXBuildPhase
9598
{
96-
public PBXResourcesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
99+
public PBXResourcesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
97100
{
98-
Debug.Log( "constructor child" + GetType().Name );
101+
// Debug.Log( "constructor child" + GetType().Name );
99102
}
100103
}
101104

102105
public class PBXShellScriptBuildPhase : PBXBuildPhase
103106
{
104-
public PBXShellScriptBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
107+
public PBXShellScriptBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
105108
{
106-
Debug.Log( "constructor child" + GetType().Name );
109+
// Debug.Log( "constructor child" + GetType().Name );
107110
}
108111
}
109112

110113
public class PBXSourcesBuildPhase : PBXBuildPhase
111114
{
112-
public PBXSourcesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
115+
public PBXSourcesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
113116
{
114-
Debug.Log( "constructor child" + GetType().Name );
117+
// Debug.Log( "constructor child" + GetType().Name );
115118
}
116119
}
117120

118121
public class PBXCopyFilesBuildPhase : PBXBuildPhase
119122
{
120-
public PBXCopyFilesBuildPhase( string guid, PBXDictionary dictionary )// : base ( guid, dictionary )
123+
public PBXCopyFilesBuildPhase( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
121124
{
122-
Debug.Log( "constructor child" + GetType().Name );
125+
// Debug.Log( "constructor child" + GetType().Name );
123126
}
124127
}
125128
}

PBXDictionary.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ namespace UnityEditor.XCodeEditor
77
public class PBXDictionary : Dictionary<string, object>
88
{
99

10+
public void Append( PBXDictionary dictionary )
11+
{
12+
foreach( var item in dictionary) {
13+
this.Add( item.Key, item.Value );
14+
}
15+
}
16+
17+
public void Append<T>( PBXDictionary<T> dictionary ) where T : PBXObject
18+
{
19+
foreach( var item in dictionary) {
20+
this.Add( item.Key, item.Value );
21+
}
22+
}
1023
}
1124

1225
public class PBXDictionary<T> : Dictionary<string, T> where T : PBXObject
@@ -26,9 +39,17 @@ public PBXDictionary( PBXDictionary genericDictionary )
2639
}
2740
}
2841

29-
public void AddObject( T newObject )
42+
public void Add( T newObject )
3043
{
3144
this.Add( newObject.guid, newObject );
3245
}
46+
47+
public void Append( PBXDictionary<T> dictionary )
48+
{
49+
foreach( KeyValuePair<string, T> item in dictionary) {
50+
this.Add( item.Key, (T)item.Value );
51+
}
52+
}
53+
3354
}
3455
}

PBXFileReference.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public class PBXFileReference : PBXObject
7171
{ ".dylib", "PBXFrameworksBuildPhase" }
7272
};
7373

74-
public PBXFileReference() : base()
74+
public PBXFileReference( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
7575
{
7676

7777
}
7878

79-
public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT ) : this()
79+
public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT ) : base()
8080
{
8181
this.Add( PATH_KEY, filePath );
8282
this.Add( NAME_KEY, System.IO.Path.GetFileName( filePath ) );
@@ -88,7 +88,12 @@ private void GuessFileType()
8888
{
8989
this.Remove( EXPLICIT_FILE_TYPE_KEY );
9090
this.Remove( LASTKNOWN_FILE_TYPE_KEY );
91-
string extension = System.IO.Path.GetExtension( (string)this[ PATH_KEY ] );
91+
string extension = System.IO.Path.GetExtension( (string)_data[ PATH_KEY ] );
92+
if( !PBXFileReference.typeNames.ContainsKey( extension ) ){
93+
Debug.LogWarning( "Unknown file extension: " + extension + "\nPlease add extension and Xcode type to PBXFileReference.types" );
94+
return;
95+
}
96+
9297
this.Add( LASTKNOWN_FILE_TYPE_KEY, PBXFileReference.typeNames[ extension ] );
9398
this.buildPhase = PBXFileReference.typePhases[ extension ];
9499
}

PBXGroup.cs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ public class PBXGroup : PBXObject
1111
protected const string PATH_KEY = "path";
1212
protected const string SOURCETREE_KEY = "sourceTree";
1313

14+
#region Constructor
15+
1416
public PBXGroup( string name, string path = null, string tree = "SOURCE_ROOT" ) : base()
15-
{
16-
// this.id = GenerateId();
17+
{
1718
this.Add( NAME_KEY, name );
1819
this.Add( CHILDREN_KEY, new PBXList() );
1920

@@ -31,14 +32,15 @@ public PBXGroup( string guid, PBXDictionary dictionary ) : base( guid, dictionar
3132

3233
}
3334

35+
#endregion
3436
#region Properties
3537

3638
public string name {
3739
get {
3840
if( !ContainsKey( NAME_KEY ) ) {
3941
return null;
4042
}
41-
return (string)this[NAME_KEY];
43+
return (string)_data[NAME_KEY];
4244
}
4345
}
4446

@@ -47,7 +49,7 @@ public PBXList children {
4749
if( !ContainsKey( CHILDREN_KEY ) ) {
4850
this.Add( CHILDREN_KEY, new PBXList() );
4951
}
50-
return (PBXList)this[CHILDREN_KEY];
52+
return (PBXList)_data[CHILDREN_KEY];
5153
}
5254
}
5355

@@ -56,13 +58,13 @@ public string path {
5658
if( !ContainsKey( PATH_KEY ) ) {
5759
return null;
5860
}
59-
return (string)this[PATH_KEY];
61+
return (string)_data[PATH_KEY];
6062
}
6163
}
6264

6365
public string sourceTree {
6466
get {
65-
return (string)this[SOURCETREE_KEY];
67+
return (string)_data[SOURCETREE_KEY];
6668
}
6769
}
6870

@@ -71,29 +73,16 @@ public string sourceTree {
7173

7274
public string AddChild( PBXObject child )
7375
{
74-
if( !( child is PBXDictionary ) )
75-
return "";
76-
// return "";
77-
78-
string isa = (string)child[ ISA_KEY ];
79-
if( string.Compare( isa, "PBXFileReference" ) != 0 || string.Compare( isa, "PBXGroup" ) != 0 )
80-
return null;
81-
82-
// if( !ContainsKey( CHILDREN_KEY ) ) {
83-
// this.Add( CHILDREN_KEY, new PBXList() );
84-
// }
85-
86-
children.Add( child.guid );
87-
return child.guid;
76+
if( child is PBXFileReference || child is PBXGroup ) {
77+
children.Add( child.guid );
78+
return child.guid;
79+
}
80+
81+
return null;
8882
}
8983

9084
public void RemoveChild( string id )
9185
{
92-
// if( !ContainsKey( CHILDREN_KEY ) ) {
93-
// this.Add( CHILDREN_KEY, new PBXList() );
94-
// return;
95-
// }
96-
9786
if( !IsGuid( id ) )
9887
return;
9988

@@ -110,12 +99,12 @@ public bool HasChild( string id )
11099
if( !IsGuid( id ) )
111100
return false;
112101

113-
return ((PBXList)this[ CHILDREN_KEY ]).Contains( id );
102+
return ((PBXList)_data[ CHILDREN_KEY ]).Contains( id );
114103
}
115104

116105
public string GetName()
117106
{
118-
return (string)this[ NAME_KEY ];
107+
return (string)_data[ NAME_KEY ];
119108
}
120109

121110
// class PBXGroup(PBXObject):

0 commit comments

Comments
 (0)