| 1 | /***
|
|---|
| 2 | This file belongs to the Gotcha! distribution.
|
|---|
| 3 | Copyright (C) 1998-2002 Thorsten Thielen <thth@c2226.de>
|
|---|
| 4 |
|
|---|
| 5 | This program is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | ***/
|
|---|
| 19 |
|
|---|
| 20 | #include "thth_settings.h"
|
|---|
| 21 |
|
|---|
| 22 | #ifndef NO_ERROR
|
|---|
| 23 | #define NO_ERROR 0
|
|---|
| 24 | #endif
|
|---|
| 25 |
|
|---|
| 26 | // ** Settings ************************************************************ /*FOLD00*/
|
|---|
| 27 |
|
|---|
| 28 | THTH_SETTINGS :: ththSettings (PTHTH_SE *ppse, PSZ pszInifile, ULONG ulVersion)
|
|---|
| 29 | {
|
|---|
| 30 | // what's this?!? well, just forget about doing inits ...
|
|---|
| 31 | if (! ppse)
|
|---|
| 32 | return;
|
|---|
| 33 | this->ppse = ppse;
|
|---|
| 34 |
|
|---|
| 35 | // reset - everything should already be on defaults, but just in case ...
|
|---|
| 36 | Reset ();
|
|---|
| 37 |
|
|---|
| 38 | // shall we use the pro-file?
|
|---|
| 39 | if (! pszInifile)
|
|---|
| 40 | return;
|
|---|
| 41 | psz = pszInifile; // FIXME maybe do a strdup instead ...
|
|---|
| 42 |
|
|---|
| 43 | ulError = 0;
|
|---|
| 44 |
|
|---|
| 45 | // check if a pro-file does exist; if not we need not complain
|
|---|
| 46 | // about wrong version
|
|---|
| 47 | if (access(pszInifile, 0) != NO_ERROR) {
|
|---|
| 48 | ulVersion = 0;
|
|---|
| 49 | ulError = 3; // "select language" needed
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // open the pro-file
|
|---|
| 53 | CHAR ach[_MAX_PATH];
|
|---|
| 54 | strcpy (ach, psz);
|
|---|
| 55 | if (! (hini = PrfOpenProfile (GETHAB, ach)))
|
|---|
| 56 | {
|
|---|
| 57 | ulError = 1;
|
|---|
| 58 | return;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | // shall we check the version number?
|
|---|
| 62 | if (ulVersion) {
|
|---|
| 63 | if ((this->ulVersion =
|
|---|
| 64 | PrfQueryProfileInt (hini, "Profile", "Version", 0L))) {
|
|---|
| 65 | if (this->ulVersion != ulVersion) {
|
|---|
| 66 | ulError = 2;
|
|---|
| 67 | return;
|
|---|
| 68 | }
|
|---|
| 69 | } else
|
|---|
| 70 | ulError = 4; // INI file corrupted or wrong ini file
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | // awright baby, load the stuff! ;-)
|
|---|
| 74 | Load ();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // ** Save ****************************************************************
|
|---|
| 78 |
|
|---|
| 79 | BOOL THTH_SETTINGS :: Save (VOID)
|
|---|
| 80 | {
|
|---|
| 81 | if (!hini || !ppse)
|
|---|
| 82 | return FALSE;
|
|---|
| 83 |
|
|---|
| 84 | if (ulVersion)
|
|---|
| 85 | {
|
|---|
| 86 | CHAR ach[11];
|
|---|
| 87 | sprintf (ach, "%lu", ulVersion);
|
|---|
| 88 | PrfWriteProfileString (hini, "Profile", "Version", ach);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // awright baby, save the stuff! ;-)
|
|---|
| 92 | for (LONG i = 0; ppse[i]; i++)
|
|---|
| 93 | ppse[i]->Save (hini);
|
|---|
| 94 |
|
|---|
| 95 | return TRUE;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | // ** ~Settings *********************************************************** /*FOLD00*/
|
|---|
| 99 |
|
|---|
| 100 | THTH_SETTINGS :: ~ththSettings (VOID)
|
|---|
| 101 | {
|
|---|
| 102 | // the only thing we might need to do is save the stuff to the pro-file
|
|---|
| 103 | Save ();
|
|---|
| 104 |
|
|---|
| 105 | // goodbye pro-file!
|
|---|
| 106 | if (hini) { PrfCloseProfile (hini); }
|
|---|
| 107 | hini = NULL;
|
|---|
| 108 |
|
|---|
| 109 | // FIXME if we copied the filename, delete it now
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // ************************************************************************
|
|---|