PBXBuildFile.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace cn.sharesdk.unity3d.sdkporter
  5. {
  6. public class PBXBuildFile : PBXObject
  7. {
  8. private const string FILE_REF_KEY = "fileRef";
  9. private const string SETTINGS_KEY = "settings";
  10. private const string ATTRIBUTES_KEY = "ATTRIBUTES";
  11. private const string WEAK_VALUE = "Weak";
  12. private const string COMPILER_FLAGS_KEY = "COMPILER_FLAGS";
  13. public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base()
  14. {
  15. this.Add( FILE_REF_KEY, fileRef.guid );
  16. SetWeakLink( weak );
  17. // def Create(cls, file_ref, weak=False):
  18. // if isinstance(file_ref, PBXFileReference):
  19. // file_ref = file_ref.id
  20. //
  21. // bf = cls()
  22. // bf.id = cls.GenerateId()
  23. // bf['fileRef'] = file_ref
  24. //
  25. // if weak:
  26. // bf.set_weak_link(True)
  27. //
  28. // return bf
  29. }
  30. public PBXBuildFile( string guid, PBXDictionary dictionary ) : base ( guid, dictionary )
  31. {
  32. // Debug.Log( "constructor child" );
  33. }
  34. public bool SetWeakLink( bool weak = false )
  35. {
  36. PBXDictionary settings = null;
  37. PBXList attributes = null;
  38. if( !_data.ContainsKey( SETTINGS_KEY ) ) {
  39. if( weak ) {
  40. attributes = new PBXList();
  41. attributes.Add( WEAK_VALUE );
  42. settings = new PBXDictionary();
  43. settings.Add( ATTRIBUTES_KEY, attributes );
  44. _data[ SETTINGS_KEY ] = settings;
  45. }
  46. return true;
  47. }
  48. settings = _data[ SETTINGS_KEY ] as PBXDictionary;
  49. if( !settings.ContainsKey( ATTRIBUTES_KEY ) ) {
  50. if( weak ) {
  51. attributes = new PBXList();
  52. attributes.Add( WEAK_VALUE );
  53. settings.Add( ATTRIBUTES_KEY, attributes );
  54. return true;
  55. }
  56. else {
  57. return false;
  58. }
  59. }
  60. else {
  61. attributes = settings[ ATTRIBUTES_KEY ] as PBXList;
  62. }
  63. if( weak ) {
  64. attributes.Add( WEAK_VALUE );
  65. }
  66. else {
  67. attributes.Remove( WEAK_VALUE );
  68. }
  69. settings.Add( ATTRIBUTES_KEY, attributes );
  70. this.Add( SETTINGS_KEY, settings );
  71. return true;
  72. }
  73. public bool AddCompilerFlag( string flag )
  74. {
  75. if( !_data.ContainsKey( SETTINGS_KEY ) )
  76. _data[ SETTINGS_KEY ] = new PBXDictionary();
  77. if( !((PBXDictionary)_data[ SETTINGS_KEY ]).ContainsKey( COMPILER_FLAGS_KEY ) ) {
  78. ((PBXDictionary)_data[ SETTINGS_KEY ]).Add( COMPILER_FLAGS_KEY, flag );
  79. return true;
  80. }
  81. string[] flags = ((string)((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ]).Split( ' ' );
  82. foreach( string item in flags ) {
  83. if( item.CompareTo( flag ) == 0 )
  84. return false;
  85. }
  86. ((PBXDictionary)_data[ SETTINGS_KEY ])[ COMPILER_FLAGS_KEY ] = ( string.Join( " ", flags ) + " " + flag );
  87. return true;
  88. // def add_compiler_flag(self, flag):
  89. // k_settings = 'settings'
  90. // k_attributes = 'COMPILER_FLAGS'
  91. //
  92. // if not self.has_key(k_settings):
  93. // self[k_settings] = PBXDict()
  94. //
  95. // if not self[k_settings].has_key(k_attributes):
  96. // self[k_settings][k_attributes] = flag
  97. // return True
  98. //
  99. // flags = self[k_settings][k_attributes].split(' ')
  100. //
  101. // if flag in flags:
  102. // return False
  103. //
  104. // flags.append(flag)
  105. //
  106. // self[k_settings][k_attributes] = ' '.join(flags)
  107. }
  108. }
  109. }