Skip to content

Commit 08d6253

Browse files
committed
applies mod to xcode project from projmods file
1 parent 2d343f2 commit 08d6253

File tree

8 files changed

+312
-79
lines changed

8 files changed

+312
-79
lines changed

PBXBuildFile.cs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ namespace UnityEditor.XCodeEditor
66
{
77
public class PBXBuildFile : PBXObject
88
{
9+
private const string FILE_REF_KEY = "fileRef";
910
private const string SETTINGS_KEY = "settings";
1011
private const string ATTRIBUTES_KEY = "ATTRIBUTES";
1112
private const string WEAK_VALUE = "Weak";
1213
private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
1314

14-
public PBXBuildFile( string fileRef, bool weak = false ) : base()
15+
public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
1516
{
16-
17+
18+
this.Add( FILE_REF_KEY, fileRef.guid );
19+
SetWeakLink( weak );
20+
1721
// def Create(cls, file_ref, weak=False):
1822
// if isinstance(file_ref, PBXFileReference):
1923
// file_ref = file_ref.id
@@ -35,10 +39,10 @@ public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dict
3539

3640
public bool SetWeakLink( bool weak = false )
3741
{
38-
PBXDictionary settings = _data[SETTINGS_KEY] as PBXDictionary;
42+
PBXDictionary settings = null;
3943
PBXList attributes = null;
4044

41-
if( settings == null ) {
45+
if( !_data.ContainsKey( SETTINGS_KEY ) ) {
4246
if( weak ) {
4347
attributes = new PBXList();
4448
attributes.Add( WEAK_VALUE );
@@ -49,15 +53,21 @@ public bool SetWeakLink( bool weak = false )
4953
return true;
5054
}
5155

52-
attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
53-
if( attributes == null ) {
56+
settings = _data[ SETTINGS_KEY ] as PBXDictionary;
57+
if( !settings.ContainsKey( ATTRIBUTES_KEY ) ) {
5458
if( weak ) {
5559
attributes = new PBXList();
60+
attributes.Add( WEAK_VALUE );
61+
settings.Add( ATTRIBUTES_KEY, attributes );
62+
return true;
5663
}
5764
else {
5865
return false;
5966
}
6067
}
68+
else {
69+
attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
70+
}
6171

6272
if( weak ) {
6373
attributes.Add( WEAK_VALUE );
@@ -74,12 +84,22 @@ public bool SetWeakLink( bool weak = false )
7484

7585
public bool AddCompilerFlag( string flag )
7686
{
77-
// if( !this.ContainsKey( SETTINGS_KEY ) )
78-
// this[ SETTINGS_KEY ] = new PBXDictionary();
79-
//
80-
// if( !(PBXDictionary)this[ SETTINGS_KEY ]
87+
if( !_data.ContainsKey( SETTINGS_KEY ) )
88+
_data[ SETTINGS_KEY ] = new PBXDictionary();
8189

82-
return false;
90+
if( !((PBXDictionary)_data[ SETTINGS_KEY ]).ContainsKey( COMPILER_FLAGS_KEY ) ) {
91+
((PBXDictionary)_data[ SETTINGS_KEY ]).Add( COMPILER_FLAGS_KEY, flag );
92+
return true;
93+
}
94+
95+
string[] flags = ((string)((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ]).Split( ' ' );
96+
foreach( string item in flags ) {
97+
if( item.CompareTo( flag ) == 0 )
98+
return false;
99+
}
100+
101+
((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ] = ( string.Join( " ", flags ) + " " + flag );
102+
return true;
83103

84104
// def add_compiler_flag(self, flag):
85105
// k_settings = 'settings'

PBXBuildPhase.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,23 @@ public bool AddBuildFile( PBXBuildFile file )
2222
{
2323
// if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
2424
// return false;
25+
// Debug.Log( "--> buildphase " + (string)_data[ ISA_KEY ] );
26+
2527

2628
if( !ContainsKey( FILES_KEY ) ){
27-
Debug.Log( "key not present" );
29+
// Debug.Log( "key not present" );
2830
this.Add( FILES_KEY, new PBXList() );
2931
}
30-
Debug.Log( "key: " + _data[ FILES_KEY ] );
31-
Debug.Log( "Adding: " + file.guid );
32+
// Debug.Log( "key: " + _data[ FILES_KEY ] );
33+
// Debug.Log( "Adding: " + file.guid );
3234
((PBXList)_data[ FILES_KEY ]).Add( file.guid );
35+
// if( ((PBXList)_data[ FILES_KEY ]).Contains( file.guid ) ) {
36+
// Debug.Log( "AGGIUNTO" );
37+
// }
38+
// else {
39+
// Debug.Log( "MANCA" );
40+
// }
41+
3342
return true;
3443
}
3544

PBXFileReference.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT )
8484
this.GuessFileType();
8585
}
8686

87+
public string name {
88+
get {
89+
if( !ContainsKey( NAME_KEY ) ) {
90+
return null;
91+
}
92+
return (string)_data[NAME_KEY];
93+
}
94+
}
95+
8796
private void GuessFileType()
8897
{
8998
this.Remove( EXPLICIT_FILE_TYPE_KEY );

XCBuildConfiguration.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public PBXDictionary buildSettings {
1919
get {
2020
if( ContainsKey( BUILDSETTINGS_KEY ) )
2121
return (PBXDictionary)_data[BUILDSETTINGS_KEY];
22-
23-
Debug.Log( "strano" );
22+
2423
return null;
2524
}
2625
}
@@ -44,6 +43,7 @@ protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true
4443
if( recursive && !path.EndsWith( "/**" ) )
4544
currentPath += "**";
4645

46+
// Debug.Log( "adding: " + currentPath );
4747
if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( key ) ) {
4848
((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( key, new PBXList() );
4949
}
@@ -53,7 +53,10 @@ protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true
5353
((PBXDictionary)_data[BUILDSETTINGS_KEY])[key] = list;
5454
}
5555

56-
if( ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[key]).Add( "\"" + currentPath + "\"" ) >= 0 ) {
56+
currentPath = "\\\"" + currentPath + "\\\"";
57+
58+
if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[key]).Contains( currentPath ) ) {
59+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[key]).Add( currentPath );
5760
modified = true;
5861
}
5962
}
@@ -99,7 +102,8 @@ public bool AddOtherCFlags( PBXList flags )
99102
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Add( tempString );
100103
}
101104

102-
if( ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Add( flag ) >= 0 ) {
105+
if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Contains( flag ) ) {
106+
((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Add( flag );
103107
modified = true;
104108
}
105109
}

XCMod.cs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.IO;
4+
using Json = MiniJSON;
5+
6+
namespace UnityEditor.XCodeEditor
7+
{
8+
public class XCMod
9+
{
10+
// private string group;
11+
// private ArrayList patches;
12+
// private ArrayList libs;
13+
// private ArrayList frameworks;
14+
// private ArrayList headerpaths;
15+
// private ArrayList files;
16+
// private ArrayList folders;
17+
// private ArrayList excludes;
18+
private Hashtable _datastore;
19+
20+
public string name { get; private set; }
21+
public string path { get; private set; }
22+
23+
public string group {
24+
get {
25+
return (string)_datastore["group"];
26+
}
27+
}
28+
29+
public ArrayList patches {
30+
get {
31+
return (ArrayList)_datastore["patches"];
32+
}
33+
}
34+
35+
public ArrayList libs {
36+
get {
37+
return (ArrayList)_datastore["libs"];
38+
}
39+
}
40+
41+
public ArrayList frameworks {
42+
get {
43+
return (ArrayList)_datastore["frameworks"];
44+
}
45+
}
46+
47+
public ArrayList headerpaths {
48+
get {
49+
return (ArrayList)_datastore["headerpaths"];
50+
}
51+
}
52+
53+
public ArrayList files {
54+
get {
55+
return (ArrayList)_datastore["files"];
56+
}
57+
}
58+
59+
public ArrayList folders {
60+
get {
61+
return (ArrayList)_datastore["folders"];
62+
}
63+
}
64+
65+
public ArrayList excludes {
66+
get {
67+
return (ArrayList)_datastore["excludes"];
68+
}
69+
}
70+
71+
public XCMod( string filename )
72+
{
73+
FileInfo projectFileInfo = new FileInfo( filename );
74+
if( !projectFileInfo.Exists ) {
75+
Debug.LogWarning( "File does not exist." );
76+
}
77+
78+
name = System.IO.Path.GetFileNameWithoutExtension( filename );
79+
path = System.IO.Path.GetDirectoryName( filename );
80+
81+
string contents = projectFileInfo.OpenText().ReadToEnd();
82+
_datastore = (Hashtable)MiniJSON.jsonDecode( contents );
83+
84+
// group = (string)_datastore["group"];
85+
// patches = (ArrayList)_datastore["patches"];
86+
// libs = (ArrayList)_datastore["libs"];
87+
// frameworks = (ArrayList)_datastore["frameworks"];
88+
// headerpaths = (ArrayList)_datastore["headerpaths"];
89+
// files = (ArrayList)_datastore["files"];
90+
// folders = (ArrayList)_datastore["folders"];
91+
// excludes = (ArrayList)_datastore["excludes"];
92+
}
93+
94+
95+
// "group": "GameCenter",
96+
// "patches": [],
97+
// "libs": [],
98+
// "frameworks": ["GameKit.framework"],
99+
// "headerpaths": ["Editor/iOS/GameCenter/**"],
100+
// "files": ["Editor/iOS/GameCenter/GameCenterBinding.m",
101+
// "Editor/iOS/GameCenter/GameCenterController.h",
102+
// "Editor/iOS/GameCenter/GameCenterController.mm",
103+
// "Editor/iOS/GameCenter/GameCenterManager.h",
104+
// "Editor/iOS/GameCenter/GameCenterManager.m"],
105+
// "folders": [],
106+
// "excludes": ["^.*\\.meta$", "^.*\\.mdown^", "^.*\\.pdf$"]
107+
108+
}
109+
}

XCMod.cs.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)