added darwin code to get application data path

This commit is contained in:
Basile Burg 2015-07-17 16:30:48 +02:00
parent 4357515016
commit e690b7434e
1 changed files with 11 additions and 18 deletions

View File

@ -132,7 +132,7 @@ type
(** (**
* Returns the user data dir. * Returns the user data dir.
*) *)
function getUserDocPath: string; function getUserDataPath: string;
(** (**
* Returns the documents and settings folder for Coedit. * Returns the documents and settings folder for Coedit.
@ -502,33 +502,26 @@ begin
exit( format('%s%s...%s',[drv,directorySeparator,pth1]) ); exit( format('%s%s...%s',[drv,directorySeparator,pth1]) );
end; end;
function getUserDocPath: string; function getUserDataPath: string;
{$IFDEF WINDOWS}
var
PIDL : PItemIDList;
Folder : array[0..MAX_PATH] of Char;
const
CSIDL_APPDATA = $001A;
{$ENDIF}
begin begin
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
PIDL := nil; result := sysutils.GetEnvironmentVariable('APPDATA');
SHGetSpecialFolderLocation(0, CSIDL_APPDATA, PIDL);
SHGetPathFromIDList(PIDL, Folder);
result := Folder;
{$ENDIF} {$ENDIF}
{$IFDEF UNIX} {$IFDEF LINUX}
result := ExpandFileName('~/'); result := sysutils.GetEnvironmentVariable('HOME');
{$ENDIF} {$ENDIF}
{$IFDEF DARWIN} {$IFDEF DARWIN}
raise Exception.Create('darwin: getUserDocPath() has to be implemented'); result := sysutils.GetEnvironmentVariable('HOME') + '/Library';
{$ENDIF} {$ENDIF}
result += directorySeparator; if not DirectoryExists(result) then
raise Exception.Create('Coedit failed to retrieve the user data folder');
if result[length(result)] <> DirectorySeparator then
result += directorySeparator;
end; end;
function getCoeditDocPath: string; function getCoeditDocPath: string;
begin begin
result := getUserDocPath + 'Coedit' + directorySeparator; result := getUserDataPath + 'Coedit' + directorySeparator;
end; end;
function isFolder(sr: TSearchRec): boolean; function isFolder(sr: TSearchRec): boolean;