diff options
Diffstat (limited to 'src/PrintMonitor.cpp')
-rw-r--r-- | src/PrintMonitor.cpp | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/src/PrintMonitor.cpp b/src/PrintMonitor.cpp index b2181ee4..102ba4aa 100644 --- a/src/PrintMonitor.cpp +++ b/src/PrintMonitor.cpp @@ -396,68 +396,53 @@ bool PrintMonitor::GetFileInfo(const char *directory, const char *fileName, GCod { // Slic3r and S3D const char* generatedByString = "generated by "; - char* pos = strstr(buf, generatedByString); + const char* introString = ""; + const char* pos = strstr(buf, generatedByString); if (pos != nullptr) { pos += strlen(generatedByString); - size_t i = 0; - while (i < ARRAY_SIZE(parsedFileInfo.generatedBy) - 1 && *pos >= ' ') + } + else + { + // KISSlicer + pos = strstr(buf, "; KISSlicer"); + if (pos != nullptr) + { + pos += 2; + } + else { - char c = *pos++; - if (c == '"' || c == '\\') + // Cura (old) + const char* slicedAtString = ";Sliced at: "; + pos = strstr(buf, slicedAtString); + if (pos != nullptr) { - // Need to escape the quote-mark for JSON - if (i > ARRAY_SIZE(parsedFileInfo.generatedBy) - 3) + pos += strlen(slicedAtString); + introString = "Cura at "; + } + else + { + // Cura (new) + const char* generatedWithString = ";Generated with "; + pos = strstr(buf, generatedWithString); + if (pos != nullptr) { - break; + pos += strlen(generatedWithString); } - parsedFileInfo.generatedBy[i++] = '\\'; } - parsedFileInfo.generatedBy[i++] = c; } - parsedFileInfo.generatedBy[i] = 0; } - // Cura - const char* slicedAtString = ";Sliced at: "; - pos = strstr(buf, slicedAtString); if (pos != nullptr) { - pos += strlen(slicedAtString); - strcpy(parsedFileInfo.generatedBy, "Cura at "); - size_t i = 8; + strcpy(parsedFileInfo.generatedBy, introString); + size_t i = strlen(introString); while (i < ARRAY_SIZE(parsedFileInfo.generatedBy) - 1 && *pos >= ' ') { - char c = *pos++; - if (c == '"' || c == '\\') - { - if (i > ARRAY_SIZE(parsedFileInfo.generatedBy) - 3) - { - break; - } - parsedFileInfo.generatedBy[i++] = '\\'; - } - parsedFileInfo.generatedBy[i++] = c; + parsedFileInfo.generatedBy[i++] = *pos++; } parsedFileInfo.generatedBy[i] = 0; } - - // KISSlicer - const char* kisslicerStart = "; KISSlicer"; - if (StringStartsWith(buf, kisslicerStart)) - { - size_t stringLength = 0; - for(size_t i = 2; i < ARRAY_UPB(parsedFileInfo.generatedBy); i++) - { - if (buf[i] == '\r' || buf[i] == '\n') - { - break; - } - - parsedFileInfo.generatedBy[stringLength++] = buf[i]; - } - parsedFileInfo.generatedBy[stringLength] = 0; - } } headerInfoComplete &= (parsedFileInfo.generatedBy[0] != 0); @@ -638,7 +623,9 @@ bool PrintMonitor::GetFileInfoResponse(const char *filename, OutputBuffer *&resp ch = ','; } } - response->catf("],\"generatedBy\":\"%s\"}", info.generatedBy); + response->cat("],\"generatedBy\":"); + response->EncodeString(info.generatedBy, ARRAY_SIZE(info.generatedBy), false); + response->cat("}"); } else { @@ -1110,14 +1097,38 @@ unsigned int PrintMonitor::FindFilamentUsed(const char* buf, size_t len, float * } if (isDigit(*p)) { - char* q; - filamentUsed[filamentsFound] = strtod(p, &q); // S3D reports filament usage in mm, no conversion needed + filamentUsed[filamentsFound] = strtod(p, nullptr); // S3D reports filament usage in mm, no conversion needed + ++filamentsFound; + } + } + } + + // Look for filament usage as generated by recent KISSlicer versions + if (!filamentsFound) + { + const char *filamentLengthStr = "; Ext "; + p = buf; + while (filamentsFound < maxFilaments && (p = strstr(p, filamentLengthStr)) != nullptr) + { + p += strlen(filamentLengthStr); + while(isdigit(*p)) + { + ++p; + } + while(strchr(" :=\t", *p) != nullptr) + { + ++p; + } + + if (isDigit(*p)) + { + filamentUsed[filamentsFound] = strtod(p, nullptr); ++filamentsFound; } } } - // Special case: KISSlicer only generates the filament volume, so we need to calculate the length from it + // Special case: Old KISSlicer only generates the filament volume, so we need to calculate the length from it if (!filamentsFound) { const char *filamentVolumeStr = "; Estimated Build Volume: "; |