Recent

Author Topic: [solved] GetDesktopPath  (Read 1423 times)

Handoko

  • Hero Member
  • *****
  • Posts: 4314
  • My goal: build my own game engine using Lazarus
[solved] GetDesktopPath
« on: October 20, 2020, 08:00:14 pm »
Can anyone help me test this code on Linuxes and Windows? I tested on Ubuntu Mate and WinXP, it works but I want to make sure it 'really' works. Or maybe you have better suggestion.

Code: Pascal  [Select][+][-]
  1. function GetDesktopPath: string;
  2. var
  3.   S: string;
  4. begin
  5. {$ifdef WINDOWS}
  6.   S := GetEnvironmentVariable('HOMEDRIVE') + GetEnvironmentVariable('HOMEPATH');
  7. {$endif}
  8. {$ifdef LINUX}
  9.   S := GetEnvironmentVariable('HOME');
  10. {$endif}
  11.   Result := S + DirectorySeparator + 'Desktop' + DirectorySeparator;
  12. end;

Note:
SysUtils unit is required.
« Last Edit: October 22, 2020, 07:56:24 pm by Handoko »

ASerge

  • Hero Member
  • *****
  • Posts: 1816
Re: GetDesktopPath
« Reply #1 on: October 20, 2020, 08:14:22 pm »
Can anyone help me test this code on Linuxes and Windows? I tested on Ubuntu Mate and WinXP, it works but I want to make sure it 'really' works. Or maybe you have better suggestion.
Windows 7 - work. But it is more correct to use WinDirs.GetWindowsSpecialDir(CSIDL_DESKTOPDIRECTORY, False);

Lulu

  • Full Member
  • ***
  • Posts: 131
Re: GetDesktopPath
« Reply #2 on: October 20, 2020, 08:35:18 pm »
Tested on win10: both Handoko and ASerge code work
fpc 3.2.0 Lazarus 2.0.10  -  AMD A8-6600K  -  Windows 10  64bits

kapibara

  • Hero Member
  • *****
  • Posts: 533
Re: GetDesktopPath
« Reply #3 on: October 20, 2020, 10:37:44 pm »
Tested OK with XUbuntu 20.04.
Lazarus trunk / fpc 3.0.4 / Debian 10 - 64 bit

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1498
  • Former Delphi 1-7, 10.2 user
Re: GetDesktopPath
« Reply #4 on: October 21, 2020, 01:20:33 am »
Change:

Code: Pascal  [Select][+][-]
  1. {$ifdef LINUX}

To:

Code: Pascal  [Select][+][-]
  1. {$ifdef UNIX}

And it will now also work in macOS and FreeBSD (tested :-)
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.3 r65500 FPC 3.3.1 r49634 macOS 11.5 aarch64 Xcode 12.5.1
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

Handoko

  • Hero Member
  • *****
  • Posts: 4314
  • My goal: build my own game engine using Lazarus
Re: GetDesktopPath
« Reply #5 on: October 22, 2020, 07:56:08 pm »
Thank you all for testing it and the suggestions.

 

TinyPortal © 2005-2018