interface
{$SCOPEDENUMS ON}
const
CSIDL_FLAG_CREATE = $8000;
CSIDL_FLAG_DONT_VERIFY = $4000;
CSIDL_ADMINTOOLS = $0030;
CSIDL_PROFILE = $0028;
type
TEnvironment =
record
public type
TSpecialFolder = (
//
AdminTools = CSIDL_ADMINTOOLS,
//
UserProfile = CSIDL_PROFILE);
TSpecialFolderOption = (
//
None = 0,
//
Create = CSIDL_FLAG_CREATE,
//
DoNotVerify = CSIDL_FLAG_DONT_VERIFY);
private
class function InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption):
string;
static;
public
class function GetFolderPath(AFolder: TSpecialFolder):
string;
overload;
static;
class function GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption):
string;
overload;
static;
end;
implementation
uses
Winapi.Windows,
Winapi.SHFolder;
{ TEnvironment }
class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder; AOption: TSpecialFolderOption):
string;
begin
Result := InternalGetFolder(AFolder, AOption);
end;
class function TEnvironment.InternalGetFolder(AFolder: TSpecialFolder; AOption: TSpecialFolderOption):
string;
var
LStr:
array [0 .. MAX_PATH]
of Char;
begin
SetLastError(ERROR_SUCCESS);
if SHGetFolderPath(0, Integer(AFolder)
or Integer(AOption), 0, 0, @LStr) = S_OK
then
Result := LStr;
end;
class function TEnvironment.GetFolderPath(AFolder: TSpecialFolder):
string;
begin
Result := InternalGetFolder(AFolder, TSpecialFolderOption.None);
end;