forked from Kolyah35/minecraft-pe-0.6.1
Fixes and enhancements from my MCPE repository. (https://github.com/mschiller890/mcpe64)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "OptionsFile.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <platform/log.h>
|
||||
|
||||
OptionsFile::OptionsFile() {
|
||||
#ifdef __APPLE__
|
||||
@@ -19,19 +20,32 @@ void OptionsFile::save(const StringVector& settings) {
|
||||
fprintf(pFile, "%s\n", it->c_str());
|
||||
}
|
||||
fclose(pFile);
|
||||
} else {
|
||||
LOGI("OptionsFile::save failed to open '%s' for writing: %s", settingsPath.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
StringVector OptionsFile::getOptionStrings() {
|
||||
StringVector returnVector;
|
||||
FILE* pFile = fopen(settingsPath.c_str(), "w");
|
||||
FILE* pFile = fopen(settingsPath.c_str(), "r");
|
||||
if(pFile != NULL) {
|
||||
char lineBuff[128];
|
||||
while(fgets(lineBuff, sizeof lineBuff, pFile)) {
|
||||
if(strlen(lineBuff) > 2)
|
||||
returnVector.push_back(std::string(lineBuff));
|
||||
// Strip trailing newline
|
||||
size_t len = strlen(lineBuff);
|
||||
while(len > 0 && (lineBuff[len-1] == '\n' || lineBuff[len-1] == '\r'))
|
||||
lineBuff[--len] = '\0';
|
||||
if(len < 3) continue;
|
||||
// Split "key:value" into two separate entries to match update() pairing
|
||||
char* colon = strchr(lineBuff, ':');
|
||||
if(colon) {
|
||||
returnVector.push_back(std::string(lineBuff, colon - lineBuff));
|
||||
returnVector.push_back(std::string(colon + 1));
|
||||
}
|
||||
}
|
||||
fclose(pFile);
|
||||
} else {
|
||||
LOGI("OptionsFile::getOptionStrings failed to open '%s' for reading: %s", settingsPath.c_str(), strerror(errno));
|
||||
}
|
||||
return returnVector;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user