summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2f2f9c9)
raw | patch | inline | side by side (parent: 2f2f9c9)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 22 Oct 2018 20:04:46 +0000 (23:04 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 22 Oct 2018 20:04:46 +0000 (23:04 +0300) |
src/game/g_options.pas | patch | blob | history | |
src/shared/envvars.pas | patch | blob | history |
diff --git a/src/game/g_options.pas b/src/game/g_options.pas
index 506fc186424753429b21151925830bb1a0b6376d..cc9a71400bc4a4a7cf159a0392e171f0c8c4cae8 100644 (file)
--- a/src/game/g_options.pas
+++ b/src/game/g_options.pas
begin
ASSERT(n >= 1);
Result := GetUserName;
- if Result = '' then Result := 'Player' + IntToStr(machine MOD 10000);
- if n > 1 then Result := Copy(Result, 1, 10) + (' ' + IntToStr(n))
+ if Result = '' then
+ Result := 'Player' + IntToStr(machine MOD 10000);
+ if n = 1 then
+ Result := Copy(Result, 1, 12) + ' '
+ else
+ Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
end;
procedure g_Options_SetDefaultVideo;
config.WriteBool('Video', 'Fullscreen', gFullscreen);
config.WriteBool('Video', 'Maximized', gWinMaximized);
+ config.WriteStr('Player1', 'Name', gPlayer1Settings.Name);
+ config.WriteStr('Player2', 'Name', gPlayer2Settings.Name);
+
config.SaveFile(FileName);
config.Free();
end;
diff --git a/src/shared/envvars.pas b/src/shared/envvars.pas
index 3774eab2fe277edbd168c160de436c954d3c5007..5c60fd0d7c1adefe3508ebaf7f5d3cc948512820 100644 (file)
--- a/src/shared/envvars.pas
+++ b/src/shared/envvars.pas
implementation
+ uses
+{$IFDEF WINDOWS}
+ Windows,
+{$ENDIF}
+ utils;
+
+
{$IFDEF WINDOWS}
-uses Windows;
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;
- function GetUserName: String;
+ (* Get system username already in cp1251 *)
+ function GetUserName: AnsiString;
+ var i: Integer;
begin
{$IF DEFINED(WINDOWS)}
- Result := SysUtils.GetEnvironmentVariable('USERNAME')
+ Result := utf2win(UTF8String(SysUtils.GetEnvironmentVariable(WideString('USERNAME'))));
{$ELSEIF DEFINED(UNIX)}
- Result := SysUtils.GetEnvironmentVariable('USER')
+ Result := utf2win(SysUtils.GetEnvironmentVariable('USER'));
{$ELSE}
- Result := ''
+ Result := '';
{$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.