From: DeaDDooMER Date: Mon, 22 Oct 2018 20:04:46 +0000 (+0300) Subject: Supported non ascii system user names X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=ded89321df07e3f5832331127637375840c25e6f;p=d2df-sdl.git Supported non ascii system user names --- diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 506fc18..cc9a714 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -148,8 +148,12 @@ uses 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; @@ -966,6 +970,9 @@ begin 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 3774eab..5c60fd0 100644 --- a/src/shared/envvars.pas +++ b/src/shared/envvars.pas @@ -26,8 +26,14 @@ interface 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 @@ -47,15 +53,25 @@ begin 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.