unit lispecfolder;

{$MODE Delphi}
{$RANGECHECKS ON}
{$OVERFLOWCHECKS ON}
{$IOCHECKS ON}
{$OBJECTCHECKS ON}
{$VARSTRINGCHECKS ON}
{$LONGSTRINGS ON}


// This code is part of the opsi.org project

// Copyright (c) uib gmbh (www.uib.de)
// This sourcecode is owned by the uib gmbh, D55118 Mainz, Germany
// and published under the Terms of the GNU Affero General Public License.
// Text of the AGPL: http://www.gnu.org/licenses/agpl-3.0-standalone.html
// author: Rupert Roeder, detlef oertel
// credits: http://www.opsi.org/credits/


interface

uses
  //LCLIntf,
  Classes,
  SysUtils;

var
  specialFolders, debugmessages: TStringList;

procedure retrieveFolders4Linux;


function GetCommonStartmenuPath: string;

function GetCommonDesktopPath: string;

function GuessCommonProfilesPath: string;

function GetCommonAppDataPath: string;

function GetCommonStartupPath: string;
function GetCommonProgramsPath: string;
function GetStartmenuPath: string;
function GetDesktopPath: string;
function GetAppDataPath: string;
function GetStartupPath: string;
function GetProgramsPath: string;
function GetSendToPath: string;

function GetUserProfilePath: string;
function GetProfilesPath: string;
function GetDefaultUsersProfilesPath: string;

implementation

uses osfunc, osparser;

var
  errorinfo: string;


const
  csidlstrings: array [0..9] of string = (
    'desktop',
    'sendto',
    'startmenu',
    'startup',
    'programs',
    'desktopdirectory',
    'common_startmenu',
    'common_programs',
    'common_startup',
    'common_desktopdirectory'
    );





procedure retrieveFolders4Linux;
var
  r, s, t, x, profiledir: string;
  charbuf , pstr : pchar;
  i: integer;
  profdirlength : dword;

begin
  try
    specialFolders.Add('Common AppData');
    specialFolders.Values['Common AppData'] := '';

    specialFolders.add('Common Desktop');
    specialFolders.Values['Common Desktop'] :=   '';

    specialFolders.add('Common Start Menu');
    specialFolders.Values['Common Start Menu'] :=  '';

    specialFolders.add('Common Startup');
    specialFolders.Values['Common Startup'] := '';

    specialFolders.add('Common Programs');
    specialFolders.Values['Common Programs'] := '';

    specialFolders.Add('AppData');
    specialFolders.Values['AppData'] := GetEnvironmentVariable('HOME');

    specialFolders.add('Desktop');
    specialFolders.Values['Desktop'] := GetEnvironmentVariable('HOME')+'/Desktop';

    specialFolders.add('Start Menu');
    specialFolders.Values['Start Menu'] := '';

    specialFolders.add('Startup');
    specialFolders.Values['Startup'] := '';

    specialFolders.add('Programs');
    specialFolders.Values['Programs'] := '';

    specialFolders.add('SendTo');
    specialFolders.Values['SendTo'] := '';

    specialFolders.add('current profile');
    specialFolders.Values['current profile'] := GetEnvironmentVariable('HOME');

    specialFolders.add('Users home');
    specialFolders.Values['Users home'] := '/home';

    specialFolders.add('Common Profile');
    specialFolders.Values['Common Profile'] := '';

    specialFolders.add('DefaultUserProfile');
    specialFolders.Values['DefaultUserProfile'] := '';

    specialFolders.Values['current profile'] :=
        specialFolders.Values['Users home'] + '\'+getLoggedInUser;

  finally
  end;
end;


function GetCommonStartmenuPath: string;
begin
  Result := specialFolders.Values['Common Start Menu'];
end;

function GetCommonDesktopPath: string;
begin
  Result := specialFolders.Values['Common Desktop'];
end;

function GetCommonAppDataPath: string;
begin
  Result := specialFolders.Values['Common AppData'];
end;

function GetCommonStartupPath: string;
begin
  Result := specialFolders.Values['Common Startup'];
end;

function GetCommonProgramsPath: string;
begin
  Result := specialFolders.Values['Common Programs'];
end;

function GetStartmenuPath: string;
begin
  Result := specialFolders.Values['Start Menu'];
end;

function GetDesktopPath: string;
begin
  Result := specialFolders.Values['Desktop'];
end;

function GetAppDataPath: string;
begin
  Result := specialFolders.Values['AppData'];
end;

function GetStartupPath: string;
begin
  Result := specialFolders.Values['Startup'];
end;

function GetProgramsPath: string;
begin
  Result := specialFolders.Values['Programs'];
end;

function GetSendToPath: string;
begin
  Result := specialFolders.Values['SendTo'];
end;

function GetUserProfilePath: string;
begin
  Result := specialFolders.Values['current profile'];
end;


function guessCommonProfilesPath: string;
begin
  // Linux ?
  (*
  Result := specialFolders.Values['Users home'];
  if uibNTVersion < tntverWINVISTA then
    Result := Result + '\All Users'
  else
    Result := Result + '\Public';
  *)
end;

function getCommonProfilesPath: string;
begin
  Result := specialFolders.Values['Common Profile'];
end;


function GetProfilesPath: string;
begin
  Result := specialFolders.Values['Users home'];
end;

function GetDefaultUsersProfilesPath: string;
begin
  Result := specialFolders.Values['DefaultUserProfile'];
end;




{****************************************************** }

begin
  //uibNTVersion := GetUibNTVersion(errorinfo);
  specialFolders := TStringList.Create;
  debugmessages := TStringList.Create;
  //retrieveFoldersFromHKLM;
  //retrieveFoldersFromWinApi;
  // If we do it here, there is no log file !
  //retrieveFolders4Linux;
end.

