Logo Search packages:      
Sourcecode: adonthell version File versions  Download package

bool config::read_adonthellrc (  ) 

Reads the configuration file. If it cannot find the file, it tries to write a default one.

Returns:
true on success, false otherwise.

Definition at line 294 of file prefs.cc.

References audio_channels, audio_resolution, audio_sample_rate, audio_volume, language, parse_adonthellrc(), prefsin, quick_load, screen_mode, u_int32, and write_adonthellrc().

{
    int n, i = 1;
    u_int32 major = 0, minor = 0, micro = 0, MAJOR, MINOR, MICRO;
    char suffix[16] = "\0", SUFFIX[16] = "\0"; 
    string s, fname;

#ifndef WIN32
    fname = adonthellrc + "/adonthellrc";
#else
    fname = adonthellrc + "/adonthell.ini";
#endif

    // try to create that directory in case it dosn't exist
#ifdef WIN32
    mkdir (adonthellrc.c_str ());
#else
    mkdir (adonthellrc.c_str (), 0700);
#endif
    
    // prefsin is declared in lex.prefs.c
    prefsin = fopen (fname.c_str (), "r");

    // open failed -> try to write new configuration 
    if (!prefsin)
    {
        write_adonthellrc ();

        // now try again
        if (!(prefsin = fopen (fname.c_str (), "r")))
        {
            fprintf (stderr, "*** warning: prefs::read_adonthellrc: creating config file failed\n");
            return false;
        }
    }

    // adonthellrc opened -> read configuration
    while (i)
    {
        switch (i = parse_adonthellrc (n, s))
        {
            case PREFS_LANGUAGE:
            {
                if (parse_adonthellrc (n, s) == PREFS_STR) language = s;
                break;
            }
            case PREFS_FONT:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) font = s;
                break;
            }
            case PREFS_SCREEN_MODE:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) screen_mode = n;
                break;
            }

            case PREFS_DOUBLE_SCREEN:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) double_screen = n;
                break;
            }

            case PREFS_QUICK_LOAD:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) quick_load = n;
                break;
            }

            case PREFS_AUDIO_RESOLUTION:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) audio_resolution = n;
                break;
            }

            case PREFS_AUDIO_CHANNELS:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) audio_channels = n;
                break;
            }

            case PREFS_AUDIO_SAMPLE_RATE:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) audio_sample_rate = n;
                break;
            }

            case PREFS_AUDIO_VOLUME:
            {
                if (parse_adonthellrc (n, s) == PREFS_NUM) audio_volume = n;
                break;
            }

            case PREFS_VERSION:
            {
                // get config file version number
                if (parse_adonthellrc (n, s) == PREFS_STR) 
                    sscanf (s.c_str (), "%d.%d.%d%15s", &major, &minor, &micro, suffix);
                break;
            }
            default: break;
        }
    }    

    fclose (prefsin);

    // get engine version numbers
    sscanf (VERSION, "%d.%d.%d%15s", &MAJOR, &MINOR, &MICRO, SUFFIX);
    
    // compare version of config file and engine
    if (major < MAJOR || 
        (major == MAJOR && minor < MINOR) ||
        (major == MAJOR && minor == MINOR && micro < MICRO) ||
        strcmp (suffix, SUFFIX) != 0)
    {
        // update config file if engine is newer
        write_adonthellrc ();
    }

    return true;
}


Generated by  Doxygen 1.6.0   Back to index