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); }
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); }
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); }