Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Onur Rauf Bingol committed Apr 18, 2019
1 parent 6020439 commit 80c4f11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
25 changes: 15 additions & 10 deletions src/json2on/json2on.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,30 @@ bool json2on(std::string &jsonString, Config &cfg, std::string &fileName)

std::string json2on_run(std::string &fileName, Config &cfg)
{
// Save file name
std::string fnameSave;

// Open JSON file
std::ifstream fp(fileName);
if (!fp)
{
if (!cfg.silent())
std::cout << "[ERROR] Cannot open file '" << fileName << "' for reading" << std::endl;
return false;
}
else
{
// Read file to a string
std::stringstream buffer;
buffer << fp.rdbuf();
std::string jsonString = buffer.str();

// Read file to a string
std::stringstream buffer;
buffer << fp.rdbuf();
std::string jsonString = buffer.str();
// Prepare save file name
fnameSave = fileName.substr(0, fileName.find_last_of(".")) + ".3dm";

// Prepare save file name
std::string fnameSave = fileName.substr(0, fileName.find_last_of(".")) + ".3dm";
// Convert geometry to .3dm format
if (!json2on(jsonString, cfg, fnameSave))
fnameSave.clear();
}

// Convert geometry to .3dm format
if (!json2on(jsonString, cfg, fnameSave))
fnameSave.clear();
return fnameSave;
}
12 changes: 7 additions & 5 deletions src/on2json/on2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,17 @@ std::string on2json_run(std::string &fileName, Config &cfg)
fnameSave = fileName.substr(0, fileName.find_last_of(".")) + ".json";
std::ofstream fileSave(fnameSave.c_str(), std::ios::out);
if (!fileSave)
{
// Save JSON string to the file
fileSave << jsonString << std::endl;
fileSave.close();
}
else
{
if (!cfg.silent())
std::cout << "[ERROR] Cannot open file '" << fnameSave << "' for writing!" << std::endl;
return false;
fnameSave.clear();
}

// Save JSON string to the file
fileSave << jsonString << std::endl;
fileSave.close();
}

return fnameSave;
Expand Down

0 comments on commit 80c4f11

Please sign in to comment.