Explorar el Código

Merged revisions 10068,10072,10082,10104,10111 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r10068 | peter | 2008-01-27 20:55:05 +0100 (Sun, 27 Jan 2008) | 2 lines

* global appconfig dir needs to be common_appdata directory
........
r10072 | peter | 2008-01-27 22:40:55 +0100 (Sun, 27 Jan 2008) | 5 lines

* 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
........
r10104 | peter | 2008-01-29 23:14:53 +0100 (Tue, 29 Jan 2008) | 3 lines

* made forcedirectories consistent with other file handling
to accept both / and \ as spearators
........
r10111 | peter | 2008-01-30 01:15:22 +0100 (Wed, 30 Jan 2008) | 2 lines

* quote parameters with spaces
........

git-svn-id: branches/fixes_2_2@10129 -

peter hace 17 años
padre
commit
7321468f75

+ 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;

+ 4 - 4
rtl/objpas/sysutils/sysutils.inc

@@ -40,7 +40,7 @@
             Result:=Temp;
             Temp:='';
           end;
-        If (Length(Result)>0) and (result[length(result)]<>DirectorySeparator) then
+        If (Length(Result)>0) and (result[length(result)] in AllowDirectorySeparators) then
           Result:=Result+DirectorySeparator;
         Result:=Result+name;
         If not FileExists(Result) Then
@@ -551,7 +551,7 @@ begin
       E.ErrorCode:=3;
       Raise E;
     end;
-  Result := DoForceDirectories(Dir);
+  Result := DoForceDirectories(SetDirSeparators(Dir));
 end;
 
 Procedure GetRandomBytes(Var Buf; NBytes : Integer);
@@ -632,7 +632,7 @@ begin
 {$ifdef MSWINDOWS}
   SetLength(Result,MAX_PATH);
   SetLength(Result,GetModuleFileName(Module, Pchar(Result),Length(Result)));
-{$ELSE}  
+{$ELSE}
   Result:='';
-{$ENDIF}  
+{$ENDIF}
 end;

+ 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
 ****************************************************************************}

+ 22 - 29
rtl/win/sysutils.pp

@@ -866,16 +866,19 @@ end;
 
 function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
 
-Var
-  CommandLine : AnsiString;
-  i : Integer;
+var
+  CommandLine: AnsiString;
+  I: integer;
 
-Begin
-  Commandline:='';
-  For i:=0 to high(ComLine) Do
-   Commandline:=CommandLine+' '+Comline[i];
-  ExecuteProcess:=ExecuteProcess(Path,CommandLine);
-End;
+begin
+  Commandline := '';
+  for I := 0 to High (ComLine) do
+   if Pos (' ', ComLine [I]) <> 0 then
+    CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
+   else
+    CommandLine := CommandLine + ' ' + Comline [I];
+  ExecuteProcess := ExecuteProcess (Path, CommandLine);
+end;
 
 Procedure Sleep(Milliseconds : Cardinal);
 
@@ -1037,35 +1040,25 @@ begin
 end;
 
 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_LOCAL_APPDATA);
+  If (Result<>'') then
     begin
-    Result:=GetSpecialDir(CSIDL_LOCAL_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;
 
 Procedure InitSysConfigDir;

+ 25 - 30
rtl/wince/sysutils.pp

@@ -35,7 +35,7 @@ uses
 
 type
   TSystemTime = Windows.TSystemTime;
-  
+
   EWinCEError = class(Exception)
   public
     ErrorCode : DWORD;
@@ -676,16 +676,20 @@ end;
 
 function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
 
-Var
-  CommandLine : AnsiString;
-  i : Integer;
+var
+  CommandLine: AnsiString;
+  I: integer;
+
+begin
+  Commandline := '';
+  for I := 0 to High (ComLine) do
+   if Pos (' ', ComLine [I]) <> 0 then
+    CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
+   else
+    CommandLine := CommandLine + ' ' + Comline [I];
+  ExecuteProcess := ExecuteProcess (Path, CommandLine);
+end;
 
-Begin
-  Commandline:='';
-  For i:=0 to high(ComLine) Do
-   Commandline:=CommandLine+' '+Comline[i];
-  ExecuteProcess:=ExecuteProcess(Path,CommandLine);
-End;
 
 Procedure Sleep(Milliseconds : Cardinal);
 
@@ -738,32 +742,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 +934,7 @@ procedure InitWinCEWidestrings;
   begin
     widestringmanager.CompareWideStringProc:=@WinCECompareWideString;
     widestringmanager.CompareTextWideStringProc:=@WinCECompareTextWideString;
-    
+
     widestringmanager.UpperAnsiStringProc:=@WinCEAnsiUpperCase;
     widestringmanager.LowerAnsiStringProc:=@WinCEAnsiLowerCase;
     widestringmanager.CompareStrAnsiStringProc:=@WinCEAnsiCompareStr;