forked from dcariola/XCodeEditor-for-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPBXFileReference.cs
More file actions
127 lines (114 loc) · 4.05 KB
/
PBXFileReference.cs
File metadata and controls
127 lines (114 loc) · 4.05 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
122
123
124
125
126
127
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace UnityEditor.SKZXCodeEditor
{
public class PBXFileReference : PBXObject
{
protected const string PATH_KEY = "path";
protected const string NAME_KEY = "name";
protected const string SOURCETREE_KEY = "sourceTree";
protected const string EXPLICIT_FILE_TYPE_KEY = "explicitFileType";
protected const string LASTKNOWN_FILE_TYPE_KEY = "lastKnownFileType";
protected const string ENCODING_KEY = "fileEncoding";
public string buildPhase;
public readonly Dictionary<TreeEnum, string> trees = new Dictionary<TreeEnum, string> {
{ TreeEnum.ABSOLUTE, "<absolute>" },
{ TreeEnum.GROUP, "<group>" },
{ TreeEnum.BUILT_PRODUCTS_DIR, "BUILT_PRODUCTS_DIR" },
{ TreeEnum.DEVELOPER_DIR, "DEVELOPER_DIR" },
{ TreeEnum.SDKROOT, "SDKROOT" },
{ TreeEnum.SOURCE_ROOT, "SOURCE_ROOT" }
};
public static readonly Dictionary<string, string> typeNames = new Dictionary<string, string> {
{ ".a", "archive.ar" },
{ ".app", "wrapper.application" },
{ ".s", "sourcecode.asm" },
{ ".c", "sourcecode.c.c" },
{ ".cpp", "sourcecode.cpp.cpp" },
{ ".framework", "wrapper.framework" },
{ ".h", "sourcecode.c.h" },
{ ".icns", "image.icns" },
{ ".m", "sourcecode.c.objc" },
{ ".mm", "sourcecode.cpp.objcpp" },
{ ".nib", "wrapper.nib" },
{ ".plist", "text.plist.xml" },
{ ".png", "image.png" },
{ ".rtf", "text.rtf" },
{ ".tiff", "image.tiff" },
{ ".txt", "text" },
{ ".xcodeproj", "wrapper.pb-project" },
{ ".xib", "file.xib" },
{ ".strings", "text.plist.strings" },
{ ".bundle", "wrapper.plug-in" },
{ ".dylib", "compiled.mach-o.dylib" }
};
public static readonly Dictionary<string, string> typePhases = new Dictionary<string, string> {
{ ".a", "PBXFrameworksBuildPhase" },
{ ".app", null },
{ ".s", "PBXSourcesBuildPhase" },
{ ".c", "PBXSourcesBuildPhase" },
{ ".cpp", "PBXSourcesBuildPhase" },
{ ".framework", "PBXFrameworksBuildPhase" },
{ ".h", null },
{ ".icns", "PBXResourcesBuildPhase" },
{ ".m", "PBXSourcesBuildPhase" },
{ ".mm", "PBXSourcesBuildPhase" },
{ ".nib", "PBXResourcesBuildPhase" },
{ ".plist", "PBXResourcesBuildPhase" },
{ ".png", "PBXResourcesBuildPhase" },
{ ".rtf", "PBXResourcesBuildPhase" },
{ ".tiff", "PBXResourcesBuildPhase" },
{ ".txt", "PBXResourcesBuildPhase" },
{ ".xcodeproj", null },
{ ".xib", "PBXResourcesBuildPhase" },
{ ".strings", "PBXResourcesBuildPhase" },
{ ".bundle", "PBXResourcesBuildPhase" },
{ ".dylib", "PBXFrameworksBuildPhase" }
};
public PBXFileReference( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
{
}
public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT ) : base()
{
this.Add( PATH_KEY, filePath );
this.Add( NAME_KEY, System.IO.Path.GetFileName( filePath ) );
this.Add( SOURCETREE_KEY, (string)( System.IO.Path.IsPathRooted( filePath ) ? trees[TreeEnum.ABSOLUTE] : trees[tree] ) );
this.GuessFileType();
}
public string name {
get {
if( !ContainsKey( NAME_KEY ) ) {
return null;
}
return (string)_data[NAME_KEY];
}
}
private void GuessFileType()
{
this.Remove( EXPLICIT_FILE_TYPE_KEY );
this.Remove( LASTKNOWN_FILE_TYPE_KEY );
string extension = System.IO.Path.GetExtension( (string)_data[ PATH_KEY ] );
if( !PBXFileReference.typeNames.ContainsKey( extension ) ){
Debug.LogWarning( "Unknown file extension: " + extension + "\nPlease add extension and Xcode type to PBXFileReference.types" );
return;
}
this.Add( LASTKNOWN_FILE_TYPE_KEY, PBXFileReference.typeNames[ extension ] );
this.buildPhase = PBXFileReference.typePhases[ extension ];
}
private void SetFileType( string fileType )
{
this.Remove( EXPLICIT_FILE_TYPE_KEY );
this.Remove( LASTKNOWN_FILE_TYPE_KEY );
this.Add( EXPLICIT_FILE_TYPE_KEY, fileType );
}
}
public enum TreeEnum {
ABSOLUTE,
GROUP,
BUILT_PRODUCTS_DIR,
DEVELOPER_DIR,
SDKROOT,
SOURCE_ROOT
}
}