mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-13 03:31:52 +08:00
Handle input file errors gracefully
This commit is contained in:
parent
9eb28371de
commit
cba3b19be4
@ -8,6 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "boost/filesystem.hpp"
|
||||||
|
|
||||||
using namespace Slic3r;
|
using namespace Slic3r;
|
||||||
|
|
||||||
@ -33,8 +34,18 @@ main(const int argc, const char **argv)
|
|||||||
// load config files supplied via --load
|
// load config files supplied via --load
|
||||||
for (std::vector<std::string>::const_iterator file = cli_config.load.values.begin();
|
for (std::vector<std::string>::const_iterator file = cli_config.load.values.begin();
|
||||||
file != cli_config.load.values.end(); ++file) {
|
file != cli_config.load.values.end(); ++file) {
|
||||||
|
if (!boost::filesystem::exists(*file)) {
|
||||||
|
std::cout << "No such file: " << *file << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
DynamicPrintConfig c;
|
DynamicPrintConfig c;
|
||||||
c.load(*file);
|
try {
|
||||||
|
c.load(*file);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
std::cout << "Error while reading config file: " << e.what() << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
c.normalize();
|
c.normalize();
|
||||||
print_config.apply(c);
|
print_config.apply(c);
|
||||||
}
|
}
|
||||||
@ -50,9 +61,19 @@ main(const int argc, const char **argv)
|
|||||||
// read input file(s) if any
|
// read input file(s) if any
|
||||||
std::vector<Model> models;
|
std::vector<Model> models;
|
||||||
for (t_config_option_keys::const_iterator it = input_files.begin(); it != input_files.end(); ++it) {
|
for (t_config_option_keys::const_iterator it = input_files.begin(); it != input_files.end(); ++it) {
|
||||||
|
if (!boost::filesystem::exists(*it)) {
|
||||||
|
std::cout << "No such file: " << *it << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
Model model;
|
Model model;
|
||||||
// TODO: read other file formats with Model::read_from_file()
|
// TODO: read other file formats with Model::read_from_file()
|
||||||
Slic3r::IO::STL::read(*it, &model);
|
try {
|
||||||
|
Slic3r::IO::STL::read(*it, &model);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
std::cout << *it << ": " << e.what() << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (model.objects.empty()) {
|
if (model.objects.empty()) {
|
||||||
printf("Error: file is empty: %s\n", it->c_str());
|
printf("Error: file is empty: %s\n", it->c_str());
|
||||||
|
@ -8,8 +8,12 @@ namespace Slic3r { namespace IO {
|
|||||||
bool
|
bool
|
||||||
STL::read(std::string input_file, TriangleMesh* mesh)
|
STL::read(std::string input_file, TriangleMesh* mesh)
|
||||||
{
|
{
|
||||||
mesh->ReadSTLFile(input_file);
|
try {
|
||||||
mesh->check_topology();
|
mesh->ReadSTLFile(input_file);
|
||||||
|
mesh->check_topology();
|
||||||
|
} catch (...) {
|
||||||
|
throw std::runtime_error("Error while reading STL file");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ TriangleMesh::~TriangleMesh() {
|
|||||||
void
|
void
|
||||||
TriangleMesh::ReadSTLFile(const std::string &input_file) {
|
TriangleMesh::ReadSTLFile(const std::string &input_file) {
|
||||||
stl_open(&stl, input_file.c_str());
|
stl_open(&stl, input_file.c_str());
|
||||||
|
if (this->stl.error != 0) throw std::runtime_error("Failed to read STL file");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user