update libslic3r

This commit is contained in:
QIDI TECH
2025-08-04 10:13:51 +08:00
parent e3f49c2fb5
commit 8d4d60ec48
96 changed files with 4993 additions and 1903 deletions

View File

@@ -10,9 +10,11 @@
#include <boost/system/error_code.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/path.hpp>
#include <openssl/md5.h>
#include "libslic3r.h"
#include "libslic3r_version.h"
//define CLI errors
@@ -69,6 +71,7 @@
#define CLI_GCODE_PATH_IN_UNPRINTABLE_AREA -102
#define CLI_FILAMENT_UNPRINTABLE_ON_FIRST_LAYER -103
namespace boost { namespace filesystem { class directory_entry; }}
namespace Slic3r {
@@ -122,6 +125,146 @@ inline std::string convert_to_full_version(std::string short_version)
}
return result;
}
class PathSanitizer
{
public:
static std::string sanitize(const std::string &path) {
return sanitize_impl(path);
}
static std::string sanitize(std::string &&path) {
return sanitize_impl(path);
}
static std::string sanitize(const char *path) {
return path ? sanitize_impl(std::string(path)) : "";
}
static std::string sanitize(const boost::filesystem::path &path) {
return sanitize_impl(path.string());
}
private:
inline static size_t start_pos = std::string::npos;
inline static size_t id_start_pos = std::string::npos;
inline static size_t name_size = 0;
static bool init_usrname_range()
{
if (start_pos != std::string::npos) {
return true;
}
#ifdef _WIN32
const char *env = std::getenv("USERPROFILE");
#if QDT_RELEASE_TO_PUBLIC
const size_t len = strlen("\\AppData\\Roaming\\QIDIStudio\\user");
#else
const size_t len = QDT_INTERNAL_TESTING == 1 ? strlen("\\AppData\\Roaming\\QIDIStudioInternal\\user") : strlen("\\AppData\\Roaming\\QIDIStudioBeta\\user");
#endif
#elif __APPLE__
const char *env = std::getenv("HOME");
#if QDT_RELEASE_TO_PUBLIC
const size_t len = strlen("/Library/Application Support/QIDIStudio/user");
#else
const size_t len = QDT_INTERNAL_TESTING == 1 ? strlen("/Library/Application Support/QIDIStudioInternal/user") : strlen("/Library/Application Support/QIDIStudioBeta/user");
#endif
#elif __linux__
const char *env = std::getenv("HOME");
#if QDT_RELEASE_TO_PUBLIC
const size_t len = strlen("/.config/QIDIStudio/user");
#else
const size_t len = QDT_INTERNAL_TESTING == 1 ? strlen("/.config/QIDIStudioInternal/user") : strlen("/.config/QIDIStudioBeta/user");
#endif
#else
// Unsupported platform, return raw input
return false;
#endif
if (!env) {
return false;
}
std::string full(env);
size_t sep_pos = full.find_last_of("\\/");
if (sep_pos == std::string::npos) {
return false;
}
start_pos = sep_pos + 1;
name_size = full.length() - start_pos;
id_start_pos = full.length() + len + 1;
if (name_size == 0) {
return false;
}
if (start_pos + name_size > full.length()) {
return false;
}
return true;
}
static std::string sanitize_impl(const std::string &raw)
{
if (!init_usrname_range()) {
return raw;
}
if (raw.length() < start_pos + name_size) {
return raw;
}
std::string sanitized = raw;
if (raw[start_pos + name_size] == '\\' || raw[start_pos + name_size] == '/') {
sanitized.replace(start_pos, name_size, std::string(name_size, '*'));
} else if (std::isupper(raw[start_pos])) {
sanitized.replace(start_pos, 12, std::string(12, '*'));
} else {
return raw;
}
if (id_start_pos != std::string::npos && id_start_pos < sanitized.length() && (sanitized[id_start_pos - 1] == '\\' || sanitized[id_start_pos - 1] == '/') &&
std::isdigit(sanitized[id_start_pos])) {
// If the ID part is present, sanitize it as well
size_t id_end_pos = sanitized.find_first_of("\\/", id_start_pos);
if (id_end_pos == std::string::npos) {
id_end_pos = sanitized.length();
}
sanitized.replace(id_start_pos, id_end_pos - id_start_pos, std::string(id_end_pos - id_start_pos, '*'));
}
return sanitized;
}
static std::string sanitize_impl(std::string &&raw)
{
if (!init_usrname_range()) {
return raw;
}
if (raw.length() < start_pos + name_size) {
return raw;
}
if (raw[start_pos + name_size] == '\\' || raw[start_pos + name_size] == '/') {
raw.replace(start_pos, name_size, std::string(name_size, '*'));
} else if (std::isupper(raw[start_pos])) {
raw.replace(start_pos, 12, std::string(12, '*'));
} else {
return raw;
}
if (id_start_pos != std::string::npos && id_start_pos < raw.length() && (raw[id_start_pos - 1] == '\\' || raw[id_start_pos - 1] == '/') &&
std::isdigit(raw[id_start_pos])) {
// If the ID part is present, sanitize it as well
size_t id_end_pos = raw.find_first_of("\\/", id_start_pos);
if (id_end_pos == std::string::npos) {
id_end_pos = raw.length();
}
raw.replace(id_start_pos, id_end_pos - id_start_pos, std::string(id_end_pos - id_start_pos, '*'));
}
return std::move(raw);
}
};
template<typename DataType>
inline DataType round_divide(DataType dividend, DataType divisor) //!< Return dividend divided by divisor rounded to the nearest integer
{
@@ -692,6 +835,9 @@ inline std::string filter_characters(const std::string& str, const std::string&
return filteredStr;
}
void save_string_file(const boost::filesystem::path& p, const std::string& str);
void load_string_file(const boost::filesystem::path& p, std::string& str);
} // namespace Slic3r
#if WIN32