PDA

View Full Version : Using TrIDLib from thinBasic



Mark0
16-04-2008, 22:34
Here's a small demo that show how to use TrIDLib (http://mark0.net/code-tridlib-e.html) free edition from thinBasic.
TrIDLib is a DLL that make implementing the same filetype recognition abilities of TrID (http://mark0.net/soft-trid-e.html) on another app / tool a quick & easy task.

The usage of this edition of the library is free for personal, non commercial, reasearch or educational use.

The TrIDLib's web page is still being completed, as well as the documentation, but I think the sample source will be enough to get anyone interested up & running.

Bye!


' TrIDLib thinBasic Demo
' http://mark0.net/code-tridlib-e.html

uses "console"

#INCLUDE "TrIDLib-Const.inc"
#INCLUDE "TrIDLib-Funct.inc"

LOCAL ret AS LONG
LOCAL szBuf AS ASCIIZ * 4096
LOCAL ResNum AS LONG
LOCAL ResId AS LONG
LOCAL sOut$ as string
local MyFile$ as string

MyFile$ = "triddefs.trd" ' a random file to analyze

console_writeline "TrIDLib demo"
console_writeline

ret = TrID_LoadDefsPack("") ' load the definitions package (TrIDDefs.TRD) from current path
ret = TrID_SubmitFileA(MyFile$) ' submit the file
ret = TrID_Analyze() ' perform the analysis
IF ret THEN
ResNum = TrID_GetInfo(%TRID_GET_RES_NUM, 0, szBuf) ' get the number of results
IF ResNum = 0 THEN
console_writeline "Unknown filetype!"
ELSE
FOR ResId = 1 TO ResNum ' cycle trough the results
Ret = TrID_GetInfo(%TRID_GET_RES_FILETYPE, ResId, szBuf) ' get filetype descriptions
console_write STR$(ResId)& ":" & $TAB & szBuf
Ret = TrID_GetInfo(%TRID_GET_RES_FILEEXT, ResId, szBuf) ' get filetype extensions
console_write " (" & szBuf & ")"
Ret = TrID_GetInfo(%TRID_GET_RES_POINTS, ResId, szBuf) ' get the matching points
console_writeline " -" & STR$(Ret)
NEXT
END IF
ELSE
console_writeline "Error(s) occurred!"
END IF

console_writeline "Press any key."
CONSOLE_WAITKEY

Here's the output (the file analyzed is TrID's defs package):

TrIDLib demo

File: triddefs.trd
1: TrID defs package (TRD) - 22009
2: AOS File Format (AOS) - 10000
3: Generic RIFF container () - 4000
Press any key.

Bye!

Mark0
16-04-2008, 22:38
Here are the two include files too:

TrIDLib-const.inc

'-------------------------------------------------------
' Constants FOR TrID_GetInfo
'-------------------------------------------------------

%TRID_GET_RES_NUM = 1 ' Get the number of results available
%TRID_GET_RES_FILETYPE = 2 ' Filetype descriptions
%TRID_GET_RES_FILEEXT = 3 ' Filetype extension
%TRID_GET_RES_POINTS = 4 ' Matching points

%TRID_GET_VER = 1001 ' TrIDLib version (major * 100 + minor)
%TRID_GET_DEFSNUM = 1004 ' Number of filetypes definitions loaded


'-------------------------------------------------------
' Additional constants for the full version
'-------------------------------------------------------

%TRID_GET_DEF_ID = 100 ' Get the id of the filetype's definition for a given result
%TRID_GET_DEF_FILESCANNED = 101 ' Various info about that def
%TRID_GET_DEF_AUTHORNAME = 102 ' "
%TRID_GET_DEF_AUTHOREMAIL = 103 ' "
%TRID_GET_DEF_AUTHORHOME = 104 ' "
%TRID_GET_DEF_FILE = 105 ' "
%TRID_GET_DEF_REMARK = 106 ' "
%TRID_GET_DEF_RELURL = 107 ' "
%TRID_GET_DEF_TAG = 108 ' "
%TRID_GET_DEF_MIMETYPE = 109 ' "

%TRID_GET_ISTEXT = 1005 ' Check if the submitted file is text or binary one

TrIDLib-funct.inc:

'-------------------------------------------------------
' Functions
'-------------------------------------------------------

DECLARE FUNCTION TrID_LoadDefsPack LIB "tridlib.dll" ALIAS "TrID_LoadDefsPack" (BYREF szPath AS ASCIIZ) AS LONG
DECLARE FUNCTION TrID_SubmitFileA LIB "tridlib.dll" ALIAS "TrID_SubmitFileA" (BYREF szFileName AS ASCIIZ) AS LONG
DECLARE FUNCTION TrID_Analyze LIB "tridlib.dll" ALIAS "TrID_Analyze" () AS LONG
DECLARE FUNCTION TrID_GetInfo LIB "tridlib.dll" ALIAS "TrID_GetInfo" (BYVAL lInfoType AS LONG, _
BYVAL lInfoIdx AS LONG, _
BYREF sTrIDRes AS ASCIIZ) AS LONG

'-------------------------------------------------------
' Additional function for the full version
'-------------------------------------------------------

DECLARE FUNCTION TrID_SetDefsPack LIB "tridlib.dll" (BYVAL lDefsPtr AS LONG) AS LONG

P.S.
Amazing how quick & effortless the sample porting process from PowerBASIC was. The sources are about identical, except from printing on the console! Thanks to the thinBasic team for such an awesome tool!

Bye!

ErosOlmi
16-04-2008, 22:58
Ciao Marco.

Thanks a lot for this big present and for taking thinBasic into account for your TrIDLib development.

ErosOlmi
16-04-2008, 23:09
Marco,

where can I get TrIDDefs.TRD file?

Mark0
17-04-2008, 00:06
You'll find the most update on TrID's page:
http://mark0.net/soft-trid-e.html#download

Bye!

Petr Schreiber
17-04-2008, 08:53
Hi Mark0,

worked well in my test for new PowerPoint fileformat, BMPs and M15.
What surprised me was that it recognized even Fujifilm RAF, the database of supported formats is really huge :o


Thanks,
Petr

Mark0
17-04-2008, 14:00
Thanks Petr!