⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atxtotalcmd.pas

📁 支持版本:Delphi 5-2009, C++Builder 5-2009 ATViewer特性: Text, Binary, Hex, Unicode:所有文件
💻 PAS
字号:
unit ATxTotalCmd;

interface

function TCDefExe: string; //Path to Total Commander's executable (Totalcmd.exe)
function TCDefIni: string; //Path to TC's config file (named wincmd.ini by default)
function TCDefIniFTP: string; //Path to TC's FTP config file (named wcx_ftp.ini by default)

procedure SetTcIniFilename(const fn: string);
function GetTcIniKey(const section, key: string): string;
procedure SetTcIniKey(const section, key: string; const value: string);


implementation

uses
  Windows, SysUtils, IniFiles,
  ATxSProc, ATxRegistry, ATxUtils;

var
  FIniFile: TIniFile = nil;


procedure SetTcIniFilename(const fn: string);
begin
  if Assigned(FIniFile) then
    FreeAndNil(FIniFile);
  FIniFile:= TIniFile.Create(fn);
end;

function tcDefDir: string;
begin
  Result:= SExpandVars('%COMMANDER_PATH%');
  if SExpanded(Result) then Exit;

  Result:=
    GetRegKeyStr(HKEY_CURRENT_USER, 'Software\Ghisler\Total Commander', 'InstallDir',
    GetRegKeyStr(HKEY_LOCAL_MACHINE, 'Software\Ghisler\Total Commander', 'InstallDir', ''));
end;

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

function tcDefIni: string;
begin
  Result:= SExpandVars('%COMMANDER_INI%');
  if SExpanded(Result) then Exit;

  Result:= 
    GetRegKeyStr(HKEY_CURRENT_USER, 'SOFTWARE\Ghisler\Total Commander', 'IniFileName',
    GetRegKeyStr(HKEY_LOCAL_MACHINE, 'SOFTWARE\Ghisler\Total Commander', 'IniFileName',
    ''));
  if Result='' then Exit;

  if Pos('\', Result)=0 then
    Insert('%windir%\', Result, 1);

  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',
    ''));
  if Result='' then Exit;

  if Pos('\', Result)=0 then
    Insert('%windir%\', Result, 1);

  if Pos('.\', Result)=1 then
    SReplace(Result, '.', tcDefDir);

  Result:= SExpandVars(Result);
end;


//----------------------------------------------------------------------------
function ActualFileName(const section: string): string;
var
  S: string;
begin
  Result:= FIniFile.FileName;

  S:= SExpandVars(FIniFile.ReadString(section, 'RedirectSection', ''));

  if (S='') or (S='0') then
    Exit;

  if (S='1') then
    Result:= SExpandVars(FIniFile.ReadString('Configuration', 'AlternateUserIni', Result))
  else
    Result:= S;

  if Pos('\', Result)=0 then
    Result:= ExtractFilePath(FIniFile.FileName) + Result;
end;

function GetTcIniKey(const section, key: string): string;
var
  FN: string;
begin
  FN:= ActualFileName(section);
  if FN = FIniFile.FileName then
    Result:= FIniFile.ReadString(section, key, '')
  else
    with TIniFile.Create(FN) do
    try
      Result:= ReadString(section, key, '');
    finally
      Free;
    end;
end;

procedure SetTcIniKey(const section, key: string; const value: string);
var
  FN: string;
begin
  FN:= ActualFileName(section);
  if FN = FIniFile.FileName then
    FIniFile.WriteString(section, key, value)
  else
    with TIniFile.Create(FN) do
    try
      WriteString(section, key, value);
    finally
      Free;
    end;
end;


initialization

finalization
  
  if Assigned(FIniFile) then
    FreeAndNil(FIniFile);

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -