class function TConfig.GXIniFolder: string;
const
GXEPath = '\GXExplorer';
ShellFolderKey = '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders';
var
AppDataPath, FullPath: string;
Buffer: array[0..MAX_PATH] of Char;
Malloc: IMalloc;
PIDL: PItemIDList;
DefaultPath: Boolean;
begin
AppDataPath := '';
FullPath := '';
DefaultPath := False;
// Try to get path using API
if Succeeded((SHGetSpecialFolderLocation(0, CSIDL_APPDATA, PIDL))) then
if (SHGetPathFromIDList(PIDL, Buffer)) then
if Succeeded(SHGetMalloc(Malloc)) then
try
AppDataPath := Buffer;
finally
Malloc.Free(PIDL);
Malloc := nil;
end;
// API failed, so try to get path using registry
if AppDataPath = '' then
with {$IFDEF VER130}
TRegistry.Create(KEY_READ){$ELSE}TRegistry.Create{$ENDIF} do
if OpenKey(ShellFolderKey, False) then
AppDataPath := ReadString('AppData');
// Registry failed, so default to installation folder (no per-user settings)
if AppDataPath = '' then
begin
AppDataPath := ExtractFileDir(ParamStr(0));
DefaultPath := True;
end;
if not DefaultPath then FullPath := AppDataPath + GXEPath else
FullPath := AppDataPath;
if not DirectoryExists(FullPath) then
if not CreateDir(FullPath) then
FullPath := ExtractFileDir(ParamStr(0));
Result := FullPath;
end;
const
GXEPath = '\GXExplorer';
ShellFolderKey = '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders';
var
AppDataPath, FullPath: string;
Buffer: array[0..MAX_PATH] of Char;
Malloc: IMalloc;
PIDL: PItemIDList;
DefaultPath: Boolean;
begin
AppDataPath := '';
FullPath := '';
DefaultPath := False;
// Try to get path using API
if Succeeded((SHGetSpecialFolderLocation(0, CSIDL_APPDATA, PIDL))) then
if (SHGetPathFromIDList(PIDL, Buffer)) then
if Succeeded(SHGetMalloc(Malloc)) then
try
AppDataPath := Buffer;
finally
Malloc.Free(PIDL);
Malloc := nil;
end;
// API failed, so try to get path using registry
if AppDataPath = '' then
with {$IFDEF VER130}
TRegistry.Create(KEY_READ){$ELSE}TRegistry.Create{$ENDIF} do
if OpenKey(ShellFolderKey, False) then
AppDataPath := ReadString('AppData');
// Registry failed, so default to installation folder (no per-user settings)
if AppDataPath = '' then
begin
AppDataPath := ExtractFileDir(ParamStr(0));
DefaultPath := True;
end;
if not DefaultPath then FullPath := AppDataPath + GXEPath else
FullPath := AppDataPath;
if not DirectoryExists(FullPath) then
if not CreateDir(FullPath) then
FullPath := ExtractFileDir(ParamStr(0));
Result := FullPath;
end;