Detect path to TC main settings file from plugin

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

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
norfie
Power Member
Power Member
Posts: 1194
Joined: 2003-02-18, 14:18 UTC

Detect path to TC main settings file from plugin

Post by *norfie »

kajoj1 wrote:@norfie
So how can I get wincmd.ini location :?:
Some of my future VisualDirSize functions will use values from wincmd.ini...
Please read the LS-Plugin writer's guide:
ListDefaultParamStruct ...
DefaultIniName Suggested location+name of the ini file where the plugin could store its data. This is a fully qualified path+file name, and will be in the same directory as the wincmd.ini. It's recommended to store the plugin data in this file or at least in this directory, because the plugin directory or the Windows directory may not be writable!
But you can extract the path to wincmd.ini only - not the real file name of wincmd.ini which can has other names. Maybe Christian Ghisler knows a solution?

[mod]Splited from: http://www.ghisler.ch/board/viewtopic.php?t=8222

Lefteous (Moderator)[/mod]
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2kajoj1
So how can I get wincmd.ini location
It's possible to detect the exact location. Maybe there are easier ways but this should work:

1. The highest priority for wincmd.ini locations is the /i commandline parameter. Use the GetCommandLine Winapi function to get this path and extract the value of the /i parameter. If the commandline string contains /i --> done, otherwise continue to 2.
2. Search for the file Wincmd.ini in TC program directory (%COMMANDER_PATH% environment string). If the file exists continue to 2a. Otherwise continue to 3.
2a. Read UseIniInProgramDir setting in [Configuration] section. Binary compare UseIniInProgramDir with 1 to find out if wincmd.ini in current directory is used. If this is the case continue to 2b, otherwise continue to 3.
2b. Binary compare UseIniInProgramDir with 4 to find out of UseIniInProgramDir should overwrite eventually existing registry values. If this is the case --> done, otherwise continue to 3.
3. Read the registry setting "IniFileName" in
HKEY_CURRENT_USER\Software\Ghisler. If path has been found --> done, otherwise read the setting "IniFileName" in HKEY_LOCAL_MACHINE\Software\Ghisler. If a path has been found here --> done, otherwise continue to 3a.
3a. If 2a returned true (UseIniInProgramDir AND 1) use the Wincmd.ini in program directory (done) otherwise continue to 4.
4. The lowest priority is a Wincmd.ini file in Windows directory (done). Otherwise no valid ini file exists.

Some remarks: I have not tested if a file named Totalcmd.ini is used instead of Wincmd.ini for 4.
It cannot be used for 2.
kajoj1
Member
Member
Posts: 122
Joined: 2005-08-08, 10:24 UTC
Contact:

Post by *kajoj1 »

@Lefteous
3. Read the registry setting "IniFileName" in
HKEY_CURRENT_USER\Software\Ghisler. If path has been found --> done, otherwise read the setting "IniFileName" in HKEY_LOCAL_MACHINE\Software\Ghisler. If a path has been found here --> done, otherwise continue to 3a.
Now I am completely disoriented. So I can use Registry or not :?:
User avatar
norfie
Power Member
Power Member
Posts: 1194
Joined: 2003-02-18, 14:18 UTC

Post by *norfie »

It's possible to detect the exact location. Maybe there are easier ways but this should work ...
It's not necessary to find out the path - this information you can get from ListDefaultParamStruct but the filename of wincmd.ini can be changed by command-line only (?).
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2kajoj1
Now I am completely disoriented. So I can use Registry or not Question
Yes the path to the main settings file could be saved in the registry.

2norfie
It's not necessary to find out the path - this information you can get from ListDefaultParamStruct but the filename of wincmd.ini can be changed by command-line only (?).
It could be another one in one of the registry settings. As I wrote in remarks I have not tested this for point 4. As far as I rememeber I tested it for point 2 and in this case totalcmd.ini is not possible.
User avatar
petermad
Power Member
Power Member
Posts: 16009
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2kajoj1
Now I am completely disoriented. So I can use Registry or not
Not as the only approach, since the path might NOT be in the registry - it will for example not be there if the user has unpacked his Total Commander from the installation file i stead of having run (executed) the installation file.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
kajoj1
Member
Member
Posts: 122
Joined: 2005-08-08, 10:24 UTC
Contact:

Post by *kajoj1 »

OK so this is my proposal to get wincmd.ini (based of Lefteous one) :

Assumptions:
ListDefaultParamStruct always give me right path to "wincmd.ini"
default filename is "wincmd.ini"
filename of "wincmd.ini" can be changed by command-line or in registry

Algorithm:
1. Get path using ListDefaultParamStruct
2. Use the GetCommandLine Winapi function to get this path and extract the value of the /i parameter. If the commandline string contains /i --> done, otherwise continue to 3.
3. Read the registry setting "IniFileName" in HKEY_CURRENT_USER\Software\Ghisler.
If path has been found --> done, otherwise read the setting "IniFileName" in HKEY_LOCAL_MACHINE\Software\Ghisler. If a path has been found here --> done, otherwise continue to 4.
4. Try filename "wincmd.ini" and check if file exist. If no than cannot find wincmd.ini name (should never appears)
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2kajoj1
I have now tested the last open question. TC doesn't look for Totalcmd.ini in Windows directory. Your optimized algorithm should always return the right path to the main settings file.

An additional hint for others who are interested in main settings file location detection: Both algorithms will fail for standalone executables simply because of the fact that GetCommandLine will not return the TC commandline but the standalone tool commandline.
kajoj1
Member
Member
Posts: 122
Joined: 2005-08-08, 10:24 UTC
Contact:

Post by *kajoj1 »

I have implemented this algorithm. It seems to work OK. :D
User avatar
Alextp
Power Member
Power Member
Posts: 2321
Joined: 2004-08-16, 22:35 UTC
Location: Russian Federation
Contact:

Post by *Alextp »

2All
Here is the Delphi code to detect paths to wincmd.ini and wcx_ftp.ini (main and ftp ini files).
From TC Plugins Manager code.
If functions return paths that not exist, then paths must be entered manually, by user.

Code: Select all

function tcDefDir: string;
begin
  //get from running TC
  Result:= SProc.SExpandVars('%COMMANDER_PATH%');
  //get from registry
  if Pos(':\', Result)=0 then
  Result:=
    GetRegKeyStr(HKEY_CURRENT_USER, 'Software\Ghisler\Total Commander', 'InstallDir',
    GetRegKeyStr(HKEY_LOCAL_MACHINE, 'Software\Ghisler\Total Commander', 'InstallDir',
      'C:\TotalCmd'));
end;

function tcDefExe: string;
begin
  Result:= tcDefDir+'\Totalcmd.exe';
end;

function tcDefIni: string;
begin
  Result:= 
    GetRegKeyStr(HKEY_CURRENT_USER, 'SOFTWARE\Ghisler\Total Commander', 'IniFileName',
    GetRegKeyStr(HKEY_LOCAL_MACHINE, 'SOFTWARE\Ghisler\Total Commander', 'IniFileName',
    'wincmd.ini'));
  if Pos('\', Result)=0 then Insert('%windir%\', Result, 1);
  //if string ".\Wincmd.ini":
  if Pos('.\', Result)=1 then
    SReplace(Result, '.', tcDefDir);
  Result:= SExpandVars(Result);
end;

function tcDefIniFtp: string;
begin
  Result:= 
    GetRegKeyStr(HKEY_CURRENT_USER, 'SOFTWARE\Ghisler\Total Commander', 'FtpIniName',
    GetRegKeyStr(HKEY_LOCAL_MACHINE, 'SOFTWARE\Ghisler\Total Commander', 'FtpIniName',
    'wcx_ftp.ini'));
  if Pos('\', Result)=0 then Insert('%windir%\', Result, 1);
  //if string ".\Wincmd.ini":
  if Pos('.\', Result)=1 then
    SReplace(Result, '.', tcDefDir);
  Result:= SExpandVars(Result);
end;
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

I have found out that the optimzed algorithm by kajoj1 will fail in the following cases:
These conditions must be fulfilled:
1. A Wincmd.ini exists in the Total Commander directory.
2. UseIniInProgramDir is set to use the Wincmd.ini in Total Commander directory.
3. The registry value points to a completely different location.

In this case it's possible to detect that Wincmd.ini in Total Commander is the right one by comparing the directory paths of the registry value and the plugin function value. If they are different Wincmd.ini in Total Commander is the right one.


There is another case which cannot be handled this way:
These conditions must be fulfilled:
1. A Wincmd.ini exists in the Total Commander directory.
2. UseIniInProgramDir is set to use the Wincmd.ini in Total Commander directory.
3. The registry value only differs in filename from the plugin function value.

In this case the wrong ini file name will be used.

My recommendation is to check the value of the UseIniInProgramDir setting as suggested in my algorithm above.
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

Around this?

Post by *Clo »

2Lefteous
:) Hello Christian !

- Someting related to this issue ?

:D Glad to hear your opinion…

:mrgreen: VG
Claude
Clo
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
User avatar
Lefteous
Power Member
Power Member
Posts: 9536
Joined: 2003-02-09, 01:18 UTC
Location: Germany
Contact:

Post by *Lefteous »

2Clo
Well this is something completely different for plug-ins and standalone applications like TC Plugins Manager.

I'll post a detailed answer in the other thread.
Post Reply