Problem with return dir name in search result (wdx plugin)

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

Moderators: white, Hacker, petermad, Stefan2

Post Reply
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Problem with return dir name in search result (wdx plugin)

Post by *olesio »

Hello. Please help me because I spend whole night and can handle it by my self with making own wdx plugin in Delphi. I'm using decWDX Delphi library from http://www.totalcmd.net/plugring/decwdx.html and my main unit renamed to mainunit.pas which use original wdxclasses unit have following declaration of my TOlesioField class:

Code: Select all

  TOlesioField = class(TdecWDXStringField)
  public
    constructor Create(AOwner : TdecWDXRoot); override;
    destructor Destroy; override;
  protected
    function IsEmpty(AData : TObject; AUnitIndex : Integer; AFlags : Integer) : Boolean; override;
    function DoGetValue2(const AFileName : string; AData : TObject; AUnitIndex : Integer;
      AFieldValue : Pointer; AMaxLen, AFlags : Integer; AIsUnicode : Boolean) : string; override;
    function GetName : string; override;
    function GetSubstitute : Integer; override;
  end;
And here are definition:

Code: Select all

constructor TOlesioField.Create(AOwner : TdecWDXRoot);
begin
  inherited Create(AOwner);
end;

destructor TOlesioField.Destroy;
begin
  inherited Destroy;
end;

function TOlesioField.GetSubstitute : integer;
begin
  Result := CONTFLAGS_FIELDEDIT;
end;

function TOlesioField.IsEmpty(AData : TObject; AUnitIndex, AFlags : Integer) : Boolean;
begin
  Result := AData = nil;
end;

function TOlesioField.GetName : string;
begin
  Result := 'File name in directory';
end;

function TOlesioField.DoGetValue2(const AFileName : string; AData : TObject; AUnitIndex : Integer;
  AFieldValue : Pointer; AMaxLen, AFlags : Integer; AIsUnicode : Boolean) : string;
var
  H : THandle;
  WFD : TWIN32FindData;
begin
  with TdecTestWDXGetValueObject(AData) do
  begin
    Result := AFileName;
    if Data.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY then
    begin
      if AFileName <> '' then
      begin
        H := FindFirstFile(PChar(AFileName + '\pft.res'), WFD);
        if H <> INVALID_HANDLE_VALUE then
        begin
          Result := AFileName;
          MessageBox(0, PChar(AFileName), PChar(string(PAnsiChar(AFieldValue))), 0);
        end;
      end;
    end;
  end;
end;
What is my goal? I want to - after typing pft.res or other file name - in "Value" field, get ONLY DIRECTORY(IES) result(s), which containt this file from "Value" field in search result. Not only filename. So two - simple I hope - questons from me:
1. How to read only string from "Value" edit field in "Plugins" tab from "Find files" window? I need it to compare in my code later. Variable AFieldValue do not return any string - even if I try converted to PChar like ValueToString function from wdxclasses.pas unit.
2. How to get only directory with defualt yellow folder icon on search result list? For Example this Test MessageBox shows me C:\PROGRAM FILES (X86)\DELPHI7\PROJECTS\MY_PREPARED FOR_TEST_DIRECTORY, but in results I only have filename. I analyzed deeply original Source Code by DEC, but He do not shows method which I want to get. Thanks in advice for any help and sorry for my bad English.
[mod]Dupe posts removed. Please, don't click the “Send” button several times if the board doesn't react immediately, just wait for… TIA.
Clo, moderator. [/mod]
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Post by *olesio »

I analyzed source of this plugin: http://www.totalcmd.net/plugring/NTFS_diz.html and I make plugin which work how I wanted to. It require ini file called fileindir.ini or with name the same as wdx plugin with ini extension. The ini file can contain max 10 section entries which should look like that above:

Code: Select all

[Search01]
IgnoreCase=1
SearchFile=*.cfg
SearchContent=for_winapi
So first is ofcourse section name from [Search01] to [Search10]. IgnoreCase (1 for True - ignore case for text to search, 0 for False - case sensitive search). SearchFile is required value and can be only extension or whole filename. SearchContent is it text to search in file. Contnet is optional. Do not enter anything to search only for specified files. So forgive me Ghisler for email with question. I handled by myself.
P.S.: and sorry for sending more than one message before. Forum freezed after pressing "Submit" and I did not seen my new topic before.
P.S.2: I fixed source above. Now False/No value can be set for files which do not contain text. Also from contentplugin.hlp I know FieldValue should be probable Pointer type, because as PChar type like in NTFS dfx plugin it can return only text values not boolean like in this case was needed.

EDIT: plugin with source availabel at: http://www.totalcmd.net/plugring/fileindir.html
Best regards: olesio
shazinaz
New Member
New Member
Posts: 1
Joined: 2011-09-29, 10:20 UTC

Post by *shazinaz »

it's really easy for me to SEE what you were talking about.
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

olesio wrote:...
EDIT: plugin with source availabel at: http://www.totalcmd.net/plugring/fileindir.html
Hi olesio

yesterday I tried your plugin.

I started a search "Find all folders which contain the file test.doc". I set
[Serach01] to the filename, no filecontent and started the search - no results, although there are files and I tried with YES and NO and restart ...

Can you give an example (or show a saved search config)?

Regards

Peter
TC 10.xx / #266191
Win 10 x64
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Post by *olesio »

Peter wrote: Can you give an example (or show a saved search config)?
Sure. Maybe my plugin do not work to perfect, but I wrote mainly for my usage and later I decided to public. So in Alt+F7 dialog you search for * in "Gerneral" Tab and in "Plugins" Tab you must choose fileindir plugin and if you want to search only dirs which containt some file (no matter what content) you must select Search03 if you have file similar fileindir.ini file

Code: Select all

[Search01]
IgnoreCase=1
SearchFile=*.cfg
SearchContent=for_winapi

[Search02]
IgnoreCase=1
SearchFile=readme
SearchContent=AGA

[Search03]
IgnoreCase=1
SearchFile=useful_winapi.pas
SearchContent=
Like you see Search03 will find dirs which only contain useful_winapi.pas. And remember my plugin read configuration from file which is named the same as plugin file. So if plugin names fileindir.wdx - config file should be named fileindir.ini. If it will be named blahblah.wdx, config should be named blahblah.ini. But default both files should be named fileindir and extension. I hope now everything will be fine. And sorry for my bad English.
Best regards: olesio
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

Thanks olesio

on Monday I will try it again. But in the meantime some clarifications:
olesio wrote:... So in Alt+F7 dialog you search for * in "Gerneral" Tab
Must it be "*" or can it also be empty (which normally is the same as "*"?

Is it necessary to select the "Attribute: Directory"-option in "Advanced tab"?
olesio wrote:

Code: Select all

[Search03]
IgnoreCase=1
SearchFile=useful_winapi.pas
SearchContent=
If I remove the line "SearchContent=" entirely - what will the plugin do?

The search options "YES and NO" work both stable?

Is "IgnoreCase" valid only for filename or also for searchcontent?

May I use wildcards (or reg-ex) in SearchContent?

What is the difference of "text-search from TC" and "SearchContent of your plugin"?

Thanks in advance

Peter
TC 10.xx / #266191
Win 10 x64
olesio
Junior Member
Junior Member
Posts: 54
Joined: 2009-01-22, 15:29 UTC
Location: Poland

Post by *olesio »

Peter wrote:Thanks olesio

on Monday I will try it again. But in the meantime some clarifications:
olesio wrote:... So in Alt+F7 dialog you search for * in "Gerneral" Tab
Must it be "*" or can it also be empty (which normally is the same as "*"?

Is it necessary to select the "Attribute: Directory"-option in "Advanced tab"?
Ah, ok - you have right the search for field can be empty.
If I remove the line "SearchContent=" entirely - what will the plugin do?
It will also work like empty text after "=".
The search options "YES and NO" work both stable?
Yes.
Is "IgnoreCase" valid only for filename or also for searchcontent?
On Windows filesystems as NTFS or FAT file name case are visible but do not care when searching for files or directories. IgnoreCase is for text case in file content.
]May I use wildcards (or reg-ex) in SearchContent?
Unfortunetly no, I do not foresee such a possibility, because in my opinion plugin file should be small as possible. So I wrote it in WinAPI technique and adding suport for RegEx may incrase project size too much. But maybe I will add this feature in future.
What is the difference of "text-search from TC" and "SearchContent of your plugin"?
The difference is that my plugin will return only Direcrories names not only filenames with searched content. I wrote this plugin because when I asked here on forum some time ago, about possibility for searching ONLY DIRECTORIES which containt some file with some text, people from forum counity recommend me script.wdx which I can not use it because I do not know script language syntax or even basic usage. You can find this topic at: http://ghisler.ch/board/viewtopic.php?t=30615 - so I decided to wrote plugin as I can and as I know Delphi language. The plugin works fine for me. And like I wrote before I decided to share it for TC Users on totalcmd.net. I hope now after my reply you know what you wanted to know :) And again sorry for my bad English.
Best regards: olesio
User avatar
Peter
Power Member
Power Member
Posts: 2064
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

I started a new thread:
http://ghisler.ch/board/viewtopic.php?p=242778

Maybe better to continue there ...

Peter
TC 10.xx / #266191
Win 10 x64
Post Reply