diff --git a/src/shared/envvars.pas b/src/shared/envvars.pas
index 3774eab2fe277edbd168c160de436c954d3c5007..a76315f42d40f9ddfc84f2d8ecead137bcd2cd2d 100644 (file)
--- a/src/shared/envvars.pas
+++ b/src/shared/envvars.pas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
implementation
implementation
+ uses
+{$IFDEF WINDOWS}
+ Windows,
+{$ENDIF}
+ utils;
+
+
{$IFDEF WINDOWS}
{$IFDEF WINDOWS}
-uses Windows;
function setenv(const VarStr: PChar; const VarVal: PChar; Repl: cint): cint;
begin
if (SetEnvironmentVariable(VarStr, VarVal)) then
function setenv(const VarStr: PChar; const VarVal: PChar; Repl: cint): cint;
begin
if (SetEnvironmentVariable(VarStr, VarVal)) then
Result := (setenv(PChar(VarName), PChar(VarVal), 1) = 0);
end;
Result := (setenv(PChar(VarName), PChar(VarVal), 1) = 0);
end;
- function GetUserName: String;
+ (* Get system username already in cp1251 *)
+ function GetUserName: AnsiString;
+ var i: Integer;
begin
{$IF DEFINED(WINDOWS)}
begin
{$IF DEFINED(WINDOWS)}
- Result := SysUtils.GetEnvironmentVariable('USERNAME')
+ Result := utf2win(UTF8String(SysUtils.GetEnvironmentVariable(WideString('USERNAME'))));
{$ELSEIF DEFINED(UNIX)}
{$ELSEIF DEFINED(UNIX)}
- Result := SysUtils.GetEnvironmentVariable('USER')
+ Result := utf2win(SysUtils.GetEnvironmentVariable('USER'));
{$ELSE}
{$ELSE}
- Result := ''
+ Result := '';
{$ENDIF}
{$ENDIF}
+ (* invalidate username with non-cp1251 symbols *)
+ i := Low(Result);
+ while i <= High(Result) do
+ begin
+ if Result[i] = '?' then
+ Result := '';
+ Inc(i)
+ end
end;
end.
end;
end.