PBXFileReference.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace cn.sharesdk.unity3d.sdkporter
  5. {
  6. public class PBXFileReference : PBXObject
  7. {
  8. protected const string PATH_KEY = "path";
  9. protected const string NAME_KEY = "name";
  10. protected const string SOURCETREE_KEY = "sourceTree";
  11. protected const string EXPLICIT_FILE_TYPE_KEY = "explicitFileType";
  12. protected const string LASTKNOWN_FILE_TYPE_KEY = "lastKnownFileType";
  13. protected const string ENCODING_KEY = "fileEncoding";
  14. public string buildPhase;
  15. public readonly Dictionary<TreeEnum, string> trees = new Dictionary<TreeEnum, string> {
  16. { TreeEnum.ABSOLUTE, "<absolute>" },
  17. { TreeEnum.GROUP, "<group>" },
  18. { TreeEnum.BUILT_PRODUCTS_DIR, "BUILT_PRODUCTS_DIR" },
  19. { TreeEnum.DEVELOPER_DIR, "DEVELOPER_DIR" },
  20. { TreeEnum.SDKROOT, "SDKROOT" },
  21. { TreeEnum.SOURCE_ROOT, "SOURCE_ROOT" }
  22. };
  23. public static readonly Dictionary<string, string> typeNames = new Dictionary<string, string> {
  24. { ".a", "archive.ar" },
  25. { ".app", "wrapper.application" },
  26. { ".s", "sourcecode.asm" },
  27. { ".c", "sourcecode.c.c" },
  28. { ".cpp", "sourcecode.cpp.cpp" },
  29. { ".framework", "wrapper.framework" },
  30. { ".h", "sourcecode.c.h" },
  31. { ".icns", "image.icns" },
  32. { ".m", "sourcecode.c.objc" },
  33. { ".mm", "sourcecode.cpp.objcpp" },
  34. { ".nib", "wrapper.nib" },
  35. { ".plist", "text.plist.xml" },
  36. { ".png", "image.png" },
  37. { ".rtf", "text.rtf" },
  38. { ".tiff", "image.tiff" },
  39. { ".txt", "text" },
  40. { ".xcodeproj", "wrapper.pb-project" },
  41. { ".xib", "file.xib" },
  42. { ".strings", "text.plist.strings" },
  43. { ".bundle", "wrapper.plug-in" },
  44. { ".dylib", "compiled.mach-o.dylib" }
  45. };
  46. public static readonly Dictionary<string, string> typePhases = new Dictionary<string, string> {
  47. { ".a", "PBXFrameworksBuildPhase" },
  48. { ".app", null },
  49. { ".s", "PBXSourcesBuildPhase" },
  50. { ".c", "PBXSourcesBuildPhase" },
  51. { ".cpp", "PBXSourcesBuildPhase" },
  52. { ".framework", "PBXFrameworksBuildPhase" },
  53. { ".h", null },
  54. { ".icns", "PBXResourcesBuildPhase" },
  55. { ".m", "PBXSourcesBuildPhase" },
  56. { ".mm", "PBXSourcesBuildPhase" },
  57. { ".nib", "PBXResourcesBuildPhase" },
  58. { ".plist", "PBXResourcesBuildPhase" },
  59. { ".png", "PBXResourcesBuildPhase" },
  60. { ".rtf", "PBXResourcesBuildPhase" },
  61. { ".tiff", "PBXResourcesBuildPhase" },
  62. { ".txt", "PBXResourcesBuildPhase" },
  63. { ".xcodeproj", null },
  64. { ".xib", "PBXResourcesBuildPhase" },
  65. { ".strings", "PBXResourcesBuildPhase" },
  66. { ".bundle", "PBXResourcesBuildPhase" },
  67. { ".dylib", "PBXFrameworksBuildPhase" }
  68. };
  69. public PBXFileReference( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
  70. {
  71. }
  72. public PBXFileReference( string filePath, TreeEnum tree = TreeEnum.SOURCE_ROOT ) : base()
  73. {
  74. this.Add( PATH_KEY, filePath );
  75. this.Add( NAME_KEY, System.IO.Path.GetFileName( filePath ) );
  76. this.Add( SOURCETREE_KEY, (string)( System.IO.Path.IsPathRooted( filePath ) ? trees[TreeEnum.ABSOLUTE] : trees[tree] ) );
  77. this.GuessFileType();
  78. }
  79. public string name {
  80. get {
  81. if( !ContainsKey( NAME_KEY ) ) {
  82. return null;
  83. }
  84. return (string)_data[NAME_KEY];
  85. }
  86. }
  87. private void GuessFileType()
  88. {
  89. this.Remove( EXPLICIT_FILE_TYPE_KEY );
  90. this.Remove( LASTKNOWN_FILE_TYPE_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. this.Add( LASTKNOWN_FILE_TYPE_KEY, PBXFileReference.typeNames[ extension ] );
  97. this.buildPhase = PBXFileReference.typePhases[ extension ];
  98. }
  99. private void SetFileType( string fileType )
  100. {
  101. this.Remove( EXPLICIT_FILE_TYPE_KEY );
  102. this.Remove( LASTKNOWN_FILE_TYPE_KEY );
  103. this.Add( EXPLICIT_FILE_TYPE_KEY, fileType );
  104. }
  105. }
  106. public enum TreeEnum {
  107. ABSOLUTE,
  108. GROUP,
  109. BUILT_PRODUCTS_DIR,
  110. DEVELOPER_DIR,
  111. SDKROOT,
  112. SOURCE_ROOT
  113. }
  114. }