Exemplo n.º 1
0
void loadConfigWithType(int configType) {
    configData *data = configDataForType(configType);
    if (!data) {
        return;
    }

//    memset(data, 0, sizeof(&data));

    char * configPath = configPathForType(configType);
    if (configPath == NULL) {
        return;
    }

    FILE* fp = fopen( configPath, "r" );
    char configText[8192];
    int count = 0;

    if (fp != NULL) {
        fgets(configText, 8192, fp);

        char lines[64][64];

        char * split1;
        split1 = strtok(configText, "|");
        while (split1 != NULL) {
            strcpy(lines[count], split1);

            count++;
            split1 = strtok(NULL, "|");
        }

        int i;

        for (i=0; i<count; i++) {
            char * line = lines[i];
            char * split2;

            split2 = strtok(line, "=");

            if (strcmp(split2, "translucencyLevel") == 0) {
                count--;
            }
            else {
                strcpy(data->keys[i], split2);

                split2 = strtok(NULL, "=");
                strcpy(data->values[i], split2);
            }
        }
    }
    fclose(fp);

    data->numConfigEntries = count;

    free(configPath);
}
Exemplo n.º 2
0
void saveConfigWithType(int configType) {
    //This doesn't actually need to log the type
    //It's only here because there's a weird bug with saving the config,
    //which adding a log seems to resolve
    logTextP("Saving config", "/c.txt", false);

    configData *data = configDataForType(configType);
    if (!data) {
        return;
    }

    //Start size at zero bytes
    int size = 0;

    //For each config entry, add the size of the value, key and delimeters to the overall file size
    int i;
    for (i=0; i<data->numConfigEntries; i++) {
        size += strlen(data->keys[i]);
        size += strlen(data->values[i]);
        size += 2;
    }

    //Create a string big enough to accomodate all of the keys, values and delimeters
    char out[size];

    strcpy(out, "");

    //For each config entry, add its key, value and delimeters to the output string
    for (i=0; i<data->numConfigEntries; i++) {
        strncat(out, data->keys[i], strlen(data->keys[i]));
        strncat(out, "=", 1);
        strncat(out, data->values[i], strlen(data->values[i]));
        strncat(out, "|", 1);
    }


//    logInt(configType, "Saving config with type");

    char * configPath = configPathForType(configType);
    if (configPath == NULL) {
        return;
    }

    //Open the config file path for writing and save the output string to it
    FILE* fp = fopen( configPath, "w" );
    if (fp != NULL) {
        fputs(out, fp);
    }

    fclose(fp);
    free(configPath);
}
Exemplo n.º 3
0
void saveConfigWithType(int configType) {
    logIntP(configType, "Saving config with type", "/c.txt");

    configData *data = configDataForType(configType);
    if (!data) {
        return;
    }

    //Start size at zero bytes
    int size = 0;

    //For each config entry, add the size of the value, key and delimeters to the overall file size
    int i;
    for (i=0; i<data->numConfigEntries; i++) {
        size += strlen(data->keys[i]);
        size += strlen(data->values[i]);
        size += 2;
    }

    //Create a string big enough to accomodate all of the keys, values and delimeters
    char out[size];

    strcpy(out, "");

    //For each config entry, add its key, value and delimeters to the output string
    for (i=0; i<data->numConfigEntries; i++) {
        strncat(out, data->keys[i], strlen(data->keys[i]));
        strncat(out, "=", 1);
        strncat(out, data->values[i], strlen(data->values[i]));
        strncat(out, "|", 1);
    }


//    logInt(configType, "Saving config with type");

    char * configPath = configPathForType(configType);
    if (configPath == NULL) {
        return;
    }

    //Open the config file path for writing and save the output string to it
    FILE* fp = fopen( configPath, "w" );
    if (fp != NULL) {
        fputs(out, fp);
    }

    fclose(fp);
    free(configPath);
}
Exemplo n.º 4
0
char * getConfigValueForKey(char * key, int configType) {
    if (!configInitialLoad) {
        loadConfig();
    }

    configData *data = configDataForType(configType);
    if (!data) {
        return NULL;
    }

    int i;

    for (i=0; i<data->numConfigEntries; i++) {
        char * check = data->keys[i];
        if (strcmp(check, key) == 0) {
            return data->values[i];
        }
    }

    return NULL;
}
Exemplo n.º 5
0
void setConfigString(char* key, char* value, int configType) {
    if (!configInitialLoad) {
        loadConfig();
    }

    configData *data = configDataForType(configType);
    if (!data) {
        return;
    }

    //Assume that the config entry does not currently exist
    int currentIndex = -1;

    //Loop through the existing entries
    int i;
    for (i=0; i<data->numConfigEntries; i++) {
        if (strcmp(key, data->keys[i]) == 0) {
            //If the key of the current entry matches the key being added, then the config entry already exists
            //Set current index to the index of the existing entry and break
            currentIndex = i;
            break;
        }
    }

    //If the entry already exists in the array, overwrite it
    if (currentIndex > -1) {
        memset(&(data->keys[currentIndex][0]), 0, 64);
        memset(&(data->values[currentIndex][0]), 0, 64);

        strcpy(data->keys[currentIndex], key);
        strcpy(data->values[currentIndex], value);
    }

    //If the entry does not yet exist in the array, add it
    else {
        strcpy(data->keys[data->numConfigEntries], key);
        strcpy(data->values[data->numConfigEntries], value);
        data->numConfigEntries = data->numConfigEntries + 1;
    }
}