#21 2011-11-26 01:02

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,379

Re: MSI files are detected as ppt/xls/doc files

Hey guys.

I finally found some time to look in to this problem. The issue occurred because of the change of the current directory. It is not a problem with ReNamer (per say), but a specific way of operation of the TridLoadDefsPack function, which searches for the TrIDDefs.trd in the current directory or the explicitly specified directory.

The error message that you saw "Error! TrIDLib.dll and/or TrIDDefs.trd not found in the program directory" is generated by the script during its normal execution. If you see this message, TrIDLib.dll is already in the program's directory and it is the TrIDDefs.trd that is not found in the current directory. ReNamer wouldn't even execute the script if any of the imported functions from external library are not satisfied, i.e. if TrIDLib.dll is not found.

So, there is a need for 2 actions:

  • Raise an error during compilation of the script if external functions are not satisfied.

  • Add a function to get the application's full path (as suggested by Andrew)

And the good news is that they are both complete! smile

The added function is (also in the wiki article):

function GetApplicationPath: WideString;

Offline

#22 2011-11-26 04:28

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: MSI files are detected as ppt/xls/doc files

Hi Andrew,

I haven't quite understood what needs to be done.
It will help if you could post the updated script with this addition.

Thanks in advance!

Offline

#23 2011-11-26 10:13

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: MSI files are detected as ppt/xls/doc files

@Denis: Thanks for adding GetApplicationPath() and GetApplicationParams() as well (didn't think of the latter when I posted last time, but it's sure to be quite useful in future scripts). smile

@narayan: Here's the modified script:

[Script deleted, see below for latest version.]

Test it and let me know!

Last edited by Andrew (2011-11-26 22:57)

Offline

#24 2011-11-26 12:20

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: MSI files are detected as ppt/xls/doc files

Andrew, I got the latest beta (I tried to run v6 in the earlier beta, but it was not recognizing the GetApplicationPath function)

The latest beta gives a different compiler error:
---------------------------
ReNamer
---------------------------
Pascal Script Compile:
Unknown error (check units and libraries)
---------------------------
OK   
---------------------------

Offline

#25 2011-11-26 15:51

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: MSI files are detected as ppt/xls/doc files

Yeah, that's the new check Denis has added, which pops up when the script is compiled and all major dependant files (the DLL in this case) are not located. So:

1) Do you have the DLL in the program dir. (and the TRD, but the DLL is the main file)?

2) Do you get the error only when you run the program via your shortcut, but not when you run the EXE directly?

If the answer to both questions is "yes", then I guess Denis needs to modify his code that checks for the existence of any dependencies.

Last edited by Andrew (2011-11-26 18:16)

Offline

#26 2011-11-26 17:53

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: MSI files are detected as ppt/xls/doc files

I had actually not gone beyond the error.

But this time I ignored the error and went beyond that point.

The entire experiment is as follows:

I selected the trial file and launched the ReNamer.
Then I launched the PascalScript rule and pasted your script (v6).
When I press "Try to Compile" button, I got the error (as before), but ignored it.
Then I clicked on "Save rule" button.

Immediately another error pops up:

---------------------------
Error
---------------------------
Preview process has been terminated due to a critical error:

Pascal Script Compile:
Unknown error (check units and libraries)
---------------------------
OK   
---------------------------

At this point, if I press the Preview button, I get the same error (this is repeatable).

I changed the extension of a known file ad checked.
The ReNamer cannot find the correct extension of the file.

Offline

#27 2011-11-26 18:17

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: MSI files are detected as ppt/xls/doc files

Can you please answer the 2 questions I asked above? It will help pinpoint the exact cause of the error. Thanks!

Last edited by Andrew (2011-11-26 18:46)

Offline

#28 2011-11-26 18:58

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: MSI files are detected as ppt/xls/doc files

Update:

I re-checked, and found that both dll and TRD had gone missing somehow.
Added them to the main folder (the same folder that contains the ReNamer executable).

So please ignore the last post.
Now I can add your script (v6) w/o any compilation errors.

****
To answer your questions:

I launched the executable by clicking on it, and then added the file and PascalScript rule (with your script).
ReNamer finds the correct extension in this case.

I selected the test file and then launched ReNamer with its shortcut, and then added the PascalScript rule (with your script).
In this case there are no errors, but ReNamer does not find the correct extension either (there is no change in extension at all).

Offline

#29 2011-11-26 23:46

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: MSI files are detected as ppt/xls/doc files

Alright, here's the amended v6 that I believe should solve your problem:

{ TrID Script v6 }

// v1 - Original script by Denis
// v2 - Modified by Andrew to output lowercase extensions and detect presence of TrIDLib.dll and TrIDDefs.trd
// v3 - Modified by Andrew to keep existing extensions if not identified properly
// v4 - Modified by Andrew to display multiple possible extensions
// v5 - Modified by Andrew to display multiple possible extensions with cutoff of 20%
// v6 - Modified by Andrew to fix a path-related issue

// Important: Download http://mark0.net/download/tridlib-free.zip and http://mark0.net/download/triddefs.zip,
// then extract TrIDLib.dll and TrIDDefs.trd to ReNamer.exe's folder/directory or else the script will fail

// TrID DLL exported functions
function TridLoadDefsPack(szPath: PChar): Integer;
  external 'TrID_LoadDefsPack@TrIDLib.dll stdcall';
function TridSubmitFileA(szFileName: PChar): Integer;
  external 'TrID_SubmitFileA@TrIDLib.dll stdcall';
function TridAnalyze: Integer;
  external 'TrID_Analyze@TrIDLib.dll stdcall';
function TridGetInfo(lInfoType: Integer; lInfoIdx: Integer; sBuf: PChar): Integer;
  external 'TrID_GetInfo@TrIDLib.dll stdcall';

// Constants for TrID_GetInfo etc.
const
  TRID_GET_RES_NUM     = 1;  // Get the number of results
  TRID_GET_RES_FILEEXT = 3;  // Filetype extension
  TRID_GET_RES_POINTS  = 4;  // Matching points
  TRID_GET_RES_CUTOFF  = 20; // Cutoff percentage for results

function GetExtensions(): WideString;
var
  Str1, Str2: String;
  I, NumRes, NumPts, TotPts: Integer;

begin
  Result := '';
  SetLength(Str1, 100);
  NumRes := TridGetInfo(TRID_GET_RES_NUM, 0, PChar(Str1));
  if (NumRes > 0) then
  begin
    for I := 1 to NumRes do
      TotPts := TotPts + TridGetInfo(TRID_GET_RES_POINTS, I, PChar(Str1));
    for I := 1 to NumRes do
    begin
      NumPts := TridGetInfo(TRID_GET_RES_POINTS, I, PChar(Str1));
      if ((NumPts*100/TotPts) > TRID_GET_RES_CUTOFF) then
      begin
        TridGetInfo(TRID_GET_RES_FILEEXT, I, PChar(Str1));
        Str2 := LowerCase(String(PChar(Str1)));
        if (Length(Str2)>0) And (Pos(Str2, Result)=0) then
        begin
          if (I > 1) then Result := Result + '/';
          Result := Result + Str2;
        end;
      end;
    end;
  end;
end;

var
  Initialized: Boolean;
  AppPath, FileExts: WideString;

begin
  if (not Initialized) then
  begin
    Initialized := True;
    AppPath := WideExtractFilePath(GetApplicationPath());
    if (TridLoadDefsPack(AppPath) = 0) then
    begin
      WideDeleteFile(AppPath + 'TrIDDefs.trd');
      if (DialogYesNo('Error! TrIDDefs.trd not found in the program directory (' + AppPath + ')!'
      + #13#10#13#10 + 'Do you want to download the latest version from the TrID website now?')) then
        ShellOpenFile('http://mark0.net/soft-trid-e.html');
      Exit;
    end;
  end;
  if (TridSubmitFileA(PChar(FilePath)) <> 0) then
  begin
    if (TridAnalyze <> 0) then
    begin
      FileExts := GetExtensions();
      if (Length(FileExts) > 0) then FileName := WideStripExtension(FileName) + '.' + FileExts;
    end;
  end;
end.

Last edited by Andrew (2011-11-27 14:28)

Offline

#30 2011-11-27 03:41

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: MSI files are detected as ppt/xls/doc files

Thanks Andrew!

This works just fine.

***
Is this version of script ready for inclusion in the wiki or would you like to wait for Denis to add/update some function(s), and then modify the script further?

Last edited by narayan (2011-11-27 03:48)

Offline

Board footer

Powered by FluxBB