OILPreferences Class Reference

This class, like the Preferences class, is only ever instantiated once. It is a collection of routines to be used to handle the OIL side of reading and writing preferences. This class is used internally by the Preferences class - no other class should need to use it. More...

#include <oilprefs.h>

List of all members.

Public Member Functions

 OILPreferences (const wxString &appName=wxEmptyString, const wxString &vendorName=wxEmptyString, const wxString &localFilename=wxEmptyString, const wxString &globalFilename=wxEmptyString, longstyle=0, wxMBConv &conv=wxConvUTF8)
void Write (LPTCHAR Section, LPTCHAR PrefName, PreferenceType Type, PrefData pData)
 This function writes a given preference out to the application's own initialisation (profile/preference) file.
void Read (LPTCHAR Section, LPTCHAR PrefName, PreferenceType Type, PrefData pData)
 This function attempts to read the given preference in the given section from the preference file. No error is raised if the preference cannot be found, because this is a perfectly valid occurence - e.g. when a tool is being used for the first time, it has no preferences in the preference file.
BOOL OpenInput ()
 Prepares the preference system for reading in preferences.
BOOL CloseInput ()
 Performs clean-up necessary when the preferences file is no longer needed for reading.
BOOL OpenOutput ()
 Prepares the OIL for writing preferences out to the preferences file.
BOOL CloseOutput ()
 Closes the preference file when all the preferences have been written.
void WipePreferenceFile ()
 Remove all entries from a preference file. This is done by deleting the file and creating a new one.
void WipeDangerousPrefs ()
 Remove potentially dangerous entries from the registry.

Static Public Member Functions

static OILPreferencesInit ()
 Performs any initialisation of the OIL layer preferences mechanisms that may fail.


Detailed Description

This class, like the Preferences class, is only ever instantiated once. It is a collection of routines to be used to handle the OIL side of reading and writing preferences. This class is used internally by the Preferences class - no other class should need to use it.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
See also:
Preferences

Definition at line 120 of file oilprefs.h.


Constructor & Destructor Documentation

OILPreferences::OILPreferences const wxString &  appName = wxEmptyString,
const wxString &  vendorName = wxEmptyString,
const wxString &  localFilename = wxEmptyString,
const wxString &  globalFilename = wxEmptyString,
long  style = 0,
wxMBConv &  conv = wxConvUTF8
[inline]
 

Definition at line 128 of file oilprefs.h.

00132                                    : Correct*/ style = 0, wxMBConv& conv = wxConvUTF8)
00133         : wxConfig(appName, vendorName, localFilename, globalFilename, style, conv) {;}


Member Function Documentation

BOOL OILPreferences::CloseInput  ) 
 

Performs clean-up necessary when the preferences file is no longer needed for reading.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Returns:
TRUE if the input file was successfully closed, FALSE otherwise.

Definition at line 378 of file oilprefs.cpp.

00379 {
00380     wxConfig::Set(NULL);
00381 
00382     return TRUE;
00383 }

BOOL OILPreferences::CloseOutput  ) 
 

Closes the preference file when all the preferences have been written.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Returns:
TRUE if the output file was successfully closeed, FALSE otherwise.

Definition at line 413 of file oilprefs.cpp.

00414 {
00415     Flush();
00416     return TRUE;
00417 }

OILPreferences * OILPreferences::Init void   )  [static]
 

Performs any initialisation of the OIL layer preferences mechanisms that may fail.

Author:
Luke_Hart & Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/Jun/2006
Returns:
OILPreferences objects if initialisation succeeded, NULL otherwise.

Definition at line 125 of file oilprefs.cpp.

00126 {
00127     wxStandardPaths     Paths;
00128     wxString    strPath( Paths.GetUserConfigDir() );
00129     strPath += _T("/.xaralx");
00130 
00131     // Delete any file that exists where the directory should be
00132     if (wxFile::Exists(strPath))
00133         ::wxRemoveFile(strPath);
00134 
00135     // Create directory iff not exist
00136     if( !wxDir::Exists( strPath ) )
00137         ::wxMkdir( strPath );
00138 
00139     TRACEUSER( "jlh92", _T("OILPreferences::Init %s\n"), PCTSTR(strPath) );
00140 
00141     // Open config storage
00142     strPath += _T("/preferences");
00143     OILPreferences* pPrefs = new OILPreferences(_T("xaralx"), _T("Xara"), strPath);
00144 
00145     TRACEUSER( "jlh92", _T("OILPreferences::Init2 %s\n"), PCTSTR(strPath) );
00146     
00147     // Return the object we made or a NULL pointer if we failed
00148     return pPrefs;
00149 }

BOOL OILPreferences::OpenInput  ) 
 

Prepares the preference system for reading in preferences.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Returns:
TRUE if the INT32 file was successfully opened, FALSE otherwise.

Definition at line 358 of file oilprefs.cpp.

00359 {
00360     // Tell wxWidgets this is the default wxConfig object
00361     wxConfig::Set(this);
00362 
00363     return TRUE;
00364 }

BOOL OILPreferences::OpenOutput  ) 
 

Prepares the OIL for writing preferences out to the preferences file.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Returns:
TRUE if the output file was successfully opened, FALSE otherwise.

Definition at line 397 of file oilprefs.cpp.

00398 {
00399     return TRUE;
00400 }

void OILPreferences::Read LPTCHAR  Section,
LPTCHAR  PrefName,
PreferenceType  Type,
PrefData  pData
 

This function attempts to read the given preference in the given section from the preference file. No error is raised if the preference cannot be found, because this is a perfectly valid occurence - e.g. when a tool is being used for the first time, it has no preferences in the preference file.

TECHNICAL NOTES

This function does not use the MFC GetProfileString() function becuase this returns a CString and we're trying to avoid these in Camelot. It uses the standard SDK function instead.

Definition at line 294 of file oilprefs.cpp.

00296 {
00297     wxString strKey = _T("/Options/") + wxString(Section) + _T("/") + wxString(PrefName);
00298     
00299     switch (Type)
00300     {
00301         case PREF_INT:
00302         {
00303             // Use the value already in pData->Int as the value to return if the 
00304             // preference is not found.
00305             /*TYPENOTE: Correct*/ long l;
00306             if (wxConfig::Read(strKey, &l))
00307                 *pData.pInt = (INT32)l; // Do not write directly as may be longer than 32 bits
00308             break;
00309         }
00310 
00311         case PREF_UINT:
00312         {
00313             // Note that signed value is read and cast directly into Unsigned memory
00314             // allocation reversing the effects fo the cast used in Write above...
00315             /*TYPENOTE: Correct*/ long l;
00316             if (wxConfig::Read(strKey, &l))
00317                 *pData.pUInt = (UINT32)l; // Do not write directly as may be longer than 32 bits
00318             break;
00319         }
00320         case PREF_DOUBLE:
00321         {
00322             // Get the textual version of the double and convert it to a double.
00323             // default to null string
00324             wxConfig::Read(strKey, (double*)(pData.pDouble));
00325             break;
00326         }   
00327         case PREF_STRING:
00328         {
00329             // Just get the string - need to ask for the address of the String's
00330             // text buffer so we can pass it to the SDK profile API.
00331             wxString str;
00332             if (wxConfig::Read(strKey, &str))
00333             {
00334                 str.Truncate(256);
00335                 *(pData.pString) = (LPCTSTR)str;
00336 //              *(pData.pString) = String_256(str); // use this form when StringBase derived classes support direct conversion
00337             }
00338             break;
00339         }
00340 
00341         default:
00342             ENSURE(FALSE, "OILPreferences::Read() called with an illegal preference type");
00343             break;
00344     }
00345 }

void OILPreferences::WipeDangerousPrefs  ) 
 

Remove potentially dangerous entries from the registry.

Author:
Chris_Gallimore (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/2001

Definition at line 177 of file oilprefs.cpp.

00178 {
00179     // wipe the potentially dangerous settings from the registry
00180     DeleteGroup(_T("Gallery"));
00181     DeleteGroup(_T("Options/Templates"));
00182     DeleteGroup(_T("Options/NewTemplates"));
00183     
00184 //  DeleteRegKeyAndSubKeys (hAppStateRegKey, PRODUCT_REGISTRYKEY_GALLERY);
00185 //  HKEY optsKey = OpenRegKey(hAppStateRegKey, PRODUCT_REGISTRYKEY_OPTIONS);
00186 //  DeleteRegKeyAndSubKeys (optsKey, TEXT ("Templates"));
00187 //  DeleteRegKeyAndSubKeys (optsKey, TEXT ("NewTemplates"));
00188 //  CloseRegKey (optsKey);
00189 }

void OILPreferences::WipePreferenceFile  ) 
 

Remove all entries from a preference file. This is done by deleting the file and creating a new one.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/11/93

Definition at line 162 of file oilprefs.cpp.

00163 {
00164     DeleteAll();
00165 }

void OILPreferences::Write LPTCHAR  Section,
LPTCHAR  PrefName,
PreferenceType  Type,
PrefData  Data
 

This function writes a given preference out to the application's own initialisation (profile/preference) file.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/93
Parameters:
Section - Name of the section to write the preference into. [INPUTS] PrefName - Name of the preference itself. Type - Type of the preference (INT32, UINT32, etc.) Data - Union holding the pointer to the data to write out to the preference file.
See also:
OILPreferences; OILPreferences::Read

Definition at line 209 of file oilprefs.cpp.

00211 {
00212     wxString strKey = _T("/Options/") + wxString(Section) + _T("/") + wxString(PrefName);
00213 
00214     BOOL Worked=FALSE;
00215 
00216     switch (Type)
00217     {
00218         case PREF_INT:
00219         {
00220             /*TYPENOTE: Correct*/ long l = (long)(*Data.pInt);
00221             Worked = wxConfig::Write(strKey, l);
00222             break;
00223         }
00224         
00225         case PREF_UINT:
00226         {
00227             // Note that unsigned cast to signed here will appear to store the wrong value
00228             // in the Config store but this apparent mistake will be rectified when the
00229             // value is read in and cast back to UINT32 again.
00230             // (Could write UINT32 prefs as strings...)
00231             //
00232             /*TYPENOTE: Correct*/ long l = (long)(*Data.pUInt);
00233             Worked = wxConfig::Write(strKey, l);
00234             break;
00235         }
00236 
00237         case PREF_DOUBLE:
00238             Worked = wxConfig::Write(strKey, (double)*(Data.pDouble));
00239             break;
00240             
00241         case PREF_STRING:
00242             Worked = wxConfig::Write(strKey, wxString((TCHAR*)*(Data.pString)));
00243 //          Worked = wxConfig::Write(strKey, *(Data.pString));  // use this form when StringBase derived classes support direct conversion
00244             break;
00245             
00246         default:
00247             ENSURE(FALSE, "OILPreferences::Write() called with an illegal preference type");
00248             break;
00249     }
00250 
00251     if (!Worked)
00252     {
00253         ERROR3  ("Error saving preference - See trace message for details");
00254         TRACE( _T("Error saving preference '%s'\n"), PrefName);
00255     }
00256 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:21 2007 for Camelot by  doxygen 1.4.4