Files
ewsdr/PlatformUtils.pas
T
ew8bakandClaude Sonnet 4.6 e9f4bf1732 fix Windows config dir: use %APPDATA% env var directly
FPC's GetAppConfigDir on Windows falls back to the exe directory
if the shell API call fails, which breaks installs in Program Files.
Read %APPDATA% from the environment variable instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 17:03:14 +03:00

86 lines
1.9 KiB
ObjectPascal

unit PlatformUtils;
{
PlatformUtils.pas - small helpers for desktop/runtime platform checks.
}
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
function QtPlatformAllowsOpenGLControls: Boolean;
function HasOpenGLSpectrumSwitch: Boolean;
function CurrentScreenDPI: Integer;
// Возвращает каталог для хранения конфигурации (с завершающим разделителем).
// macOS: ~/Library/Application Support/ewsdr/
// Linux: ~/.config/ewsdr/
// Windows: %APPDATA%\ewsdr\
function GetAppCfgDir: string;
implementation
uses
SysUtils, Forms;
function QtPlatformAllowsOpenGLControls: Boolean;
var
Qpa, FirstQpa, SessionType: string;
Sep: Integer;
begin
Result := True;
Qpa := LowerCase(Trim(GetEnvironmentVariable('QT_QPA_PLATFORM')));
SessionType := LowerCase(Trim(GetEnvironmentVariable('XDG_SESSION_TYPE')));
if Qpa <> '' then
begin
FirstQpa := Qpa;
Sep := Pos(';', FirstQpa);
if Sep > 0 then
FirstQpa := Copy(FirstQpa, 1, Sep - 1);
Result := FirstQpa <> 'wayland';
Exit;
end;
Result := SessionType <> 'wayland';
end;
function HasOpenGLSpectrumSwitch: Boolean;
var
I: Integer;
S: string;
begin
Result := False;
for I := 1 to ParamCount do
begin
S := LowerCase(ParamStr(I));
if (S = '--opengl') or (S = '-opengl') or (S = '/opengl') then
Exit(True);
end;
end;
function CurrentScreenDPI: Integer;
begin
Result := Screen.PixelsPerInch;
if Result <= 0 then Result := 96;
end;
function GetAppCfgDir: string;
begin
{$IFDEF WINDOWS}
Result := GetEnvironmentVariable('APPDATA');
if Result = '' then
Result := GetEnvironmentVariable('LOCALAPPDATA');
if Result = '' then
Result := ExtractFilePath(ParamStr(0));
Result := IncludeTrailingPathDelimiter(Result) + 'ewsdr' + PathDelim;
{$ELSE}
Result := IncludeTrailingPathDelimiter(GetAppConfigDir(False));
{$ENDIF}
if not DirectoryExists(Result) then
ForceDirectories(Result);
end;
end.