Added error checking for config.json
This commit is contained in:
@@ -25,20 +25,21 @@ int main(int argc, const char * argv[])
|
||||
// =============================
|
||||
// Load cJSON config.json file
|
||||
// =============================
|
||||
// Starting with Error Checking
|
||||
std::string configPath = "src/config/config.json";
|
||||
std::ifstream fin(configPath);
|
||||
|
||||
if(fin.is_open()){
|
||||
// std::cout<<"config.json is opened successfully"<<std::endl;
|
||||
std::ifstream jsonText("src/config/config.json");
|
||||
std::ostringstream tmp;
|
||||
tmp << jsonText.rdbuf();
|
||||
std::string json = tmp.str();
|
||||
cJSON * myJSON = cJSON_Parse(json.c_str());
|
||||
cJSON * windowName = cJSON_GetObjectItemCaseSensitive(myJSON, "WindowName");
|
||||
// if (cJSON_IsString(windowName) && (windowName->valuestring != NULL))
|
||||
// {
|
||||
// printf("Window Name is: %s\n", windowName->valuestring);
|
||||
// }
|
||||
cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize");
|
||||
int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint;
|
||||
int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
|
||||
// printf("Window:\nwidth:%d\nheight:%d\n",windowWidth,windowHeight);
|
||||
int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
|
||||
int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
|
||||
bool isWindowFS;
|
||||
@@ -73,5 +74,15 @@ int main(int argc, const char * argv[])
|
||||
|
||||
}
|
||||
game->clean();
|
||||
} else {
|
||||
std::cout<<"config.json not found or opened"<<std::endl;
|
||||
}
|
||||
|
||||
if(fin.fail()){
|
||||
std::cout<<"config.json load failed"<<std::endl;
|
||||
} else{
|
||||
// std::cout<<"config.json loaded"<<std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user