// Return TRUE if the search string exists in any
// of the prefs fields.
BOOL CPrefElement::FindString(CString strFind)
{
  strFind.MakeUpper();

  CString str = GetUIName();
  str.MakeUpper();
  if (str.Find(strFind) >= 0)
    return TRUE;

  str = GetPrefValue();
  str.MakeUpper();
  if (str.Find(strFind) >= 0)
    return TRUE;

  str = GetPrefName();
  str.MakeUpper();
  if (str.Find(strFind) >= 0)
    return TRUE;

  str = GetPrefType();
  str.MakeUpper();
  if (str.Find(strFind) >= 0)
    return TRUE;

  str = GetPrefDescription();
  str.MakeUpper();
  if (str.Find(strFind) >= 0)
    return TRUE;

  return FALSE;
}
Пример #2
0
//
// GetPrefInt()
//
// return int value if pref exists and is set
// saves you the hastle of passing in a string and evaling it later
//
int
CPreferenceFile::GetPrefInt(const char *inIdentifier, int inDefault)
{
  char value[MAXLEN];
  int nValue;

  GetPrefValue(inIdentifier, nValue, inDefault);

  return nValue;
}
Пример #3
0
//
// GetPrefBool()
//
// return True/False if a boolean pref exists and is set
// saves you the hastle of passing in a string and evaling it later
//
bool
CPreferenceFile::GetPrefBool(const char *inIdentifier, bool inDefault)
{
  char value[MAXLEN];
  int nValue;

  GetPrefValue(inIdentifier, nValue, inDefault);

  if (nValue)
    return TRUE;

  return FALSE;
}
// For a pref node element, returns a string which is used for the tree ctrl
// label.
CString CPrefElement::GetPrettyNameValueString()
{
  CString strValue = GetPrefValue();

  if (IsChoose())
  {
    strValue = GetSelectedChoiceString();
  }

  CString strRetVal;

  strRetVal.Format("%s  [%s]", m_strUIName, strValue);

  return strRetVal;
}
// Make an XML element string for this pref.
CString CPrefElement::XML(int iIndentSize, int iIndentLevel)
{
  int iIndentSpaces = iIndentSize * iIndentLevel;

  CString strRet;
  strRet.Format("%*s<PREF uiname=\"%s\" prefname=\"%s\" type=\"%s\" default=\"%s\" lockable=\"%s\" description=\"%s\" useradded=\"%s\">\n", 
    iIndentSpaces, " ", GetUIName(), GetPrefName(), GetPrefType(),
    GetDefaultValue(), IsLockable()?"true":"false", GetPrefDescription(), 
    IsUserAdded()?"true":"false");

  CString strTmp;
  if (IsChoose())
  {
    strTmp.Format("%*s<CHOICES>\n", iIndentSpaces + iIndentSize, " ");
    strRet += strTmp;

    for (int i = 0; i < m_iChoices; i++)
    {
      strTmp.Format("%*s<CHOICE uiname=\"%s\" value=\"%s\"/>\n", iIndentSpaces + iIndentSize + iIndentSize, " ", m_astrChoiceName[i], m_astrChoiceVal[i]);
      strRet += strTmp;
    }

    strTmp.Format("%*s</CHOICES>\n", iIndentSpaces + iIndentSize, " ");
    strRet += strTmp;
  }

  strTmp.Format("%*s<VALUE>%s</VALUE>\n", iIndentSpaces + iIndentSize, " ", GetPrefValue());
  strRet += strTmp;

  strTmp.Format("%*s<LOCKED>%s</LOCKED>\n", iIndentSpaces + iIndentSize, " ", IsLocked()?"true":"false");
  strRet += strTmp;

  strTmp.Format("%*s<REMOTEADMIN>%s</REMOTEADMIN>\n", iIndentSpaces + iIndentSize, " ", IsRemoteAdmin()?"true":"false");
  strRet += strTmp;

  CString strCloseTag;
  strCloseTag.Format("%*s</PREF>\n", iIndentSpaces, " ");

  strRet += strCloseTag;

  return strRet;
}
Пример #6
0
NS_IMETHODIMP
nsComm4xProfile::GetMailDir(const PRUnichar *aProfile, PRUnichar **_retval)
{
    NS_ENSURE_ARG_POINTER(_retval);
    *_retval = nsnull;
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MACOSX)
    nsresult rv;
    nsCOMPtr <nsILocalFile> resolvedLocation = do_CreateInstance("@mozilla.org/file/local;1");
    // on macos, registry entries are UTF8 encoded
    NS_ConvertUTF16toUTF8 profileName(aProfile);

    nsCOMPtr<nsIFile> regFile;
    rv = NS_GetSpecialDirectory(OLDREG_DIR, getter_AddRefs(regFile));
    if (NS_FAILED(rv)) return rv;

    regFile->AppendNative(NS_LITERAL_CSTRING(OLDREG_NAME));

    nsCAutoString path;
    rv = regFile->GetNativePath(path);
    if (NS_FAILED(rv)) return rv;

    if (NR_StartupRegistry())
        return NS_ERROR_FAILURE;

    HREG reg = nsnull;
    RKEY profile = nsnull;

    if (NR_RegOpen(path.get(), &reg))
      goto cleanup;

    if (NR_RegGetKey(reg, ROOTKEY_USERS, profileName.get(), &profile))
        goto cleanup;

    char profilePath[MAXPATHLEN];
    if (NR_RegGetEntryString(reg, profile, "ProfileLocation", profilePath, MAXPATHLEN))
        goto cleanup;

    resolvedLocation->InitWithPath(NS_ConvertUTF8toUTF16(profilePath));
    if (resolvedLocation) {
        nsCOMPtr <nsIFile> file;
        rv = resolvedLocation->Clone(getter_AddRefs(file));
        if (NS_FAILED(rv)) return rv;
        nsCOMPtr <nsILocalFile> profileLocation;
        profileLocation = do_QueryInterface(file);
        rv = profileLocation->AppendNative(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_4x));
        if (NS_FAILED(rv)) return rv;
        bool exists = false;
        rv = profileLocation->Exists(&exists);
        if (NS_FAILED(rv)) return rv;
        if (exists) {
            nsString prefValue;
            rv = GetPrefValue(profileLocation, PREF_NAME, PREF_END, getter_Copies(prefValue));
            if (NS_FAILED(rv)) return rv;
            if (!prefValue.IsEmpty()) {
#ifdef XP_MACOSX
                rv = profileLocation->SetPersistentDescriptor(NS_ConvertUTF16toUTF8(prefValue));
                if (NS_FAILED(rv)) return rv;
                nsAutoString path;
                rv = profileLocation->GetPath(path);
                if (NS_FAILED(rv)) return rv;
                *_retval = ToNewUnicode(path);
#else
                *_retval = ToNewUnicode(prefValue);
#endif
            }
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MACOSX)
            else {
                nsCOMPtr <nsIFile> mailLocation;
                rv =  resolvedLocation->Clone(getter_AddRefs(mailLocation));
                if (NS_FAILED(rv)) return rv;
                rv = mailLocation->AppendNative(NS_LITERAL_CSTRING("Mail"));
                if (NS_FAILED(rv)) return rv;
                nsAutoString path;
                rv = mailLocation->GetPath(path);
                if (NS_FAILED(rv)) return rv;
                *_retval = ToNewUnicode(path);
            }
#endif
        }
    }

cleanup:
    if (reg)
        NR_RegClose(reg);
    NR_ShutdownRegistry();
    return rv;
#else
    return NS_ERROR_FAILURE;
#endif
}