bmk_zap.bmx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Strict
  2. Import "bmk_modutil.bmx"
  3. Import "bmk_bank.bmx"
  4. Import "bmk_modinfo.bmx"
  5. Function Zap( path$,stream:TStream )
  6. If Not path Return False
  7. Local name$=StripDir( path )
  8. Local skip=False
  9. If name[..1]="."
  10. skip=True
  11. Else If name.ToLower().EndsWith( ".bak" )
  12. skip=True
  13. EndIf
  14. If skip
  15. stream.WriteLine ""
  16. Return True
  17. EndIf
  18. Local Mode=FileMode( path )
  19. Select FileType(path)
  20. Case FILETYPE_NONE
  21. Print "Error zapping file "+path
  22. Return
  23. Case FILETYPE_FILE
  24. Local size=FileSize(path)
  25. stream.WriteLine name
  26. stream.WriteLine Mode
  27. stream.WriteLine size
  28. Local from_stream:TStream=ReadStream(path)
  29. CopyBytes from_stream,stream,size
  30. from_stream.Close
  31. Case FILETYPE_DIR
  32. Local dir$[]=LoadDir( path )
  33. Local size=Len( dir )
  34. stream.WriteLine name
  35. stream.WriteLine -Mode
  36. stream.WriteLine size
  37. For Local t$=EachIn dir
  38. If Not Zap( path+"/"+t,stream ) Return
  39. Next
  40. End Select
  41. Return True
  42. End Function
  43. Function Unzap( dir$,stream:TStream )
  44. Local name$=stream.ReadLine()
  45. If Not name Return True
  46. Local Mode=Int( stream.ReadLine() )
  47. Local size=Int( stream.ReadLine() )
  48. Local path$=dir+"/"+name
  49. If Mode<0
  50. Mode=-Mode
  51. CreateDir path
  52. For Local k=0 Until size
  53. If Not Unzap( path,stream ) Return
  54. Next
  55. Else
  56. DeleteFile path
  57. Local to_stream:TStream=WriteStream(path)
  58. CopyBytes stream,to_stream,size
  59. to_stream.Close
  60. EndIf
  61. SetFileMode path,Mode
  62. Return True
  63. End Function
  64. Function ZapMod( name$,stream:TStream )
  65. Local path$=ModuleInterface( name,"release."+opt_target_platform+"."+opt_arch )
  66. If FileType(path)<>FILETYPE_FILE
  67. Print "Failed to find module"
  68. Return
  69. EndIf
  70. Local src:TSourceFile=ParseSourceFile( path )
  71. stream.WriteLine "Module: "+name
  72. For Local t$=EachIn src.info
  73. stream.WriteLine t
  74. Next
  75. stream.WriteLine ""
  76. Local bank:TBank=TBank.Create(0)
  77. Local bank_stream:TStream=TBankStream.Create( bank )
  78. If Not Zap( ModulePath(name),bank_stream ) Throw "Failed to publish module"
  79. bank_stream.Close
  80. bank=CompressBank( bank )
  81. bank_stream=TBankStream.Create( bank )
  82. CopyStream bank_stream,stream
  83. bank_stream.Close
  84. End Function
  85. Function UnzapMod( stream:TStream )
  86. Local modinfo:TModInfo=TModInfo.CreateFromStream( stream )
  87. Local path$=ModulePath( modinfo.name )
  88. If Not CreateDir( path,True ) Throw "Unable to create module directory"
  89. DeleteDir path,True
  90. Local bank:TBank=TBank.Create(0)
  91. Local bank_stream:TStream=TBankStream.Create( bank )
  92. CopyStream stream,bank_stream
  93. bank_stream.Close
  94. bank=UncompressBank( bank )
  95. bank_stream=TBankStream.Create( bank )
  96. If Not Unzap( ExtractDir(path),bank_stream )
  97. Print "Failed to Unzap module"
  98. Return
  99. EndIf
  100. bank_stream.Close
  101. ?MacOS
  102. Ranlib path
  103. ?
  104. Return True
  105. End Function