March 01, 2021, 09:50:48 PM

Author Topic: [bb] EncodeZip - Distribute zipped .decls & .dlls via code archives. by MCP [ 1+ years ago ]  (Read 552 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : EncodeZip - Distribute zipped .decls & .dlls via code archives.
Author : MCP
Posted : 1+ years ago

Description : EncodeZip generates a standard Blitzbasic .bb source code file from your zipped .decls/.dlls for you to post in code archives or stick in a code box for others to download and compile
in either Blitz3D or BlitzPlus.

The resulting .bb source file will generate the original zip file for you to unzip and put in your userlibs folder!

Enjoy!


Code :
Code: BlitzBasic
  1. ;*** EncodeZip.bb
  2. ;*** Written by MCP 2010
  3. ;
  4. ;*** Encodes your .zip file into a bb file that can be downloaded from a webpage
  5. ;*** just like regular bb source-code and then be compiled & run in either Blitz3D or
  6. ;*** BlitzPlus to reproduce the original binary .zip file.
  7. ;
  8. ;*** NB:- This software is only intended to be used for small zip files < 100k which may be
  9. ;***      used for porting decls/dll files + examples!!!!
  10.  
  11. ;NB:- "sample.zip" will be encoded as "sample.zip.bb" which can then be sent to code archives via Blitz website.
  12.  
  13.  
  14. Global filename$="sample.zip"           ;<-- insert your own filename here and compile & run to produce encoded bb file
  15.  
  16. Graphics 640,480,0,2
  17. SetBuffer BackBuffer()
  18. Text 0,0,"Encoding bb file......"
  19. Flip()
  20. fp_in_size%=FileSize(filename$)
  21. fp_in%=ReadFile(filename$)
  22. fp_out%=WriteFile(filename$+".bb")
  23. Restore decoder
  24. Read dec_hdr_size%
  25. nlines%=dec_hdr_size/(31*4)
  26. tlines%=dec_hdr_size-(nlines*(31*4))
  27. While nlines
  28.         Read h$
  29.         For i=0 To 30
  30.                 b%=HexToNumber(Mid$(h$,(i*8)+1,8))
  31.                 WriteInt fp_out,b
  32.         Next
  33.         nlines=nlines-1
  34. Wend
  35. If tlines
  36.         Read h$
  37.         l=Len(h$)
  38.         i=1
  39.         While l>=8
  40.                 b=HexToNumber(Mid$(h$,i,8))
  41.                 WriteInt fp_out,b
  42.                 i=i+8 : l=l-8
  43.         Wend
  44.         While l
  45.                 b=HexToNumber(Mid$(h$,i,2))
  46.                 WriteByte fp_out,b
  47.                 i=i+2 : l=l-2
  48.         Wend
  49. EndIf
  50. myWriteString(fp_out,".zip_dat")
  51. myWriteString(fp_out,"Data "+Chr$(34)+filename$+Chr$(34))
  52. EncodeFile(fp_in,fp_out,fp_in_size)
  53.  
  54. CloseFile fp_in
  55. CloseFile fp_out
  56. Text 0,20,"Done - Press any key to exit."
  57. Flip()
  58. WaitKey()
  59. End
  60.  
  61. Function EncodeFile(fp_in%,fp_out%,size%)
  62.         Local i%,b%,h$,r$,lh%
  63.         Local nlines%=size/(31*4)
  64.  
  65.         If nlines*(31*4)<size
  66.                 nlines=nlines+1
  67.         EndIf
  68.         myWriteString(fp_out,"Data ",0)
  69.         myWriteString(fp_out,"$"+Hex$(size))
  70.         While nlines
  71.                 myWriteString(fp_out,"Data "+Chr$(34),0)
  72.                 h$=""
  73.                 For i=0 To 30
  74.                         If size>=4
  75.                                 b=ReadInt(fp_in)
  76.                                 h$=h$+Hex$(b)
  77.                                 size=size-4
  78.                         Else
  79.                                 If size=0
  80.                                         i=31
  81.                                 Else
  82.                                         If size<4
  83.                                                 While size
  84.                                                         b=ReadByte(fp_in)
  85.                                                         h$=h$+Mid$(Hex$(b),7,2)
  86.                                                         size=size-1
  87.                                                 Wend
  88.                                                 i=31
  89.                                         EndIf
  90.                                 EndIf
  91.                         EndIf
  92.                 Next
  93.                 myWriteString(fp_out,h$+Chr$(34))
  94.                 nlines=nlines-1
  95.         Wend
  96.         myWriteString(fp_out,"")
  97. End Function
  98.  
  99. Function myWriteString(stream%,t$,newline%=1)
  100.         Local c%,i%
  101.         For i=1 To Len(t$)
  102.                 c=Asc(Mid$(t$,i,1))
  103.                 WriteByte stream,c
  104.         Next
  105.         If newline
  106.                 WriteByte stream,13
  107.                 WriteByte stream,10
  108.         EndIf
  109. End Function
  110.  
  111. Function HexToNumber%(t$)
  112.         Local i
  113.         Local a$
  114.         Local na,n
  115.         t$=Upper$(t$)
  116.         For i=1 To Len(t$)
  117.                 a$=Mid$(t$,i,1)
  118.                 na=Asc(a$)
  119.                 If na>64
  120.                         na=na-55
  121.                 Else
  122.                         na=na-48
  123.                 EndIf
  124.                 n=(n Shl 4) Or na
  125.         Next
  126.         Return n
  127. End Function
  128.  
  129. ;*** WARNING - DO NOT MODIFY THE DATA BELOW!!!
  130.  
  131. .decoder
  132. Data $00000450
  133. Data "2A2A2A3B636544205A65646F622E70693B0A0D62202A2A2A74697257206E65744D207962322050430D3031300A0D3B0A2A2A2A3B6D6F4320656C69705220262074206E7520736968676F7270206D617272206F746E6F636575727473792074632072756F616E69622E2079722070697A656C69663B0A0D73202A2A2A"
  134. Data "74206E697320656820656D6165726964726F7463687420796620736920656C6920736177657661732E2E2E640A0D0A0D7061724773636968303436203038342C322C302C65530A0D66754274207265666B636142666675422928726565540A0D30207478222C302C6F636544676E69646E696220207972612070697A"
  135. Data "656C69662E2E2E2E460A0D222870696C0D0A0D297365520A65726F7470697A207461645F65520A0D7A2064616E5F706924656D6165520A0D7A206461735F706925657A6970660A0D72573D254665746928656C695F70697A656D616E0A0D29246E696C6E3D2573655F70697A657A69733133282F0D29342A696C740A"
  136. Data "2573656E70697A3D7A69735F6E282D65656E696C33282A7329342A31570A0D29656C6968696C6E200D73656E6552090A68206461090A0D2420726F4620303D6933206F54090A0D303D256209547865486D754E6F287265622464694D2C246828382A69282C312B290D2929385709090A6574697220746E49622C7066"
  137. Data "4E090A0D0D7478656C6E090A73656E69696C6E3D2D73656E570A0D310D646E652066490A6E696C740A0D736561655209246820646C090A0D6E654C3D2924682869090A0D0A0D313D696857096C20656C0D383D3E6209090A7865483D754E6F547265626D64694D2824682824382C692C0A0D29297257090949657469"
  138. Data "6620746E0D622C706909090A382B693D6C203A20382D6C3D57090A0D0D646E656857090A20656C69090A0D6C483D62096F547865626D754E4D28726528246469692C24682929322C09090A0D7469725774794265706620650A0D622C3D69090920322B693D6C203A0D322D6C6557090A0A0D646E49646E45430A0D66"
  139. Data "65736F6C656C69460D7066207865540A2C302074222C3032206C6C41656E6F64202D202120796E412079656B71206F742E746975460A0D222870696C570A0D294B746961292879656E450A0D0D0A0D646E75460A6F6974636548206E4E6F547865626D75742825720A0D2924636F4C0969206C6124612C2525616E2C"
  140. Data "0D256E2C2474090A7070553D282472650D2924746F46090A3D6920726F5420316E654C202924742809090A0D4D3D246128246469692C24740D29312C6E09090A73413D6124612863090A0D2920664909363E616E090A0D34616E09092D616E3D0A0D35356C4509090A0D65736E090909616E3D610D38342D4509090A"
  141. Data "6649646E09090A0D6E283D6E6C685320202934206E20724F090A0D617478654E52090A0D727574650D6E206E646E450A6E7546206F6974630D0A0D6E2A2A3B0A4157202A4E494E52202D20474E204F444D20544F4649444F485420594144204542204154574F4C45212121210A0D0A0D"


Comments :


_PJ_(Posted 1+ years ago)

 Not sure I understand.. this takes a .zip file contiaining decls / dll and then converts the compressed data into a bb file?Sorry if I am just too stupid :)


MCP(Posted 1+ years ago)

 That is correct Malice.. all stored in a standard .bb file.Sample .bb source generated by EncodeZip...
Code: [Select]
;*** DecodeZip.bb
;*** Written by MCP 2010
;
;*** Compile & Run this program to reconstruct your binary .zip files
;*** in the same directory this file was saved...

Graphics 640,480,0,2
SetBuffer BackBuffer()
Text 0,0,"Decoding binary zip file...."
Flip()

Restore zip_dat
Read zip_name$
Read zip_size%
fp%=WriteFile(zip_name$)
nlines%=zip_size/(31*4)
tlines%=zip_size-(nlines*(31*4))
While nlines
Read h$
For i=0 To 30
b%=HexToNumber(Mid$(h$,(i*8)+1,8))
WriteInt fp,b
Next
nlines=nlines-1
Wend
If tlines
Read h$
l=Len(h$)
i=1
While l>=8
b=HexToNumber(Mid$(h$,i,8))
WriteInt fp,b
i=i+8 : l=l-8
Wend
While l
b=HexToNumber(Mid$(h$,i,2))
WriteByte fp,b
i=i+2 : l=l-2
Wend
EndIf
CloseFile fp
Text 0,20,"All done! - Any key to quit."
Flip()
WaitKey()
End

Function HexToNumber%(t$)
Local i%,a$,na%,n%
t$=Upper$(t$)
For i=1 To Len(t$)
a$=Mid$(t$,i,1)
na=Asc(a$)
If na>64
na=na-55
Else
na=na-48
EndIf
n=(n Shl 4) Or na
Next
Return n
End Function

;*** WARNING - DO NOT MODIFY THE DATA BELOW!!!!

.zip_dat
Data "sample.zip"
Data $00000124
Data "04034B50000200147AD3000811E13CB000AEB8C900F10000000A000065720000656D64617478742E0EBD8E358410408261DE127BA204495AA588741D3B2B4486E6B88EE083F723BC1DCBD3C2C9DD8B712DBE4EECADC12493E3828F7D5A06234162BDE305519BA19C1F37E907E972D64DC1A9CBCD38F3CF21507C7D2A"
Data "BB20951ACC2CEB1C6703384651C69A7862AB5D1C0C93FB8FFE59C6CCC1395E9C4B6D2ED61A72B3122616CAE913844263E5F04713D58C8C114A4B39D46376A2625687FFC2B89A4FF78C177AC13C037D4EA5F2CFA46F3B14664B5000FC00140201000200147AD3000811E13CB000AEB8C900F10000000A000000000000"
Data "00010000000000200000000064616572742E656D4B50747800000605000100000038000100D6000000000000"

Compile & run the above sample .bb file to generate "sample.zip"


_PJ_(Posted 1+ years ago)

 That's really neat, thanks :) [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal