Esempio n. 1
0
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
{
    Base::FileInfo fi(_cValue.c_str());
    if (fi.exists() && !fi.isWritable()) {
        // This happens when an object is being restored and tries to reference the
        // same file of another object (e.g. for copy&paste of objects inside the same document).
        return;
    }
    Base::ofstream to(fi, std::ios::out | std::ios::binary);
    if (!to) {
        std::stringstream str;
        str << "PropertyFileIncluded::RestoreDocFile(): "
            << "File '" << _cValue << "' in transient directory cannot be created.";
        throw Base::FileSystemError(str.str());
    }

    // copy plain data
    aboutToSetValue();
    unsigned char c;
    while (reader.get((char&)c)) {
        to.put((char)c);
    }
    to.close();

    // set read-only after restoring the file
    fi.setPermissions(Base::FileInfo::ReadOnly);
    hasSetValue();
}
void PropertyPythonObject::RestoreDocFile(Base::Reader &reader)
{
    aboutToSetValue();
    std::string buffer;
    char c;
    while (reader.get(c)) {
        buffer.push_back(c);
    }
    this->fromString(buffer);
    hasSetValue();
}
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
{
    Base::ofstream to(Base::FileInfo(_cValue.c_str()));
    if (!to) 
        throw Base::Exception("PropertyFileIncluded::RestoreDocFile() "
        "File in document transient dir deleted");

    // copy plain data
    aboutToSetValue();
    unsigned char c;
    while (reader.get((char&)c)) {
        to.put((const char)c);
    }
    to.close();
    hasSetValue();
}
void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
{
    Base::FileInfo fi(_cValue.c_str());
    Base::ofstream to(fi, std::ios::out | std::ios::binary);
    if (!to) {
        std::stringstream str;
        str << "PropertyFileIncluded::RestoreDocFile(): "
            << "File '" << _cValue << "' in transient directory doesn't exist.";
        throw Base::Exception(str.str());
    }

    // copy plain data
    aboutToSetValue();
    unsigned char c;
    while (reader.get((char&)c)) {
        to.put((const char)c);
    }
    to.close();

    // set read-only after restoring the file
    fi.setPermissions(Base::FileInfo::ReadOnly);
    hasSetValue();
}