Restore GUI-free Web module runtimes
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Build Release / upload_src (push) Has been cancelled
Build Release / build (10.13, macos-15-intel, osx-64) (push) Has been cancelled
Build Release / build (11.0, macos-latest, osx-arm64) (push) Has been cancelled
Build Release / build (15.0, macos-latest, osx-arm64) (push) Has been cancelled
Build Release / build (ubuntu-22.04, linux-64) (push) Has been cancelled
Build Release / build (ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Build Release / build (windows-latest, win-64) (push) Has been cancelled
CodeQL Advanced (c-cpp) / Analyze (c-cpp) (push) Has been cancelled
Push Crowdin Translations / update-crowdin (push) Has been cancelled
Fetch Crowdin Translations / update-crowdin (push) Has been cancelled
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Build Release / upload_src (push) Has been cancelled
Build Release / build (10.13, macos-15-intel, osx-64) (push) Has been cancelled
Build Release / build (11.0, macos-latest, osx-arm64) (push) Has been cancelled
Build Release / build (15.0, macos-latest, osx-arm64) (push) Has been cancelled
Build Release / build (ubuntu-22.04, linux-64) (push) Has been cancelled
Build Release / build (ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Build Release / build (windows-latest, win-64) (push) Has been cancelled
CodeQL Advanced (c-cpp) / Analyze (c-cpp) (push) Has been cancelled
Push Crowdin Translations / update-crowdin (push) Has been cancelled
Fetch Crowdin Translations / update-crowdin (push) Has been cancelled
This commit is contained in:
@@ -104,8 +104,20 @@ using namespace zipios;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace App
|
||||
{
|
||||
namespace App
|
||||
{
|
||||
|
||||
static std::string webRestoreStage;
|
||||
|
||||
extern "C" const char* fc_web_document_restore_stage()
|
||||
{
|
||||
return webRestoreStage.c_str();
|
||||
}
|
||||
|
||||
extern "C" void fc_web_document_restore_property(const char* name)
|
||||
{
|
||||
webRestoreStage = std::string("property:") + (name ? name : "<null>");
|
||||
}
|
||||
|
||||
static bool globalIsRestoring;
|
||||
static bool globalIsRelabeling;
|
||||
@@ -1118,14 +1130,16 @@ void Document::Save(Base::Writer& writer) const
|
||||
writer.Stream() << "</Document>" << '\n';
|
||||
}
|
||||
|
||||
void Document::Restore(Base::XMLReader& reader)
|
||||
{
|
||||
void Document::Restore(Base::XMLReader& reader)
|
||||
{
|
||||
webRestoreStage = "document-start";
|
||||
d->hashers.clear();
|
||||
d->touchedObjs.clear();
|
||||
addStringHasher(d->Hasher);
|
||||
setStatus(Document::PartialDoc, false);
|
||||
|
||||
reader.readElement("Document");
|
||||
webRestoreStage = "document-header";
|
||||
reader.readElement("Document");
|
||||
const long scheme = reader.getAttribute<long>("SchemaVersion");
|
||||
reader.DocumentSchema = static_cast<int>(scheme);
|
||||
if (reader.hasAttribute("ProgramVersion")) {
|
||||
@@ -1161,6 +1175,7 @@ void Document::Restore(Base::XMLReader& reader)
|
||||
// read the Document Properties, when reading in Uid the transient directory gets renamed
|
||||
// automatically
|
||||
try {
|
||||
webRestoreStage = "document-properties";
|
||||
PropertyContainer::Restore(reader);
|
||||
}
|
||||
catch (const std::out_of_range& error) {
|
||||
@@ -1207,6 +1222,7 @@ void Document::Restore(Base::XMLReader& reader)
|
||||
else if (scheme >= 3) {
|
||||
// read the feature types
|
||||
try {
|
||||
webRestoreStage = "objects";
|
||||
readObjects(reader);
|
||||
}
|
||||
catch (const std::out_of_range& error) {
|
||||
@@ -1215,11 +1231,14 @@ void Document::Restore(Base::XMLReader& reader)
|
||||
|
||||
// tip object handling. First the whole document has to be read, then we
|
||||
// can restore the Tip link out of the TipName Property:
|
||||
Tip.setValue(getObject(TipName.getValue()));
|
||||
webRestoreStage = "tip";
|
||||
Tip.setValue(getObject(TipName.getValue()));
|
||||
}
|
||||
|
||||
reader.readEndElement("Document");
|
||||
}
|
||||
webRestoreStage = "document-end";
|
||||
reader.readEndElement("Document");
|
||||
webRestoreStage = "document-complete";
|
||||
}
|
||||
|
||||
void DocumentP::checkStringHasher(const Base::XMLReader& reader)
|
||||
{
|
||||
@@ -1544,7 +1563,8 @@ std::vector<DocumentObject*> Document::readObjects(Base::XMLReader& reader)
|
||||
|
||||
|
||||
// read the object types
|
||||
reader.readElement("Objects");
|
||||
webRestoreStage = "objects-header";
|
||||
reader.readElement("Objects");
|
||||
int Cnt = static_cast<int>(reader.getAttribute<long>("Count"));
|
||||
|
||||
if (!reader.hasAttribute(fcAttrDependencies)) {
|
||||
@@ -1598,6 +1618,7 @@ std::vector<DocumentObject*> Document::readObjects(Base::XMLReader& reader)
|
||||
|
||||
long lastId = 0;
|
||||
for (int i = 0; i < Cnt; i++) {
|
||||
webRestoreStage = "object-declaration";
|
||||
reader.readElement("Object");
|
||||
std::string type = reader.getAttribute<const char*>("type");
|
||||
std::string name = reader.getAttribute<const char*>("name");
|
||||
@@ -1686,20 +1707,23 @@ std::vector<DocumentObject*> Document::readObjects(Base::XMLReader& reader)
|
||||
|
||||
// read the features itself
|
||||
reader.clearPartialRestoreDocumentObject();
|
||||
reader.readElement("ObjectData");
|
||||
webRestoreStage = "object-data-header";
|
||||
reader.readElement("ObjectData");
|
||||
Cnt = static_cast<int>(reader.getAttribute<long>("Count"));
|
||||
for (int i = 0; i < Cnt; i++) {
|
||||
reader.readElement("Object");
|
||||
webRestoreStage = "object-data-entry";
|
||||
reader.readElement("Object");
|
||||
std::string name = reader.getName(reader.getAttribute<const char*>("name"));
|
||||
if (DocumentObject* pObj = getObject(name.c_str()); pObj
|
||||
&& !pObj->testStatus(
|
||||
PartialObject)) { // check if this feature has been registered
|
||||
pObj->setStatus(ObjectStatus::Restore, true);
|
||||
try {
|
||||
FC_TRACE("restoring " << pObj->getFullName());
|
||||
pObj->Restore(reader);
|
||||
}
|
||||
// Try to continue only for certain exception types if not handled
|
||||
try {
|
||||
FC_TRACE("restoring " << pObj->getFullName());
|
||||
webRestoreStage = std::string("object-properties:") + name;
|
||||
pObj->Restore(reader);
|
||||
}
|
||||
// Try to continue only for certain exception types if not handled
|
||||
// by the feature type. For all other exception types abort the process.
|
||||
catch (const Base::UnicodeError& e) {
|
||||
e.reportException();
|
||||
@@ -1726,9 +1750,11 @@ std::vector<DocumentObject*> Document::readObjects(Base::XMLReader& reader)
|
||||
reader.clearPartialRestoreDocumentObject();
|
||||
}
|
||||
}
|
||||
reader.readEndElement("Object");
|
||||
webRestoreStage = "object-data-end";
|
||||
reader.readEndElement("Object");
|
||||
}
|
||||
reader.readEndElement("ObjectData");
|
||||
webRestoreStage = "object-data-complete";
|
||||
reader.readEndElement("ObjectData");
|
||||
|
||||
return objs;
|
||||
}
|
||||
@@ -2146,7 +2172,7 @@ void Document::restore(const char* filename,
|
||||
if (file.gcount() != static_cast<std::streamsize>(archive.size())) {
|
||||
throw Base::FileException("Unable to read project file", filename);
|
||||
}
|
||||
std::istringstream archiveStream(std::move(archive), std::ios::in | std::ios::binary);
|
||||
std::istringstream archiveStream(archive, std::ios::in | std::ios::binary);
|
||||
std::unique_ptr<zipios::ZipInputStream> zipstreamPtr;
|
||||
try {
|
||||
zipstreamPtr = std::make_unique<zipios::ZipInputStream>(archiveStream);
|
||||
@@ -2191,10 +2217,10 @@ void Document::restore(const char* filename,
|
||||
catch (const std::exception& e) {
|
||||
throw Base::RuntimeError(std::string("Document::Restore: ") + e.what());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().error("Invalid Document.xml: %s\n", e.what());
|
||||
setStatus(Document::RestoreError, true);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().error("Invalid Document.xml: %s\n", e.what());
|
||||
setStatus(Document::RestoreError, true);
|
||||
}
|
||||
|
||||
d->partialLoadObjects.clear();
|
||||
d->programVersion = reader.ProgramVersion;
|
||||
@@ -2203,22 +2229,40 @@ void Document::restore(const char* filename,
|
||||
// exist, what is done in Restore().
|
||||
// Note: This file doesn't need to be available if the document has been created
|
||||
// without GUI. But if available then follow after all data files of the App document.
|
||||
webRestoreStage = "signal-restore";
|
||||
try {
|
||||
signalRestoreDocument(reader);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw Base::RuntimeError(std::string("signalRestoreDocument: ") + e.what());
|
||||
}
|
||||
webRestoreStage = "document-files";
|
||||
try {
|
||||
#ifdef FC_OS_EMSCRIPTEN
|
||||
archiveStream.clear();
|
||||
// Keep the original stream positioned by the XML reader. The Web
|
||||
// reader normalizes its exception state before probing auxiliary data.
|
||||
zipstream.exceptions(std::ios::goodbit);
|
||||
zipstream.clear(std::ios::goodbit);
|
||||
#else
|
||||
file.clear();
|
||||
#endif
|
||||
webRestoreStage = "document-files-read";
|
||||
#ifdef FC_OS_EMSCRIPTEN
|
||||
reader.readFiles(zipstream);
|
||||
#else
|
||||
reader.readFiles(zipstream);
|
||||
#endif
|
||||
webRestoreStage = "document-files-complete";
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
throw Base::RuntimeError(std::string("Document data files: ") + e.what());
|
||||
std::string streamState;
|
||||
#ifdef FC_OS_EMSCRIPTEN
|
||||
streamState = " [archive=" + std::to_string(archiveStream.rdstate());
|
||||
#else
|
||||
streamState = " [archive=file";
|
||||
#endif
|
||||
streamState += ", zip=" + std::to_string(zipstream.rdstate()) + "]";
|
||||
throw Base::RuntimeError(std::string("Document data files: ") + e.what() + streamState);
|
||||
}
|
||||
|
||||
DocumentP::checkStringHasher(reader);
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "Property.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
extern "C" void fc_web_document_restore_property(const char* name);
|
||||
|
||||
|
||||
FC_LOG_LEVEL_INIT("App",true,true)
|
||||
|
||||
@@ -361,6 +363,7 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
|
||||
&& !status.test(Property::PropTransient)
|
||||
&& !prop->testStatus(Property::PropTransient))
|
||||
{
|
||||
fc_web_document_restore_property(prop->getName());
|
||||
FC_TRACE("restore property '" << prop->getName() << "'");
|
||||
prop->Restore(reader);
|
||||
}else
|
||||
|
||||
Reference in New Issue
Block a user