void ConvertFiles()
{
    Safir::Dob::Typesystem::BinarySerialization bin;
    boost::filesystem::path storagePath = GetStorageDirectory();

    for (boost::filesystem::directory_iterator it (storagePath);
         it != boost::filesystem::directory_iterator(); ++it)
    {
        const boost::filesystem::path path = it->path();
        const EntityIdAndHandlerId id = Filename2EntityIdAndHandlerId(*it);

        if (path.extension() == ".bin")
        {
            const size_t fileSize = static_cast<size_t>(boost::filesystem::file_size(path));
            if (fileSize == 0)
            {
                continue;
            }
            bin.resize(fileSize);

            size_t numBytesRead = 0;
            boost::filesystem::ifstream file(path, std::ios::in | std::ios::binary);
            while (file.good())
            {
                file.read(&bin[0] + numBytesRead,4096);
                numBytesRead += static_cast<size_t>(file.gcount());
            }

            if(fileSize != numBytesRead)

            {
                throw Safir::Dob::Typesystem::SoftwareViolationException(L"Stupid error in file reading, probably", __WFILE__, __LINE__);
            }
            file.close();

            const Safir::Dob::Typesystem::ObjectPtr object = Safir::Dob::Typesystem::Serialization::ToObject(bin);

            const std::wstring xml = Safir::Dob::Typesystem::Serialization::ToXml(object);
            boost::filesystem::path xmlFileName(path);
            xmlFileName.replace_extension(".xml");
            boost::filesystem::wofstream xmlFile(xmlFileName);
            xmlFile << xml;
        }
    }
}
示例#2
0
void ConvertFiles()
{
    Safir::Dob::Typesystem::BinarySerialization bin;
    boost::filesystem::path storagePath = GetStorageDirectory();

    for (boost::filesystem::directory_iterator it (storagePath);
         it != boost::filesystem::directory_iterator(); ++it)
    {
        const boost::filesystem::path path = it->path();
        const EntityIdAndHandlerId id = Filename2EntityIdAndHandlerId(*it);

        if (path.extension() == ".bin")
        {
            const size_t fileSize = static_cast<size_t>(boost::filesystem::file_size(path));
            if (fileSize == 0)
            {
                continue;
            }
            bin.resize(fileSize);

            boost::filesystem::ifstream file(path, std::ios::in | std::ios::binary);
            file.read(&bin[0],fileSize);
            const Safir::Dob::Typesystem::ObjectPtr object = Safir::Dob::Typesystem::Serialization::ToObject(bin);

            const std::string xml = Safir::Dob::Typesystem::Utilities::ToUtf8
                (Safir::Dob::Typesystem::Serialization::ToXml(object));
            boost::filesystem::path xmlFileName(path);
            xmlFileName.replace_extension(".xml");
            boost::filesystem::ofstream xmlFile(xmlFileName);
            xmlFile << xml;
            xmlFile.close();

            //make the file world read-writeable
            using namespace boost::filesystem;
            permissions(path,
                        owner_read  | owner_write  |
                        group_read  | group_write  |
                        others_read | others_write );
        }
    }
}