mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
IfcConvert: check if output file already exists and ask user for confirmation for overwriting. Overwriting can be forced with -y/--yes
This commit is contained in:
@@ -95,6 +95,13 @@ std::string change_extension(const std::string& fn, const std::string& ext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool file_exists(const std::string& filename)
|
||||||
|
{
|
||||||
|
/// @todo Windows Unicode support
|
||||||
|
std::ifstream file(filename.c_str());
|
||||||
|
return file.good();
|
||||||
|
}
|
||||||
|
|
||||||
static std::stringstream log_stream;
|
static std::stringstream log_stream;
|
||||||
void write_log();
|
void write_log();
|
||||||
|
|
||||||
@@ -103,7 +110,8 @@ int main(int argc, char** argv) {
|
|||||||
generic_options.add_options()
|
generic_options.add_options()
|
||||||
("help,h", "display usage information")
|
("help,h", "display usage information")
|
||||||
("version", "display version information")
|
("version", "display version information")
|
||||||
("verbose,v", "more verbose output");
|
("verbose,v", "more verbose output")
|
||||||
|
("yes,y", "answer 'yes' automatically to possible confirmation queries (e.g overwriting an existing output file)");
|
||||||
|
|
||||||
boost::program_options::options_description fileio_options;
|
boost::program_options::options_description fileio_options;
|
||||||
fileio_options.add_options()
|
fileio_options.add_options()
|
||||||
@@ -285,6 +293,15 @@ int main(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file_exists(output_filename) && !vmap.count("yes")) {
|
||||||
|
std::string answer;
|
||||||
|
std::cout << "A file '" << output_filename << "' already exists. Overwrite the existing file?" << std::endl;
|
||||||
|
std::cin >> answer;
|
||||||
|
if (!boost::iequals(answer, "yes") && !boost::iequals(answer, "y")) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string output_extension = output_filename.substr(output_filename.size()-4);
|
std::string output_extension = output_filename.substr(output_filename.size()-4);
|
||||||
boost::to_lower(output_extension);
|
boost::to_lower(output_extension);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user