home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / gotch175.zip / src / settings / thth_settings.cpp next >
C/C++ Source or Header  |  2000-02-20  |  2KB  |  98 lines

  1. /***
  2.  settings.cpp
  3.  ***/
  4.  
  5. #include "thth_settings.h"
  6.  
  7. #ifndef NO_ERROR
  8. #define NO_ERROR 0
  9. #endif
  10.  
  11. // ** Settings ************************************************************ /*FOLD00*/
  12.  
  13. THTH_SETTINGS :: ththSettings (PTHTH_SE *ppse, PSZ pszInifile, ULONG ulVersion)
  14. {
  15.     // what's this?!? well, just forget about doing inits ...
  16.     if (! ppse)
  17.         return;
  18.     this->ppse = ppse;
  19.  
  20.     // reset - everything should already be on defaults, but just in case ...
  21.     Reset ();
  22.  
  23.     // shall we use the pro-file?
  24.     if (! pszInifile)
  25.         return;
  26.     psz = pszInifile;  // FIXME maybe do a strdup instead ...
  27.  
  28.     ulError = 0;
  29.  
  30.     // check if a pro-file does exist; if not we need not complain
  31.     // about wrong version
  32.     if (access(pszInifile, 0) != NO_ERROR) {
  33.         ulVersion = 0;
  34.         ulError = 3; // "select language" needed
  35.     }
  36.  
  37.     // open the pro-file
  38.     CHAR   ach[_MAX_PATH];
  39.     strcpy (ach, psz);
  40.     if (! (hini = PrfOpenProfile (GETHAB, ach)))
  41.     {
  42.         ulError = 1;
  43.         return;
  44.     }
  45.  
  46.     // shall we check the version number?
  47.     if (ulVersion) {
  48.         if ((this->ulVersion =
  49.              PrfQueryProfileInt (hini, "Profile", "Version", 0L))) {
  50.             if (this->ulVersion != ulVersion) {
  51.                 ulError = 2;
  52.                 return;
  53.             }
  54.         } else
  55.             ulError = 4; // INI file corrupted or wrong ini file
  56.     }
  57.  
  58.     // awright baby, load the stuff! ;-)
  59.     Load ();
  60. }
  61.  
  62. // ** Save ****************************************************************
  63.  
  64. BOOL THTH_SETTINGS :: Save (VOID)
  65. {
  66.     if (!hini || !ppse)
  67.         return FALSE;
  68.  
  69.     if (ulVersion)
  70.     {
  71.         CHAR   ach[11];
  72.         sprintf (ach, "%lu", ulVersion);
  73.         PrfWriteProfileString (hini, "Profile", "Version", ach);
  74.     }
  75.  
  76.     // awright baby, save the stuff! ;-)
  77.     for (LONG i = 0; ppse[i]; i++)
  78.         ppse[i]->Save (hini);
  79.  
  80.     return TRUE;
  81. }
  82.  
  83. // ** ~Settings *********************************************************** /*FOLD00*/
  84.  
  85. THTH_SETTINGS :: ~ththSettings (VOID)
  86. {
  87.     // the only thing we might need to do is save the stuff to the pro-file
  88.     Save ();
  89.  
  90.     // goodbye pro-file!
  91.     if (hini) { PrfCloseProfile (hini); }
  92.     hini = NULL;
  93.  
  94.     // FIXME if we copied the filename, delete it now
  95. }
  96.  
  97. // ************************************************************************
  98.