mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 12:46:11 +02:00
* android: Fixed GetAppConfigDir, GetAppConfigFile, GetUserDir, GetTempDir to return correct writable locations. For NDK libraries, the path to local storage of host Java app is used. For console apps the /data/local/tmp is used.
git-svn-id: trunk@34351 -
This commit is contained in:
parent
aa85f515e2
commit
3822515bd9
@ -1424,9 +1424,51 @@ end;
|
|||||||
Application config files
|
Application config files
|
||||||
---------------------------------------------------------------------}
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
|
{$ifdef android}
|
||||||
|
|
||||||
|
var
|
||||||
|
_HomeDir: string;
|
||||||
|
IsNDKLib: boolean;
|
||||||
|
|
||||||
Function GetHomeDir : String;
|
Function GetHomeDir : String;
|
||||||
|
var
|
||||||
|
h: longint;
|
||||||
|
i: longint;
|
||||||
|
begin
|
||||||
|
Result:=_HomeDir;
|
||||||
|
if Result <> '' then
|
||||||
|
exit;
|
||||||
|
if IsLibrary then
|
||||||
|
begin
|
||||||
|
// For shared library get the package name of a host Java application
|
||||||
|
h:=FileOpen('/proc/self/cmdline', fmOpenRead or fmShareDenyNone);
|
||||||
|
if h >= 0 then
|
||||||
|
begin
|
||||||
|
SetLength(Result, MAX_PATH);
|
||||||
|
SetLength(Result, FileRead(h, Result[1], Length(Result)));
|
||||||
|
SetLength(Result, strlen(PChar(Result)));
|
||||||
|
FileClose(h);
|
||||||
|
Result:='/data/data/' + Result;
|
||||||
|
IsNDKLib:=DirectoryExists(Result);
|
||||||
|
if IsNDKLib then
|
||||||
|
Result:=Result + '/files/'
|
||||||
|
else
|
||||||
|
Result:=''; // No package
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if Result = '' then
|
||||||
|
Result:='/data/local/tmp/';
|
||||||
|
_HomeDir:=Result;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function XdgConfigHome : String;
|
||||||
|
begin
|
||||||
|
Result:=GetHomeDir;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$else}
|
||||||
|
|
||||||
|
Function GetHomeDir : String;
|
||||||
begin
|
begin
|
||||||
Result:=GetEnvironmentVariable('HOME');
|
Result:=GetEnvironmentVariable('HOME');
|
||||||
If (Result<>'') then
|
If (Result<>'') then
|
||||||
@ -1445,6 +1487,8 @@ begin
|
|||||||
Result:=IncludeTrailingPathDelimiter(Result);
|
Result:=IncludeTrailingPathDelimiter(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$endif android}
|
||||||
|
|
||||||
Function GetAppConfigDir(Global : Boolean) : String;
|
Function GetAppConfigDir(Global : Boolean) : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -1452,6 +1496,10 @@ begin
|
|||||||
Result:=IncludeTrailingPathDelimiter(SysConfigDir)
|
Result:=IncludeTrailingPathDelimiter(SysConfigDir)
|
||||||
else
|
else
|
||||||
Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
|
Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
|
||||||
|
{$ifdef android}
|
||||||
|
if IsNDKLib then
|
||||||
|
exit;
|
||||||
|
{$endif android}
|
||||||
if VendorName<>'' then
|
if VendorName<>'' then
|
||||||
Result:=IncludeTrailingPathDelimiter(Result+VendorName);
|
Result:=IncludeTrailingPathDelimiter(Result+VendorName);
|
||||||
Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
|
Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
|
||||||
@ -1464,6 +1512,13 @@ begin
|
|||||||
Result:=IncludeTrailingPathDelimiter(SysConfigDir)
|
Result:=IncludeTrailingPathDelimiter(SysConfigDir)
|
||||||
else
|
else
|
||||||
Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
|
Result:=IncludeTrailingPathDelimiter(XdgConfigHome);
|
||||||
|
{$ifdef android}
|
||||||
|
if IsNDKLib then
|
||||||
|
begin
|
||||||
|
Result:=Result+'config'+ConfigExtension;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
{$endif android}
|
||||||
if SubDir then
|
if SubDir then
|
||||||
begin
|
begin
|
||||||
if VendorName<>'' then
|
if VendorName<>'' then
|
||||||
@ -1486,20 +1541,18 @@ begin
|
|||||||
Result:=OnGetTempDir(Global)
|
Result:=OnGetTempDir(Global)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Result:=GetEnvironmentVariable('TEMP');
|
{$ifdef android}
|
||||||
If (Result='') Then
|
Result:=GetHomeDir + 'tmp';
|
||||||
Result:=GetEnvironmentVariable('TMP');
|
ForceDirectories(Result);
|
||||||
If (Result='') Then
|
{$else}
|
||||||
Result:=GetEnvironmentVariable('TMPDIR');
|
Result:=GetEnvironmentVariable('TEMP');
|
||||||
if (Result='') then
|
If (Result='') Then
|
||||||
begin
|
Result:=GetEnvironmentVariable('TMP');
|
||||||
// fallback.
|
If (Result='') Then
|
||||||
{$ifdef android}
|
Result:=GetEnvironmentVariable('TMPDIR');
|
||||||
Result:='/data/local/tmp/';
|
if (Result='') then
|
||||||
{$else}
|
Result:='/tmp/'; // fallback.
|
||||||
Result:='/tmp/';
|
{$endif android}
|
||||||
{$endif android}
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
if (Result<>'') then
|
if (Result<>'') then
|
||||||
Result:=IncludeTrailingPathDelimiter(Result);
|
Result:=IncludeTrailingPathDelimiter(Result);
|
||||||
@ -1517,7 +1570,11 @@ Function GetUserDir : String;
|
|||||||
begin
|
begin
|
||||||
If (TheUserDir='') then
|
If (TheUserDir='') then
|
||||||
begin
|
begin
|
||||||
TheUserDir:=GetEnvironmentVariable('HOME');
|
{$ifdef android}
|
||||||
|
TheUserDir:=GetHomeDir;
|
||||||
|
{$else}
|
||||||
|
TheUserDir:=GetEnvironmentVariable('HOME');
|
||||||
|
{$endif android}
|
||||||
if (TheUserDir<>'') then
|
if (TheUserDir<>'') then
|
||||||
TheUserDir:=IncludeTrailingPathDelimiter(TheUserDir)
|
TheUserDir:=IncludeTrailingPathDelimiter(TheUserDir)
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user