Trying to develop a FS plugin

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Trying to develop a FS plugin

Post by *djorge »

Hi there. I'm trying to develop my first FS plugin. I've already read the FS interface provided. Unfortunatly, this is my first attempt to play with the filesystem structures provided by windows os.

I want my FS structure made by strings of text. How can i do that ?

Let suppose i have 2 array of strings. I was trying to put these strings in my filesystem structure. The first array appears in first place. The second array must appears when i press enter in the first string of FS plugin.

Can anyone help me? I know this is a simple example that do nothing, but its an interisting example for who is beginning to construct an FS Plugin and don't understand these FS structures provide by windows.

Thanks in advance.

David Jorge
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50421
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

You need to implement FsFindFirst and FsFindNext. In FsFindFirst, check the path sent to you by Total Commander: If it is the root "\", then send the first string. allocate some structure with malloc() (or getmem in Delphi) to store the state of the search, and return the pointer to this structure as the file find handle.

Total Commander then calls FsFindNext and sends you back your handle. Check in the state what directory is enumerated, and send back the next item from the list.

I recommend that you have a look at some plugins available with source code, e.g. the sample plugin:
https://plugins.ghisler.com/fsplugins/sampleplugin.zip

This is a very simple plugin which mirrors just the local file system. Observing what it does in a debugger is a good way to learn how plugins work.
Author of Total Commander
https://www.ghisler.com
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

ghisler(Author) wrote: I recommend that you have a look at some plugins available with source code, e.g. the sample plugin:
https://plugins.ghisler.com/fsplugins/sampleplugin.zip

This is a very simple plugin which mirrors just the local file system. Observing what it does in a debugger is a good way to learn how plugins work.
Thank you by your answer.

I have already seen the sample plugin provided. The problem is about my poor knowledge or windows filestructure (findfirst, findnext and due to these functions being recurvive functions which are dificulty to understand).

So, if i want to assign one string to the file directory so that the string appears in the file panel, do i need to implement the FsFindNext? I know that a FsFindNext is only needed to descend in the file structure (which its not what i want).

Thanks. djorge.
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

ghisler(Author) wrote:Observing what it does in a debugger is a good way to learn how plugins work.
Debugeer? How do i do that as this is a plugin?

Thanks in advance
djorge
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

So, if i want to assign one string to the file directory so that the string appears in the file panel, do i need to implement the FsFindNext? I know that a FsFindNext is only needed to descend in the file structure (which its not what i want).
You have to fill the structure (you reveive a pointer to it, the memory is already allocated). First fill it with 0, the only mandatory field is the filename. Just copy the appropriate name with strcopy or similar (it is a null terminated string). If you want to fill the change date, look at the type, and convert your string accordingly and again, copy the value into the structure. And so on :-)
I switched to Linux, bye and thanks for all the fish!
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

A very minimalistic template in Delphi:

Code: Select all

library TCFSPluginTest;

{$DEFINE NOFORMS}

uses
  fsPlugin,
  SysUtils,
  Classes,
  Windows,
  ShellApi;

{$E wfx}
{$R *.res}

var
  giPluginNr: integer;

procedure FsGetDefRootName(DefRootName:pchar;maxlen:integer); stdcall;
begin
  StrPCopy(DefRootName, 'FSPluginTest' );
end;

function FsInit(
  PluginNr: Integer;
  pProgressProc: TProgressProc;
  pLogProc: TLogProc;
  pRequestProc: TRequestProc )
: Integer; stdcall;
begin
  giPluginNr := PluginNr;
  Result := 0;
end;

function FsFindFirst(
  path :pchar;
  var FindData: tWIN32FINDDATA )
: thandle; stdcall;
begin
  FillChar( FindData, SizeOf( FindData ), 0 );
  StrPCopy( FindData.cFileName, 'Test1.txt' );
  Result := 13;
end;

function FsFindNext(
  Hdl: thandle;
  var FindData:tWIN32FINDDATA )
: bool; stdcall;
begin
  Result := False;
end;

function FsFindClose(Hdl:thandle):integer; stdcall;
begin
  Result := 0;
end;

exports
  FsGetDefRootName,
  FsInit,
  FsFindFirst,
  FsFindNext,
  FsFindClose;

begin

end.
This shows one file in the panel (Test1.txt), date is what integer 0 means as date ;-) no size, or attributes.
I switched to Linux, bye and thanks for all the fish!
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

SanskritFritz wrote:A This shows one file in the panel (Test1.txt), date is what integer 0 means as date ;-) no size, or attributes.
Thank you very much. I have convert your code into c++ and it worked. Now i am beginning to understand how this stuff works :).

In my next challenge i want a dialog box to appear when i press enter whenever the cursor is on top the filename. How do i do that?


Thanks in advance.
djorge
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

I'd like to know why i can't use AfxMessageBox macro inside the FsExecuteFille.

It seems that i can't use MFC's in the plugins.

Am i right? do i have to create my windows (like a simple message box) with the win32 CreateWindow fuction?


Can anyone help me?

Thanks in advance.
djorge
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

2djorge
I dont know MFC, but a message box stops any message queue, and sets up his own, until a button is pressed. So AFAIK you have to launch a message box in another message queue, not in the default.
I switched to Linux, bye and thanks for all the fish!
djorge
Senior Member
Senior Member
Posts: 422
Joined: 2003-07-03, 12:48 UTC
Location: Portugal

Post by *djorge »

The problem i had when using the AfXmessageBox called was with include conflits. It seems that totalcmd is a pure win32 application and needs to have the header windows.h included which is not supported when we include MFC code.

I have created window with the fuction MessageBox(....) which is a pure win32 function.

I don't know if i am right....


Thanks djorge
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50421
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Total Commander is in fact a Delphi program, which uses its own class library different from MFC. I don't know whether it's possible to write plugins using MFC - it shouldn't be any different from writing DLLs with MFC when the calling app doesn't use MFC.
Author of Total Commander
https://www.ghisler.com
User avatar
SanskritFritz
Power Member
Power Member
Posts: 3693
Joined: 2003-07-24, 09:25 UTC
Location: Budapest, Hungary

Post by *SanskritFritz »

2djorge
needs to have the header windows.h included
Why? The fsplugin.h header is all you need to interface with TC. What YOUR dll uses as headers, is entirelly your decision. There is no source taken from TC whatsoever.
All you need to provide is callback functions, in an appropriate manner (__stdcall, etc.) and call some TC functions by function pointers you receive when calling FsInit. This is purely C related functionality, MFC is just a library you use.
Where did you include windows.h?
I switched to Linux, bye and thanks for all the fish!
User avatar
Flint
Power Member
Power Member
Posts: 3501
Joined: 2003-10-27, 09:25 UTC
Location: Belgrade, Serbia
Contact:

Post by *Flint »

2 ghisler(Author)
Total Commander is in fact a Delphi program, which uses its own class library different from MFC. I don't know whether it's possible to write plugins using MFC - it shouldn't be any different from writing DLLs with MFC when the calling app doesn't use MFC.
It is possible ;) I have already written 3 plugins - LinkInfo, VirtualDisk and JccView - and all of them are written using MFC. And all of them work normally.
User avatar
fg_2002fr
Senior Member
Senior Member
Posts: 267
Joined: 2003-02-24, 10:12 UTC
Location: Tours (France)
Contact:

Post by *fg_2002fr »

to ghisler(Author)

for me too, all my plugins ( fileinfo, mmedia, dircpy ) are written using MFC without any problem

FG
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50421
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks for confirming it! Since I don't use MFC myself, it would be nice if there were at least one MFC plugin with source as an example for others...
Author of Total Commander
https://www.ghisler.com
Post Reply