From c80c97739c1e29cbbe64c2459e8558300ac654fc Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 27 Jan 2008 22:17:33 +0000 Subject: [PATCH] * rename Packages dir to Archives dir * use local configuration dirs and files git-svn-id: trunk@10075 - --- utils/fppkg/fppkg.pp | 13 ++------ utils/fppkg/pkgglobals.pp | 69 ++++++++++++++++++++++++++++++++++++++- utils/fppkg/pkghandler.pp | 2 +- utils/fppkg/pkgoptions.pp | 41 ++++++++++++----------- 4 files changed, 93 insertions(+), 32 deletions(-) diff --git a/utils/fppkg/fppkg.pp b/utils/fppkg/fppkg.pp index 992f322c31..056b76d9ea 100644 --- a/utils/fppkg/fppkg.pp +++ b/utils/fppkg/fppkg.pp @@ -47,20 +47,11 @@ Type { TMakeTool } function TMakeTool.GetConfigFileName: String; -var - G : Boolean; begin if HasOption('C','config-file') then Result:=GetOptionValue('C','config-file') else - begin -{$ifdef unix} - g:=(fpgetuid=0); -{$else} - g:=true; -{$endif} - Result:=GetAppConfigFile(G,False); - end + Result:=GetAppConfigFile(IsSuperUser,False); end; @@ -105,7 +96,7 @@ end; procedure TMakeTool.MaybeCreateLocalDirs; begin ForceDirectories(GlobalOptions.BuildDir); - ForceDirectories(GlobalOptions.PackagesDir); + ForceDirectories(GlobalOptions.ArchivesDir); ForceDirectories(GlobalOptions.CompilerConfigDir); end; diff --git a/utils/fppkg/pkgglobals.pp b/utils/fppkg/pkgglobals.pp index 7995a5da69..4658eac5a4 100644 --- a/utils/fppkg/pkgglobals.pp +++ b/utils/fppkg/pkgglobals.pp @@ -53,6 +53,11 @@ const type EPackagerError = class(Exception); +{$if defined(VER2_2) and defined(WINDOWS)} +Function GetAppConfigDir(Global : Boolean) : String; +Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String; +{$endif VER2_2 AND WINDOWS} + // Logging Function StringToLogLevels (S : String) : TLogLevels; Function LogLevelsToString (V : TLogLevels): String; @@ -99,6 +104,64 @@ uses pkgmessages; +function FPPkgGetVendorName:string; +begin +{$ifdef unix} + result:='fpc'; +{$else} + result:='FreePascal' +{$endif} +end; + + +function FPPkgGetApplicationName:string; +begin +{$ifdef unix} + result:='fppkg'; +{$else} + result:='Packages' +{$endif} +end; + + +{$if defined(VER2_2) and defined(WINDOWS)} +Function SHGetFolderPath(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; + stdcall;external 'shfolder' name 'SHGetFolderPathA'; + +Function GetAppConfigDir(Global : Boolean) : String; +Const + CSIDL_LOCAL_APPDATA = $001C; { %USERPROFILE%\Local Settings\Application Data (non roaming) } + CSIDL_COMMON_APPDATA = $0023; { %PROFILESPATH%\All Users\Application Data } + CSIDL_FLAG_CREATE = $8000; { (force creation of requested folder if it doesn't exist yet) } +Var + APath : Array[0..MAX_PATH] of char; + ID : integer; +begin + If Global then + ID:=CSIDL_COMMON_APPDATA + else + ID:=CSIDL_LOCAL_APPDATA; + if SHGetFolderPath(0,ID or CSIDL_FLAG_CREATE,0,0,@APATH[0])=S_OK then + Result:=IncludeTrailingPathDelimiter(StrPas(@APath[0])) + If (Result<>'') then + begin + if FPPkgGetVendorName<>'' then + Result:=IncludeTrailingPathDelimiter(Result+FPPkgGetVendorName); + Result:=Result+ApplicationName; + end + else + 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; +end; +{$endif VER2_2 AND WINDOWS} + function StringToLogLevels(S: String): TLogLevels; Var I : integer; @@ -341,9 +404,13 @@ begin {$ifdef unix} result:=(fpGetUID=0); {$else unix} - result:=true; + result:=false; {$endif unix} end; +initialization + OnGetVendorName:=@FPPkgGetVendorName; + OnGetApplicationName:=@FPPkgGetApplicationName; + end. diff --git a/utils/fppkg/pkghandler.pp b/utils/fppkg/pkghandler.pp index eadc20ebbe..104f752171 100644 --- a/utils/fppkg/pkghandler.pp +++ b/utils/fppkg/pkghandler.pp @@ -190,7 +190,7 @@ begin if CurrentPackage.IsLocalPackage then Result:=CurrentPackage.FileName else - Result:=GlobalOptions.PackagesDir+CurrentPackage.FileName; + Result:=GlobalOptions.ArchivesDir+CurrentPackage.FileName; end; diff --git a/utils/fppkg/pkgoptions.pp b/utils/fppkg/pkgoptions.pp index 97a5497f09..da1a70c6ef 100644 --- a/utils/fppkg/pkgoptions.pp +++ b/utils/fppkg/pkgoptions.pp @@ -23,7 +23,7 @@ Const MirrorsFileName = 'mirrors.xml'; PackagesFileName = 'packages.xml'; VersionsFileName = 'versions-%s.dat'; - CurrentConfigVersion = 2; + CurrentConfigVersion = 3; Type @@ -37,7 +37,7 @@ Type FRemoteRepository, FLocalRepository, FCompilerConfigDir, - FPackagesDir, + FArchivesDir, FBuildDir, FDownloader, FDefaultCompilerConfig, @@ -63,7 +63,7 @@ Type Property RemoteRepository : String Index 2 Read GetOptString Write SetOptString; Property LocalRepository : String Index 3 Read GetOptString Write SetOptString; Property BuildDir : String Index 4 Read GetOptString Write SetOptString; - Property PackagesDir : String Index 5 Read GetOptString Write SetOptString; + Property ArchivesDir : String Index 5 Read GetOptString Write SetOptString; Property CompilerConfigDir : String Index 6 Read GetOptString Write SetOptString; Property DefaultCompilerConfig : String Index 8 Read GetOptString Write SetOptString; Property FPMakeCompilerConfig : String Index 9 Read GetOptString Write SetOptString; @@ -139,7 +139,7 @@ Const KeyRemoteMirrorsURL = 'RemoteMirrors'; KeyRemoteRepository = 'RemoteRepository'; KeyLocalRepository = 'LocalRepository'; - KeyPackagesDir = 'PackagesDir'; + KeyArchivesDir = 'ArchivesDir'; KeyBuildDir = 'BuildDir'; KeyCompilerConfigDir = 'CompilerConfigDir'; KeyCompilerConfig = 'CompilerConfig'; @@ -172,7 +172,7 @@ begin 2 : Result:=FRemoteRepository; 3 : Result:=FLocalRepository; 4 : Result:=FBuildDir; - 5 : Result:=FPackagesDir; + 5 : Result:=FArchivesDir; 6 : Result:=FCompilerConfigDir; 8 : Result:=FDefaultCompilerConfig; 9 : Result:=FFPMakeCompilerConfig; @@ -191,7 +191,7 @@ begin 2 : FRemoteRepository:=AValue; 3 : FLocalRepository:=AValue; 4 : FBuildDir:=FixPath(AValue); - 5 : FPackagesDir:=FixPath(AValue); + 5 : FArchivesDir:=FixPath(AValue); 6 : FCompilerConfigDir:=FixPath(AValue); 8 : FDefaultCompilerConfig:=AValue; 9 : FFPMakeCompilerConfig:=AValue; @@ -222,8 +222,6 @@ end; Procedure TGlobalOptions.InitGlobalDefaults; -var - LocalDir : String; begin FConfigVersion:=CurrentConfigVersion; // Retrieve Local fppkg directory @@ -231,21 +229,19 @@ begin if IsSuperUser then begin if DirectoryExists('/usr/local/lib/fpc') then - LocalDir:='/usr/local/lib/fpc/fppkg/' + FLocalRepository:='/usr/local/lib/fpc/fppkg/' else - LocalDir:='/usr/lib/fpc/fppkg/'; + FLocalRepository:='/usr/lib/fpc/fppkg/'; end else - LocalDir:=IncludeTrailingPathDelimiter(GetEnvironmentVariable('HOME'))+'.fppkg/'; + FLocalRepository:=IncludeTrailingPathDelimiter(GetEnvironmentVariable('HOME'))+'.fppkg/'; {$else} - // Change as needed on all OS-es... - LocalDir:=ExtractFilePath(Paramstr(0))+'fppkg'+PathDelim; + FLocalRepository:=IncludeTrailingPathDelimiter(GetAppConfigDir(IsSuperUser)); {$endif} // Directories - FBuildDir:=LocalDir+'build'+PathDelim; - FPackagesDir:=LocalDir+'packages'+PathDelim; - FCompilerConfigDir:=LocalDir+'config'+PathDelim; - FLocalRepository:=LocalDir; + FBuildDir:=FLocalRepository+'build'+PathDelim; + FArchivesDir:=FLocalRepository+'archives'+PathDelim; + FCompilerConfigDir:=FLocalRepository+'config'+PathDelim; // Remote FRemoteMirrorsURL:=DefaultMirrorsURL; FRemoteRepository:=DefaultRemoteRepository; @@ -281,6 +277,13 @@ begin begin FRemoteRepository:='auto'; end; + if FConfigVersion<3 then + begin + // Directories + FBuildDir:=FLocalRepository+'build'+PathDelim; + FArchivesDir:=FLocalRepository+'archives'+PathDelim; + FCompilerConfigDir:=FLocalRepository+'config'+PathDelim; + end; if (FConfigVersion>CurrentConfigVersion) then Error(SErrUnsupportedConfigVersion,[AFileName]); end; @@ -290,7 +293,7 @@ begin FRemoteRepository:=ReadString(SDefaults,KeyRemoteRepository,FRemoteRepository); FLocalRepository:=ReadString(SDefaults,KeyLocalRepository,FLocalRepository); FBuildDir:=FixPath(ReadString(SDefaults,KeyBuildDir,FBuildDir)); - FPackagesDir:=FixPath(ReadString(SDefaults,KeyPackagesDir,FPackagesDir)); + FArchivesDir:=FixPath(ReadString(SDefaults,KeyArchivesDir,FArchivesDir)); FCompilerConfigDir:=FixPath(ReadString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir)); FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig); FFPMakeCompilerConfig:=ReadString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig); @@ -314,7 +317,7 @@ begin begin WriteInteger(SDefaults,KeyConfigVersion,CurrentConfigVersion); WriteString(SDefaults,KeyBuildDir,FBuildDir); - WriteString(SDefaults,KeyPackagesDir,FPackagesDir); + WriteString(SDefaults,KeyArchivesDir,FArchivesDir); WriteString(SDefaults,KeyCompilerConfigDir,FCompilerConfigDir); WriteString(SDefaults,KeyLocalRepository,FLocalRepository); WriteString(SDefaults,KeyRemoteMirrorsURL,FRemoteMirrorsURL);