Send only original files

When we re-serialize them, the XML file will not be exactly the same so the signature will fail to match. We need to send the original bytes.

This changes the behaviour: It now sends all non-default files instead of all files that were loaded fully.

Contributes to issue CURA-5034.
This commit is contained in:
Ghostkeeper 2018-06-08 16:02:00 +02:00
parent ddb80be1ec
commit 4727340ae4
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A
2 changed files with 16 additions and 27 deletions

View file

@ -1,11 +1,15 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Set, TYPE_CHECKING
import os #To walk over material files.
import os.path #To filter on material files.
from typing import TYPE_CHECKING
from UM.Settings.ContainerRegistry import ContainerRegistry #To get the material profiles we need to send.
from UM.Job import Job #The interface we're implementing.
from UM.Logger import Logger
from UM.Resources import Resources
from cura.CuraApplication import CuraApplication
if TYPE_CHECKING:
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
@ -14,20 +18,19 @@ if TYPE_CHECKING:
#
# This way it won't freeze up the interface while sending those materials.
class SendMaterialJob(Job):
def __init__(self, material_ids: Set[str], device: "NetworkedPrinterDevice"):
def __init__(self, device: "NetworkedPrinterDevice"):
super().__init__()
self.material_ids = material_ids
self.device = device
def run(self):
container_registry = ContainerRegistry.getInstance()
for material_id in self.material_ids:
Logger.log("d", "Syncing material profile with printer: {material_id}".format(material_id = material_id))
for file_path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.MaterialInstanceContainer):
if not file_path.startswith(Resources.getDataStoragePath() + os.sep):
continue
_, file_name = os.path.split(file_path)
Logger.log("d", "Syncing material profile with printer: {file_name}".format(file_name = file_name))
parts = []
material = container_registry.findContainers(id = material_id)[0]
serialized_material = material.serialize().encode("utf-8")
parts.append(self.device._createFormPart("name=\"file\"; filename=\"{file_name}.xml.fdm_material\"".format(file_name = material_id), serialized_material))
parts.append(self.device._createFormPart("name=\"filename\"", (material_id + ".xml.fdm_material").encode("utf-8"), "text/plain"))
with open(file_path, "rb") as f:
parts.append(self.device._createFormPart("name=\"file\"; filename=\"{file_name}\"".format(file_name = file_name), f.read()))
parts.append(self.device._createFormPart("name=\"filename\"", file_name.encode("utf-8"), "text/plain"))
self.device.postFormWithParts(target = "/materials", parts = parts)