function TNetscapeInstaller.NS6GetDBDir: String;
{This method also works for NS7. It either returns a string with the fully-qualified
path and filename for registry.dat, or an empty string if the retrieval fails.}
var
  sDataDir,
  sRegFile,
  sCurrent: String;
  listReg: TStringlist;
  NSRegistry: TNSRegistry;
begin
  Result := '';

  {The registry should hold a string with the current user's profile location.
  This location is different from OS to OS. The method RegGetUserDataDir is
  defined below.}
  sDataDir := RegGetUserDataDir;

  {If there's no such key it's an error condition and we should shake our head
  sorrowfully and raise an error.}
  if sDataDir = '' then
    Exit;

  {The NS profile registry will be in the following location.}
  sRegFile := sDataDir + '\Mozilla\registry.dat';

  {if it's not there, Netscape isn't corrrectly set up and we should decline to
  proceed.}
  if not FileExists(sRegFile) then
    Exit;

  listReg := TStringlist.Create;
  {TNSRegistry is defined in a separate unit - see the following posting to this
  newsgroup.}
  NSRegistry := TNSRegistry.Create(sRegFile);

  try
    if NSRegistry.ValueExists('/\Common\Profiles\CurrentProfile') then
      sCurrent := NSRegistry.ReadValue('/\Common\Profiles\CurrentProfile')
    else begin
      listReg.Text := NSRegistry.GetKeyList('/\Common\Profiles');
      {TfrmSelectProfile is a simple dialog that displays a list of all profiles
      and returns the one the user selects.}
      sCurrent := TfrmSelectProfile.SelectNSProfile('', listReg);
    end;

    if sCurrent = '' then
      Exit;

    if NSRegistry.ValueExists(Format('/\Common\Profiles\%s\directory', [
      sCurrent]))
    then
      Result := NSRegistry.ReadValue(Format('/\Common\Profiles\%s\directory', [
      sCurrent]));
  finally
    NSRegistry.Free;
    listReg.Free;
  end;

  LogData(Format('The Netscape registry at "%s" has "%s" as the current ' +
    'profile', [sRegFile, sCurrent]));
end;

function TNetscapeInstaller.RegGetUserDataDir: String;
const
  cUserDataKey =
    'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders';
var
  Reg: TRegistry;
begin
  Result := '';
  Reg := TRegistry.Create;

  try
    Reg.RootKey := HKEY_CURRENT_USER;

    if Reg.KeyExists(cUserDataKey) then begin
      Reg.OpenKey(cUserDataKey, False);

      if Reg.ValueExists('AppData') then
        Result := Reg.ReadString('AppData');

      Reg.CloseKey;
      LogData(Format('Windows Registry key "%s" contains "AppData" value "%s"',
        [cUserDataKey, Result]));
    end;
  finally
    Reg.Free;
  end;
end;
 

Reply via email to