?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. -- FMP info
  2. -- Thanks to Jerzy Kut for the num_to_char function
  3. -- Thanks to Robbob for the ReadChunkSize function
  4.  
  5. function num_to_char ( number )
  6.  return ( string.char ( math.mod ( math.mod ( number, 256 ) + 256, 256 ) ) )
  7. end
  8.  
  9. function ReadChunkID( file )
  10.  acc = ""
  11.  acc = acc..file:read(1)
  12.  acc = acc..file:read(1)
  13.  acc = acc..file:read(1)
  14.  acc = acc..file:read(1)
  15.  return acc
  16. end
  17.  
  18. function ReadChunkSize( file )
  19.  acc = 0
  20.  acc = acc + string.byte( file:read(1) )
  21.  acc = acc * 256
  22.  acc = acc + string.byte( file:read(1) )
  23.  acc = acc * 256
  24.  acc = acc + string.byte( file:read(1) )
  25.  acc = acc * 256
  26.  acc = acc + string.byte( file:read(1) )  
  27.  return acc
  28. end
  29.  
  30. function main ()
  31.  if mappy.msgBox ("FMP info", "This will show the chunks and their length in a selected FMP file. Run the script (you will be prompted for a FMP to open)?", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK then
  32.  
  33.   local isok,asname = mappy.fileRequester (".", "FMP files (*.fmp)", "*.fmp", mappy.MMB_OPEN)
  34.    if isok == mappy.MMB_OK then
  35.  
  36.     infpt = io.open (asname, "rb")
  37.     chkid = ReadChunkID (infpt)
  38.  
  39.     if chkid ~= "FORM" then
  40.      mappy.msgBox ("FMP info", "Not a FMP file "..chkid, mappy.MMB_OK, mappy.MMB_ICONINFO)
  41.      return
  42.     end
  43.  
  44.     fmplen = ReadChunkSize (infpt)
  45.  
  46.     fmpid = ReadChunkID (infpt) -- FMAP id
  47.     fmpinfo = "FMP file info:\n\n"..asname.."\nFMP file length "..(fmplen+8).."\n"..chkid.." Type: "..fmpid.." Length: "..fmplen.."\n"
  48.     fmplen = fmplen - 4
  49.  
  50.     while chkid ~= 0 do
  51.      chkid = ReadChunkID (infpt)
  52.      chklen = ReadChunkSize (infpt)
  53.      fmpinfo = fmpinfo.."Chunk id: "..chkid.."  Length: "..chklen.."\n"
  54.      infpt:read (chklen)
  55.      fmplen = fmplen - (chklen+8)
  56.      if fmplen <= 0 then
  57.       break
  58.      end
  59.     end
  60.  
  61.     infpt:close ()
  62.  
  63.     mappy.msgBox ("FMP info", fmpinfo, mappy.MMB_OK, mappy.MMB_ICONINFO)
  64.  
  65.   end
  66.  end
  67. end
  68.  
  69. test, errormsg = pcall( main )
  70. if not test then
  71.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  72. end
  73.