FIX: ParamStr function for UTF-8 file names under Unix

This commit is contained in:
Alexander Koblov 2013-06-08 11:52:31 +00:00
commit 6d2d1d2877
3 changed files with 38 additions and 10 deletions

View file

@ -171,6 +171,9 @@ procedure FixFormIcon(Handle: LCLType.HWND);
procedure HideConsoleWindow;
procedure FixDateNamesToUTF8;
function ParamStrU(Param: Integer): UTF8String; overload;
function ParamStrU(const Param: String): UTF8String; overload;
implementation
uses
@ -932,6 +935,31 @@ begin
end;
end;
function ParamStrU(Param: Integer): UTF8String;
{$IFDEF UNIX}
begin
Result:= SysToUTF8(ObjPas.ParamStr(Param));
end;
{$ELSE}
begin
if (Param >= 0) and (Param < argc) then
Result:= StrPas(argv[Param])
else
Result:= EmptyStr;
end;
{$ENDIF}
function ParamStrU(const Param: String): UTF8String;
{$IFDEF UNIX}
begin
Result:= SysToUTF8(Param);
end;
{$ELSE}
begin
Result:= Param;
end;
{$ENDIF}
{ EInvalidQuoting }
constructor EInvalidQuoting.Create;

View file

@ -1 +1 @@
unit uGlobsPaths; interface var gpExePath : String = ''; // executable directory gpCfgDir : String = ''; // directory from which configuration files are used gpGlobalCfgDir : String = ''; // config dir global for all user gpCmdLineCfgDir : String = ''; // config dir passed on the command line gpLngDir : String = ''; // path to language *.po files gpPixmapPath : String = ''; // path to pixmaps gpCacheDir : UTF8String = ''; // cache directory procedure LoadPaths; implementation uses SysUtils, FileUtil, uDebug, uOSUtils, DCOSUtils, DCStrUtils; function GetAppName : String; begin Result := 'doublecmd'; end; procedure LoadPaths; begin OnGetApplicationName := @GetAppName; gpExePath := ExtractFilePath(TryReadAllLinks(ParamStr(0))); DCDebug('Executable directory: ', gpExePath); gpGlobalCfgDir := gpExePath; if gpCmdLineCfgDir <> EmptyStr then begin if GetPathType(gpCmdLineCfgDir) <> ptAbsolute then gpCmdLineCfgDir := IncludeTrailingPathDelimiter(mbGetCurrentDir) + gpCmdLineCfgDir; gpCmdLineCfgDir := ExpandAbsolutePath(gpCmdLineCfgDir); gpCfgDir := gpCmdLineCfgDir; end else begin gpCfgDir := GetAppConfigDir; if gpCfgDir = EmptyStr then begin DCDebug('Warning: Cannot get user config directory.'); gpCfgDir := gpGlobalCfgDir; end; end; gpCfgDir := IncludeTrailingPathDelimiter(gpCfgDir); gpLngDir := gpExePath + 'language' + DirectorySeparator; gpPixmapPath := gpExePath + 'pixmaps' + DirectorySeparator; gpCacheDir := GetAppCacheDir; // set up environment variables mbSetEnvironmentVariable('COMMANDER_INI', gpCfgDir + 'doublecmd.xml'); mbSetEnvironmentVariable('COMMANDER_DRIVE', ExtractRootDir(gpExePath)); mbSetEnvironmentVariable('COMMANDER_PATH', ExcludeTrailingBackslash(gpExePath)); end; end.
unit uGlobsPaths; interface var gpExePath : String = ''; // executable directory gpCfgDir : String = ''; // directory from which configuration files are used gpGlobalCfgDir : String = ''; // config dir global for all user gpCmdLineCfgDir : String = ''; // config dir passed on the command line gpLngDir : String = ''; // path to language *.po files gpPixmapPath : String = ''; // path to pixmaps gpCacheDir : UTF8String = ''; // cache directory procedure LoadPaths; implementation uses SysUtils, FileUtil, uDebug, uOSUtils, DCOSUtils, DCStrUtils; function GetAppName : String; begin Result := 'doublecmd'; end; procedure LoadPaths; begin OnGetApplicationName := @GetAppName; gpExePath := ExtractFilePath(TryReadAllLinks(ParamStrU(0))); DCDebug('Executable directory: ', gpExePath); gpGlobalCfgDir := gpExePath; if gpCmdLineCfgDir <> EmptyStr then begin if GetPathType(gpCmdLineCfgDir) <> ptAbsolute then gpCmdLineCfgDir := IncludeTrailingPathDelimiter(mbGetCurrentDir) + gpCmdLineCfgDir; gpCmdLineCfgDir := ExpandAbsolutePath(gpCmdLineCfgDir); gpCfgDir := gpCmdLineCfgDir; end else begin gpCfgDir := GetAppConfigDir; if gpCfgDir = EmptyStr then begin DCDebug('Warning: Cannot get user config directory.'); gpCfgDir := gpGlobalCfgDir; end; end; gpCfgDir := IncludeTrailingPathDelimiter(gpCfgDir); gpLngDir := gpExePath + 'language' + DirectorySeparator; gpPixmapPath := gpExePath + 'pixmaps' + DirectorySeparator; gpCacheDir := GetAppCacheDir; // set up environment variables mbSetEnvironmentVariable('COMMANDER_INI', gpCfgDir + 'doublecmd.xml'); mbSetEnvironmentVariable('COMMANDER_DRIVE', ExtractRootDir(gpExePath)); mbSetEnvironmentVariable('COMMANDER_PATH', ExcludeTrailingBackslash(gpExePath)); end; end.

View file

@ -23,7 +23,7 @@ uses
{$IF DEFINED(NIGHTLY_BUILD)}
uOSUtils,
{$ENDIF}
Forms, Dialogs, SysUtils, uDCUtils, uGlobsPaths, FileUtil, getopts, uDebug, uLng;
Forms, Dialogs, SysUtils, uDCUtils, uGlobsPaths, getopts, uDebug, uLng;
procedure ProcessCommandLineParams;
var
@ -66,12 +66,12 @@ begin
end;
2:
begin
gpCmdLineCfgDir:= TrimQuotes(OptArg);
gpCmdLineCfgDir:= ParamStrU(TrimQuotes(OptArg));
end;
end;
end;
'L', 'l': CommandLineParams.LeftPath:= TrimQuotes(OptArg);
'R', 'r': CommandLineParams.RightPath:= TrimQuotes(OptArg);
'L', 'l': CommandLineParams.LeftPath:= ParamStrU(TrimQuotes(OptArg));
'R', 'r': CommandLineParams.RightPath:= ParamStrU(TrimQuotes(OptArg));
'P', 'p': CommandLineParams.ActiveRight:= (UpperCase(OptArg) = 'R');
'T', 't': CommandLineParams.NewTab:= True;
'?', ':': DCDebug ('Error with opt : ', OptOpt);
@ -84,16 +84,16 @@ begin
if ParamCount - OptInd = 0 then
begin
if CommandLineParams.ActiveRight then
CommandLineParams.RightPath:= ParamStr(OptInd)
CommandLineParams.RightPath:= ParamStrU(OptInd)
else
CommandLineParams.LeftPath:= ParamStr(OptInd);
CommandLineParams.LeftPath:= ParamStrU(OptInd);
Inc(OptInd, 1);
end
// If also found two parameters then use it as paths in panels
else if ParamCount - OptInd = 1 then
begin
CommandLineParams.LeftPath:= ParamStr(OptInd);
CommandLineParams.RightPath:= ParamStr(OptInd + 1);
CommandLineParams.LeftPath:= ParamStrU(OptInd);
CommandLineParams.RightPath:= ParamStrU(OptInd + 1);
Inc(OptInd, 2);
end;
// Unknown options, print to console
@ -101,7 +101,7 @@ begin
begin
while OptInd <= ParamCount do
begin
OptionUnknown:= ParamStr(OptInd) + ' ';
OptionUnknown:= ParamStrU(OptInd) + ' ';
Inc(OptInd)
end;
DCDebug ('Non options : ', OptionUnknown);