00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "vmsMozillaPrefs.h"
00008
00009 vmsMozillaPrefs::vmsMozillaPrefs()
00010 {
00011
00012 }
00013
00014 vmsMozillaPrefs::~vmsMozillaPrefs()
00015 {
00016
00017 }
00018
00019 bool vmsMozillaPrefs::LoadPrefs(LPCSTR pszFile)
00020 {
00021 Free ();
00022
00023 HANDLE hFile = CreateFile (pszFile, GENERIC_READ, FILE_SHARE_READ, NULL,
00024 OPEN_EXISTING, 0, NULL);
00025 if (hFile == INVALID_HANDLE_VALUE)
00026 return false;
00027
00028 int n = GetFileSize (hFile, NULL);
00029 m_strPrefs.pszString = new char [n+1];
00030
00031 DWORD dw;
00032 ReadFile (hFile, m_strPrefs.pszString, n, &dw, NULL);
00033 m_strPrefs.pszString [n] = 0;
00034
00035 CloseHandle (hFile);
00036
00037 return true;
00038 }
00039
00040 void vmsMozillaPrefs::Free()
00041 {
00042 if (m_strPrefs.pszString) {
00043 delete [] m_strPrefs.pszString;
00044 m_strPrefs.pszString = 0;
00045 }
00046 }
00047
00048 fsString vmsMozillaPrefs::get_Value(LPCSTR pszPrefName) const
00049 {
00050 LPCSTR pszPrefs = m_strPrefs.pszString;
00051
00052 fsString strPrefName;
00053 strPrefName = "\"";
00054 strPrefName += pszPrefName;
00055 strPrefName += "\"";
00056
00057 while (*pszPrefs && strnicmp (pszPrefs, strPrefName, strPrefName.Length ()))
00058 pszPrefs++;
00059
00060 if (*pszPrefs == 0)
00061 return MOZILLAPREFS_VALUE_NOT_FOUND;
00062
00063 pszPrefs += strPrefName.Length ();
00064
00065
00066 while (*pszPrefs && *pszPrefs != ',')
00067 pszPrefs++;
00068
00069 if (*pszPrefs == 0)
00070 return MOZILLAPREFS_UNEXPECTED_ERROR;
00071
00072 pszPrefs++;
00073 while (*pszPrefs == ' ' || *pszPrefs == '\t')
00074 pszPrefs++;
00075
00076 bool bInQ = false;
00077 if (*pszPrefs == '"') {
00078 pszPrefs++;
00079 bInQ = true;
00080 }
00081
00082 fsString strValue;
00083
00084 if (bInQ)
00085 {
00086 while (*pszPrefs && *pszPrefs != '"')
00087 {
00088 char c = *pszPrefs++;
00089
00090 if (c == '\\')
00091 {
00092 switch (*pszPrefs)
00093 {
00094 case 'n': c = '\n'; break;
00095 case 't': c = '\t'; break;
00096 case 'r': c = '\r'; break;
00097 default: c = *pszPrefs; break;
00098 }
00099
00100 pszPrefs++;
00101 }
00102
00103 strValue += c;
00104 }
00105 }
00106 else
00107 {
00108 while (IsCharAlphaNumeric (*pszPrefs))
00109 strValue += *pszPrefs++;
00110 }
00111
00112 return strValue;
00113 }