diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index d07690b73b..31bd02ad10 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -741,7 +741,8 @@ ConfigSubstitutions ConfigBase::load(const std::string& filename, ForwardCompati if (file == nullptr) throw Slic3r::RuntimeError("Error opening the file: " + filename + "\n"); - file_type = (bgcode::core::is_valid_binary_gcode(*file, true) == bgcode::core::EResult::Success) ? EFileType::BinaryGCode : EFileType::AsciiGCode; + std::vector cs_buffer(65536); + file_type = (bgcode::core::is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == bgcode::core::EResult::Success) ? EFileType::BinaryGCode : EFileType::AsciiGCode; fclose(file); } else @@ -1070,7 +1071,8 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f if (file.f == nullptr) throw Slic3r::RuntimeError(format("Error opening the file: %1%", filename)); - bgcode::core::EResult res = bgcode::core::is_valid_binary_gcode(*file.f); + std::vector cs_buffer(65536); + bgcode::core::EResult res = bgcode::core::is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%", std::string(bgcode::core::translate_result(res)))); @@ -1083,7 +1085,7 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(bgcode::core::translate_result(res)))); bgcode::core::BlockHeader block_header; - res = read_next_block_header(*file.f, file_header, block_header, bgcode::core::EBlockType::SlicerMetadata, true); + res = read_next_block_header(*file.f, file_header, block_header, bgcode::core::EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(bgcode::core::translate_result(res)))); if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::SlicerMetadata) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 4953bdbdc4..f16777d384 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1041,7 +1041,8 @@ void GCodeProcessor::process_file(const std::string& filename, std::function cs_buffer(65536); + const bool is_binary = bgcode::core::is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == bgcode::core::EResult::Success; fclose(file); if (is_binary) @@ -1134,8 +1135,6 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct const long file_size = ftell(file.f); rewind(file.f); - bgcode::core::set_checksum_max_cache_size(1024); - // read file header bgcode::core::FileHeader file_header; bgcode::core::EResult res = bgcode::core::read_header(*file.f, file_header, nullptr); @@ -1143,11 +1142,10 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct throw Slic3r::RuntimeError("File: " + filename + "does not contain a valid binary gcode\n Error: " + std::string(bgcode::core::translate_result(res)) + "\n"); - const bool verify_checksum = true; - // read file metadata block bgcode::core::BlockHeader block_header; - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + std::vector cs_buffer(65536); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::FileMetadata) @@ -1164,7 +1162,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct m_producer = EProducer::Unknown; // read printer metadata block - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::PrinterMetadata) @@ -1184,7 +1182,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct #endif // ENABLE_BINARIZED_GCODE_WIN_DEBUG // read thumbnail blocks - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); @@ -1217,7 +1215,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct } #endif // ENABLE_BINARIZED_GCODE_DEBUG - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); } @@ -1240,7 +1238,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct #endif // ENABLE_BINARIZED_GCODE_WIN_DEBUG // read slicer metadata block - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::SlicerMetadata) @@ -1275,7 +1273,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct initialize_result_moves(); // read gcodes block - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::GCode) @@ -1295,7 +1293,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct if (ftell(file.f) == file_size) break; - res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, verify_checksum); + res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size()); if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n"); } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 45e4d0535f..34cae91a7e 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -883,7 +883,8 @@ ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, Forw FILE* file = boost::nowide::fopen(path.c_str(), "rb"); if (file == nullptr) throw Slic3r::RuntimeError("Error opening the file: " + path + "\n"); - const bool is_binary = bgcode::core::is_valid_binary_gcode(*file, true) == bgcode::core::EResult::Success; + std::vector cs_buffer(65536); + const bool is_binary = bgcode::core::is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == bgcode::core::EResult::Success; fclose(file); DynamicPrintConfig config;