Pārlūkot izejas kodu

* Added GetUSerDir function (ID 11338)

git-svn-id: trunk@11074 -
michael 17 gadi atpakaļ
vecāks
revīzija
26575472b6

+ 26 - 0
rtl/objpas/sysutils/osutil.inc

@@ -121,6 +121,12 @@ begin
   Result:=GetAppConfigFile(Global,False);
 end;
 
+Function DGetUserDir : String;
+
+begin
+  Result:=ExtractFilePath(Paramstr(0));
+end;
+
 
 { ---------------------------------------------------------------------
     Fallback implementations for AppConfigDir implementation.
@@ -146,6 +152,26 @@ begin
 end;
 {$endif}
 
+{ ---------------------------------------------------------------------
+    Fallback implementations for GetUserDir implementation.
+  ---------------------------------------------------------------------}
+{
+ If a particular OS does it different:
+ - set the HAVE_OSUSERDIR define before including sysutils.inc.
+ - implement the function.
+ Default makes it the application directory. Rationale is that the result
+ will be used for config files, and it should exist. The application directory
+ has this for sure.
+}
+
+{$ifndef HAS_OSUSERDIR}
+Function GetUserDir : String;
+
+begin
+  Result:=DGetUserDir;
+end;
+{$endif}
+
 { ---------------------------------------------------------------------
   Get temporary directory name
   ---------------------------------------------------------------------}

+ 1 - 0
rtl/objpas/sysutils/osutilsh.inc

@@ -37,6 +37,7 @@ function GetTempFileName(Dir,Prefix: PChar; uUnique: DWORD; TempFileName: PChar)
 Function GetAppConfigDir(Global : Boolean) : String;
 Function GetAppConfigFile(Global : Boolean) : String;
 Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
+Function GetUserDir : String;
 Function VendorName : String;
 Function ApplicationName : String;
 

+ 23 - 1
rtl/unix/sysutils.pp

@@ -31,6 +31,7 @@ interface
 {$DEFINE HAS_TEMPDIR}
 {$DEFINE HASUNIX}
 {$DEFINE HASCREATEGUID}
+{$DEFINE HAS_OSUSERDIR}
 
 uses
   Unix,errors,sysconst,Unixtype;
@@ -1039,7 +1040,7 @@ end;
 
 
 {****************************************************************************
-                              Initialization code
+                              GetTempDir 
 ****************************************************************************}
 
 
@@ -1060,6 +1061,27 @@ begin
     Result:=IncludeTrailingPathDelimiter(Result);
 end;
 
+{****************************************************************************
+                              GetUserDir 
+****************************************************************************}
+
+Var
+  TheUserDir : String;
+
+Function GetUserDir : String;
+
+begin
+  If (TheUserDir='') then
+    begin
+    TheUserDir:=GetEnvironmentVariable('HOME'); 
+    if (TheUserDir<>'') then
+      TheUserDir:=IncludeTrailingPathDelimiter(TheUserDir)
+    else
+      TheUserDir:=GetTempDir(False);
+    end;
+  Result:=TheUserDir;    
+end;
+
 
 {****************************************************************************
                               Initialization code

+ 7 - 0
rtl/win/sysutils.pp

@@ -27,6 +27,7 @@ uses
 {$DEFINE HAS_SLEEP}
 {$DEFINE HAS_OSERROR}
 {$DEFINE HAS_OSCONFIG}
+{$DEFINE HAS_OSUSERDIR}
 {$DEFINE HAS_CREATEGUID}
 
 { Include platform independent interface part }
@@ -1061,6 +1062,12 @@ begin
   result:=DGetAppConfigFile(Global,SubDir);
 end;
 
+Function GetUserDir : String;
+
+begin
+  Result:=GetSpecialDir(CSIDL_PROFILE);
+end;
+
 Procedure InitSysConfigDir;
 
 begin