Lazarus
Programming => Operating Systems => macOS / Mac OS X => Topic started by: Hansaplast on May 12, 2016, 01:50:15 pm
-
This is not the first time this topic is discussed, but as a Mac user, something I'd like to fix.
The problem:
Both GetAppConfigDir and GetAppConfigFile return an inappropriate result for Mac OS X (per Apple guidelines).
jwdietrich posted a way to work around this in this post (http://forum.lazarus.freepascal.org/index.php?topic=17421.0).
I just modified this a little bit ...
function GetPreferencesFolder(Global:boolean): String;
{ platform-independend method to search for the location of preferences folder}
const
kMaxPath = 1024;
var
{$IFDEF LCLCarbon}
theError: OSErr;
theRef: FSRef;
{$ENDIF}
pathBuffer: PChar;
begin
{$IFDEF LCLCarbon}
try
pathBuffer := Allocmem(kMaxPath);
except on exception do exit;
end;
try
Fillchar(pathBuffer^, kMaxPath, #0);
Fillchar(theRef, Sizeof(theRef), #0);
if Global then // kLocalDomain
theError := FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kDontCreateFolder, theRef)
else
theError := FSFindFolder(kUserDomain , kApplicationSupportFolderType, kDontCreateFolder, theRef);
if (pathBuffer <> nil) and (theError = noErr) then
begin
theError := FSRefMakePath(theRef, pathBuffer, kMaxPath);
if theError = noErr then GetPreferencesFolder := UTF8ToAnsi(StrPas(pathBuffer)) + '/';
end;
finally
Freemem(pathBuffer);
end
{$ELSE}
GetPreferencesFolder := GetAppConfigDir(false);
{$ENDIF}
{
User preferences live in the location returned by FSFindFolder(kUserDomain,kPreferencesFolderType).
User application support items live in the location returned by FSFindFolder(kUserDomain, kApplicationSupportFolderType).
Global preferences live in the location returned by FSFindFolder(kLocalDomain,kPreferencesFolderType).
Global application support items live in the location returned by FSFindFolder(kLocalDomain, kApplicationSupportFolderType).
}
end;
Since GetAppConfigDir/File does not distinguishes between "Preferences" and "Application Data", I picked "Application Data". One can argue this might not be the 100% correct solution, but at least it better than the current "~/.config" location, and one could even store INI files there (instead of properly using XML in "Preferences").
So I went look for the functions GetAppConfigDir and GetAppConfigFile (sysutils), to see if I can incorporate this code, but I cannot edit these files. Probably because they are part of FPC?
I'd love to help out and create a patch to address this issue. Would anyone be able to assist?
-
Hi
Thanks for your proposal in the bug tracker (http://bugs.freepascal.org/view.php?id=20706).
You have a page (http://wiki.lazarus.freepascal.org/Creating_A_Patch) in the wiki to make a patch. The problem is that you must use the svn fpc and lazarus version, and this is not possible for me.
I just think you should remove the UTF8ToAnsi, and Use DirectorySeparator instead of the constant '/' , but it is a detail.
But in which unit is now the OSErr type ? I had it in previous versions of Lazarus, but no more in 1.6 ? I Can't find it anywhere.
Thanks
-
Good point (DirectorySeparator and removing UTF8ToAnsi).
OSErr is defined in "MacOSAll" I believe. :-)