Recent

Author Topic: Finding correct preferences folder under Cocoa  (Read 1554 times)

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: Finding correct preferences folder under Cocoa
« Reply #15 on: October 18, 2019, 02:19:01 am »
@trev

Excellent, thanks for those references.

My preference files are cross-platform json. I just need a legal place to save them.
« Last Edit: October 18, 2019, 02:26:15 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: Finding correct preferences folder under Cocoa
« Reply #16 on: November 13, 2019, 05:02:47 pm »
The code for GetSupportDir does not compile, stopping at:

Code: Pascal  [Select]
  1. if Global then   // kLocalDomain
  2.   theError := FSFindFolder(kLocalDomain, FolderType, kDontCreateFolder, theRef)
  3. else             // kUserDomain
  4.   theError := FSFindFolder(kUserDomain , FolderType, kDontCreateFolder, theRef);
  5.  

with error: 'Got "FILES.FSRef" expected "MACOSALL.FSRef"'

Unless I change:
Code: Pascal  [Select]
  1. Uses
  2.   {$IFDEF DARWIN}
  3.   MacOSAll, Files
  4.   {$ENDIF}

to
Code: Pascal  [Select]
  1. Uses
  2.   {$IFDEF DARWIN}
  3.   Files, MacOSAll
  4.   {$ENDIF}

I assume this is ok, but I am not a macOS expert. It seems to work, maybe the wiki should be modified.
« Last Edit: November 13, 2019, 05:07:20 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

VTwin

  • Hero Member
  • *****
  • Posts: 787
  • Former Turbo Pascal 3 user
Re: Finding correct preferences folder under Cocoa
« Reply #17 on: November 13, 2019, 05:35:38 pm »
Not quite. My tests on Mac, Win, and Lin suggest you need something like this:

Code: Pascal  [Select]
  1. { GetSupportDir
  2.   Return path to user application support directory. }
  3. function GetSupportDir: string;
  4. begin
  5.   {$IFDEF DARWIN}
  6.   result := GetSupportDir(false, kApplicationSupportFolderType)
  7.     + ApplicationName + PathDelim;
  8.   {$ELSE}
  9.   result := GetAppConfigDirUTF8(false);
  10.   {$ENDIF}
  11. end;

to get the application support directory. Otherwise the Mac code gives you the 'Application Support' directory, while Win and Lin give the application support directory in that directory.
« Last Edit: November 16, 2019, 03:53:30 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0 (2.0.7) fixes svn 62148 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4