From TotalcmdWiki
Jump to navigation Jump to search

ContentGetDetectString is called when the plugin is loaded for the first time. It should return a parse function which allows Total Commander to find out whether your plugin can probably handle the file or not. You can use this as a first test - more thorough tests may be performed in ContentGetValue(). It's very important to define a good test string, especially when there are dozens of plugins loaded! The test string allows Total Commander to call only those plugins relevant for that specific file type.


int __stdcall ContentGetDetectString(char* DetectString,int maxlen);

Description of parameters:

DetectString Return the detection string here. See remarks for the syntax.

maxlen Maximum length, in bytes, of the detection string (currently 2k).

Return value:

The return value is unused and should be set to 0. You can also declare the function as "void __stdcall".


The syntax of the detection string is as follows. There are operands, operators and functions.


EXT The extension of the file to be loaded (always uppercase).
SIZE The size of the file to be loaded.
FORCE 1 if the user chose 'Image/Multimedia' from the menu, 0 otherwise.

MULTIMEDIA This detect string is special: It is always TRUE (also in older TC versions). If it is present in the string, this plugin overrides internal multimedia viewers in TC. If not, the internal viewers are used. Check the example below!
[5] The fifth byte in the file to be loaded. The first 8192 bytes can be checked for a match.
12345 The number 12345
"TEST" The string "TEST"


& AND. The left AND the right expression must be true (!=0).
| OR: Either the left OR the right expression needs to be true (!=0).
= EQUAL: The left and right expression need to be equal.
!= UNEQUAL: The left and right expression must not be equal.
< SMALLER: The left expression is smaller than the right expression. Comparing a number and a string returns false (0). Booleans are stored as 0 (false) and 1 (true).
> LARGER: The left expression is larger than the right expression.


() Braces: The expression inside the braces is evaluated as a whole.
!() NOT: The expression inside the braces will be inverted. Note that the braces are necessary!
FIND() The text inside the braces is searched in the first 8192 bytes of the file. Returns 1 for success and 0 for failure.
FINDI() The text inside the braces is searched in the first 8192 bytes of the file. Upper/lowercase is ignored.

Internal handling of variables

Varialbes can store numbers and strings. Operators can compare numbers with numbers and strings with strings, but not numbers with strings. Exception: A single char can also be compared with a number. Its value is its ANSI character code (e.g. "A"=65). Boolean values of comparisons are stored as 1 (true) and 0 (false).


String Interpretation

EXT="WAV" | EXT="AVI" The file may be a Wave or AVI file.

EXT="WAV" & [0]="R" & [1]="I" & [2]="F" & [3]="F" & FIND("WAVEfmt") Also checks for Wave header "RIFF" and string "WAVEfmt"

EXT="WAV" & (SIZE<1000000 | FORCE) Load wave files smaller than 1000000 bytes at startup/file change, and all wave files if the user explictly chooses 'Image/Multimedia' from the menu.

([0]="P" & [1]="K" & [2]=3 & [3]=4) | ([0]="P" & [1]="K" & [2]=7 & [3]=8) Checks for the ZIP header PK#3#4 or PK#7#8 (the latter is used for multi-volume zip files).

EXT="TXT" & !(FINDI("<HEAD>") | FINDI("<BODY>")) This plugin handles text files which aren't HTML files. A first detection is done with the <HEAD> and <BODY> tags. If these are not found, a more thorough check may be done in the plugin itself.

MULTIMEDIA & (EXT="WAV" | EXT="MP3") Replace the internal player for WAV and MP3 files (which normally uses Windows Media Player as a plugin). Requires TC 6.0 or later!

Operator precedence

The strongest operators are =, != < and >, then comes &, and finally |. What does this mean? Example: expr1="a" & expr2 | expr3<5 & expr4!=b will be evaluated as ((expr1="a") & expr2) | ((expr3<5) & (expr4!="b"))
If in doubt, simply use braces to make the evaluation order clear.

Back to Content plugins developer guide