Browse Source

* VendorName function added to allow an extra subdirectory
to group multiple products
* OnGetVendorName hook, like OnGetApplicationName
* use COMMON_APPPATH for global config files under windows

git-svn-id: trunk@10072 -

peter 17 năm trước cách đây
mục cha
commit
95d0ce1270

+ 12 - 3
rtl/objpas/sysutils/osutil.inc

@@ -78,6 +78,15 @@ end;
     Application name
   ---------------------------------------------------------------------}
 
+Function VendorName : String;
+
+begin
+  If Assigned(OnGetVendorName) then
+    Result:=OnGetVendorName()
+  else
+    Result:='';
+end;
+
 Function ApplicationName : String;
 
 begin
@@ -100,9 +109,9 @@ end;
 Function DGetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
 
 begin
-  Result:=ExtractFilePath(ParamStr(0));
-  If SubDir then
-    Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
+  Result:=IncludeTrailingPathDelimiter(GetAppConfigDir(Global));
+  if SubDir then
+    Result:=IncludeTrailingPathDelimiter(Result+'Config');
   Result:=Result+ApplicationName+ConfigExtension;
 end;
 

+ 3 - 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 VendorName : String;
 Function ApplicationName : String;
 
 Const
@@ -44,11 +45,13 @@ Const
   SysConfigDir    : String = '';
 
 Type
+  TGetVendorNameEvent  = Function : String;
   TGetAppNameEvent  = Function : String;
   TGetTempDirEvent  = Function (Global : Boolean) : String;
   TGetTempFileEvent = Function (Const Dir,Prefix : String) : String;
 
 Var
+  OnGetVendorName      : TGetVendorNameEvent;
   OnGetApplicationName : TGetAppNameEvent;
   OnGetTempDir         : TGetTempDirEvent;
   OnGetTempFile        : TGetTempFileEvent;

+ 13 - 17
rtl/unix/sysutils.pp

@@ -1009,33 +1009,29 @@ begin
   If Global then
     Result:=SysConfigDir
   else
-    Result:=XdgConfigHome + ApplicationName;
+    Result:=XdgConfigHome;
+  if VendorName<>'' then
+    Result:=IncludeTrailingPathDelimiter(Result+VendorName);
+  Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
 end;
 
 Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
 
 begin
-  if Global then
-    begin
-    Result:=IncludeTrailingPathDelimiter(SysConfigDir);
-    if SubDir then
-      Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
-    Result:=Result+ApplicationName+ConfigExtension;
-    end
+  If Global then
+    Result:=SysConfigDir
   else
+    Result:=XdgConfigHome;
+  if SubDir then
     begin
-    if SubDir then
-      begin
-      Result:=IncludeTrailingPathDelimiter(GetAppConfigDir(False));
-      Result:=Result+ApplicationName+ConfigExtension;
-      end
-    else
-      begin
-      Result:=XdgConfigHome + ApplicationName + ConfigExtension;
-      end;
+      if VendorName<>'' then
+        Result:=IncludeTrailingPathDelimiter(Result+VendorName);
+      Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
     end;
+  Result:=Result+ApplicationName+ConfigExtension;
 end;
 
+
 {****************************************************************************
                               Initialization code
 ****************************************************************************}

+ 10 - 8
rtl/win/sysutils.pp

@@ -1037,23 +1037,25 @@ begin
 end;
 
 Function GetAppConfigDir(Global : Boolean) : String;
-
 begin
   If Global then
-    Result:=GetSpecialDir(CSIDL_COMMON_APPDATA)+ApplicationName
+    Result:=GetSpecialDir(CSIDL_COMMON_APPDATA)
+  else
+    Result:=GetSpecialDir(CSIDL_LOCAL_APPDATA);
+  If (Result<>'') then
+    begin
+      if VendorName<>'' then
+        Result:=IncludeTrailingPathDelimiter(Result+VendorName);
+      Result:=Result+ApplicationName;
+    end
   else
-    Result:=GetSpecialDir(CSIDL_LOCAL_APPDATA)+ApplicationName;
-  If (Result='') then
     Result:=DGetAppConfigDir(Global);
 end;
 
 Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
 
 begin
-  Result:=IncludeTrailingPathDelimiter(GetAppConfigDir(Global));
-  if SubDir then
-    Result:=IncludeTrailingPathDelimiter(Result+'Config');
-  Result:=Result+ApplicationName+ConfigExtension;
+  result:=DGetAppConfigFile(Global,SubDir);
 end;
 
 Procedure InitSysConfigDir;

+ 12 - 21
rtl/wince/sysutils.pp

@@ -35,7 +35,7 @@ uses
 
 type
   TSystemTime = Windows.TSystemTime;
-  
+
   EWinCEError = class(Exception)
   public
     ErrorCode : DWORD;
@@ -738,32 +738,23 @@ Function GetAppConfigDir(Global : Boolean) : String;
 
 begin
   If Global then
-    Result:=DGetAppConfigDir(Global) // or use windows dir ??
+    Result:=GetSpecialDir(CSIDL_COMMON_APPDATA)
   else
+    Result:=GetSpecialDir(CSIDL_APPDATA);
+  If (Result<>'') then
     begin
-    Result:=GetSpecialDir(CSIDL_APPDATA)+ApplicationName;
-    If (Result='') then
-      Result:=DGetAppConfigDir(Global);
-    end;
+      if VendorName<>'' then
+        Result:=IncludeTrailingPathDelimiter(Result+VendorName);
+      Result:=Result+ApplicationName;
+    end
+  else
+    Result:=DGetAppConfigDir(Global);
 end;
 
 Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
 
 begin
-  if Global then
-    begin
-    Result:=IncludeTrailingPathDelimiter(DGetAppConfigDir(Global));
-    if SubDir then
-      Result:=IncludeTrailingPathDelimiter(Result+'Config');
-    Result:=Result+ApplicationName+ConfigExtension;
-    end
-  else
-    begin
-    Result:=IncludeTrailingPathDelimiter(GetAppConfigDir(False));
-    if SubDir then
-      Result:=Result+'Config\';
-    Result:=Result+ApplicationName+ConfigExtension;
-    end;
+  result:=DGetAppConfigFile(Global,SubDir);
 end;
 
 Function GetTempDir(Global : Boolean) : String;
@@ -939,7 +930,7 @@ procedure InitWinCEWidestrings;
   begin
     widestringmanager.CompareWideStringProc:=@WinCECompareWideString;
     widestringmanager.CompareTextWideStringProc:=@WinCECompareTextWideString;
-    
+
     widestringmanager.UpperAnsiStringProc:=@WinCEAnsiUpperCase;
     widestringmanager.LowerAnsiStringProc:=@WinCEAnsiLowerCase;
     widestringmanager.CompareStrAnsiStringProc:=@WinCEAnsiCompareStr;