forked from dcariola/XCodeEditor-for-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPBXBuildFile.cs
More file actions
121 lines (100 loc) · 3.19 KB
/
Copy pathPBXBuildFile.cs
File metadata and controls
121 lines (100 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace UnityEditor.XCodeEditor
{
public class PBXBuildFile : PBXObject
{
private const string FILE_REF_KEY = "fileRef";
private const string SETTINGS_KEY = "settings";
private const string ATTRIBUTES_KEY = "ATTRIBUTES";
private const string WEAK_VALUE = "Weak";
private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
public string name;
public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
{
string buildFileGuid = generateBuildFileGuid(fileRef);
this.guid = buildFileGuid;
this.Add( FILE_REF_KEY, fileRef.guid );
SetWeakLink( weak );
name = fileRef.name;
}
public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
{
if(!this.data.ContainsKey(SETTINGS_KEY))
return;
object settingsObj = this.data[SETTINGS_KEY];
if(!(settingsObj is PBXDictionary))
return;
PBXDictionary settingsDict = (PBXDictionary) settingsObj;
settingsDict.internalNewlines = false;
if( !settingsDict.ContainsKey(ATTRIBUTES_KEY) )
return;
object attributesObj = settingsDict[ATTRIBUTES_KEY];
if(!(attributesObj is PBXList))
return;
PBXList attributesCast = (PBXList)attributesObj;
attributesCast.internalNewlines = false;
}
private string generateBuildFileGuid(PBXFileReference fileRef) {
string buildFileGuid = GenerateGuid();
//todo generate with "from ..." section of comment
buildFileGuid += " /* " + fileRef.name + " */";
return buildFileGuid;
}
public string getFileRefGuid() {
if (ContainsKey (FILE_REF_KEY)) {
object obj = GetObjectForKey(FILE_REF_KEY);
if(obj is string) {
return (string)obj;
}
}
return "";
}
public void SetWeakLink( bool weak)
{
PBXDictionary settings = null;
PBXList attributes = null;
if (_data.ContainsKey (SETTINGS_KEY)) {
settings = _data[SETTINGS_KEY] as PBXDictionary;
if (settings.ContainsKey(ATTRIBUTES_KEY)) {
attributes = settings[ATTRIBUTES_KEY] as PBXList;
}
}
if (weak) {
if (settings == null) {
settings = new PBXDictionary();
settings.internalNewlines = false;
_data.Add(SETTINGS_KEY, settings);
}
if (attributes == null) {
attributes = new PBXList();
attributes.internalNewlines = false;
attributes.Add(WEAK_VALUE);
settings.Add(ATTRIBUTES_KEY, attributes);
}
}
else {
if(attributes != null && attributes.Contains(WEAK_VALUE)) {
attributes.Remove(WEAK_VALUE);
}
}
}
public bool AddCompilerFlag( string flag )
{
if( !_data.ContainsKey( SETTINGS_KEY ) )
_data[ SETTINGS_KEY ] = new PBXDictionary();
if( !((PBXDictionary)_data[ SETTINGS_KEY ]).ContainsKey( COMPILER_FLAGS_KEY ) ) {
((PBXDictionary)_data[ SETTINGS_KEY ]).Add( COMPILER_FLAGS_KEY, flag );
return true;
}
string[] flags = ((string)((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ]).Split( ' ' );
foreach( string item in flags ) {
if( item.CompareTo( flag ) == 0 )
return false;
}
((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ] = ( string.Join( " ", flags ) + " " + flag );
return true;
}
}
}