|
4 | 4 |
|
5 | 5 | namespace UnityEditor.XCodeEditor |
6 | 6 | { |
7 | | - public class PBXFileReference : PBXType |
| 7 | + public class PBXFileReference : PBXObject |
8 | 8 | { |
| 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 | + |
9 | 16 | 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" } |
14 | 24 | }; |
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 | + }; |
37 | 73 |
|
38 | 74 | public PBXFileReference() : base() |
39 | 75 | { |
40 | 76 |
|
41 | 77 | } |
42 | 78 |
|
| 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 | + |
43 | 111 | // class PBXFileReference(PBXType): |
44 | 112 | // def __init__(self, d=None): |
45 | 113 | // PBXType.__init__(self, d) |
@@ -115,4 +183,13 @@ public PBXFileReference() : base() |
115 | 183 | // |
116 | 184 | // return fr |
117 | 185 | } |
| 186 | + |
| 187 | + public enum TreeEnum { |
| 188 | + ABSOLUTE, |
| 189 | + GROUP, |
| 190 | + BUILT_PRODUCTS_DIR, |
| 191 | + DEVELOPER_DIR, |
| 192 | + SDKROOT, |
| 193 | + SOURCE_ROOT |
| 194 | + } |
118 | 195 | } |
0 commit comments