예제 #1
0
파일: test.c 프로젝트: tmud/libs
static void test_append(void) {
  struct zip_t *zip = zip_open(ZIPNAME, ZIP_DEFAULT_COMPRESSION_LEVEL, 'a');
  assert(zip != NULL);

  assert(0 == zip_entry_open(zip, "test\\test-2.txt"));
  assert(0 == strcmp(zip_entry_name(zip), "test/test-2.txt"));
  assert(total_entries == zip_entry_index(zip));
  assert(0 == zip_entry_write(zip, TESTDATA2, strlen(TESTDATA2)));
  assert(strlen(TESTDATA2) == zip_entry_size(zip));
  assert(CRC32DATA2 == zip_entry_crc32(zip));

  ++total_entries;
  assert(0 == zip_entry_close(zip));

  assert(0 == zip_entry_open(zip, "test\\empty/"));
  assert(0 == strcmp(zip_entry_name(zip), "test/empty/"));
  assert(0 == zip_entry_size(zip));
  assert(0 == zip_entry_crc32(zip));

  assert(total_entries == zip_entry_index(zip));
  ++total_entries;
  assert(0 == zip_entry_close(zip));

  assert(0 == zip_entry_open(zip, "empty/"));
  assert(0 == strcmp(zip_entry_name(zip), "empty/"));
  assert(0 == zip_entry_size(zip));
  assert(0 == zip_entry_crc32(zip));

  assert(total_entries == zip_entry_index(zip));
  ++total_entries;
  assert(0 == zip_entry_close(zip));

  zip_close(zip);
}
예제 #2
0
void D3MFExporter::writeRelInfoToFile( const std::string &folder, const std::string &relName ) {
    if ( nullptr == m_zipArchive ) {
        throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
    }
    const std::string entry = folder + "/" + relName;
    zip_entry_open( m_zipArchive, entry.c_str() );

    const std::string &exportTxt( mRelOutput.str() );
    zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );

    zip_entry_close( m_zipArchive );
}
예제 #3
0
void D3MFExporter::exportContentTyp( const std::string &filename ) {
    if ( nullptr == m_zipArchive ) {
        throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
    }
    const std::string entry = filename;
    zip_entry_open( m_zipArchive, entry.c_str() );

    const std::string &exportTxt( mContentOutput.str() );
    zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );

    zip_entry_close( m_zipArchive );
}
void main_window::on_save_mission()
{
    if (m_filename.empty())
    {
        on_save_as_mission();
        return;
    }

    zip_t *zip = zip_open(m_filename.c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 0);
    if (!zip)
    {
        alert("Unable to save mission " + m_filename);
        return;
    }

    std::string str = "<!--Open Horizon mission-->\n";
    str += "<mission location=\"" + m_location + "\">\n";

    auto &p = m_scene_view->get_player();
    str += "\t<player ";
    str += "x=\"" + std::to_string(p.pos.x) + "\" ";
    str += "y=\"" + std::to_string(p.pos.y + p.y) + "\" ";
    str += "z=\"" + std::to_string(p.pos.z) + "\" ";
    str += "yaw=\"" + std::to_string(p.yaw.get_deg()) + "\" ";
    str += "editor_y=\"" + std::to_string(p.y) + "\" ";
    str += ">\n";
    str += "\t\t<attribute ";
    for (auto &a: p.attributes)
    {
        if (!a.second.empty())
            str += a.first + "=\"" + a.second + "\" ";
    }
    str += "/>\n";
    str += "\t</player>\n";

    for (auto &o: m_scene_view->get_objects())
    {
        str += "\n\t<object ";
        str += "name=\"" + o.name + "\" ";
        str += "id=\"" + o.id + "\" ";
        str += "active=\"" + to_string(o.active) + "\" ";
        str += "x=\"" + std::to_string(o.pos.x) + "\" ";
        str += "y=\"" + std::to_string(o.pos.y + o.y) + "\" ";
        str += "z=\"" + std::to_string(o.pos.z) + "\" ";
        str += "yaw=\"" + std::to_string(o.yaw.get_deg()) + "\" ";
        str += "editor_y=\"" + std::to_string(o.y) + "\" ";
        str += ">\n";
        str += "\t\t<attribute ";
        for (auto &a: o.attributes)
        {
            if (!a.second.empty())
                str += a.first + "=\"" + a.second + "\" ";
        }
        str += "/>\n";
        str += "\t</object>\n";
    }

    for (auto &z: m_scene_view->get_zones())
    {
        str += "\n\t<zone ";
        str += "name=\"" + z.name + "\" ";
        str += "active=\"" + to_string(z.active) + "\" ";
        str += "x=\"" + std::to_string(z.pos.x) + "\" ";
        str += "y=\"" + std::to_string(z.pos.y) + "\" ";
        str += "z=\"" + std::to_string(z.pos.z) + "\" ";
        str += "radius=\"" + std::to_string(z.radius) + "\" ";
        str += ">\n";
        str += "\t\t<attribute ";
        for (auto &a: z.attributes)
        {
            if (!a.second.empty())
                str += a.first + "=\"" + a.second + "\" ";
        }
        str += "/>\n";
        str += "\t</zone>\n";
    }

    for (auto &pth: m_scene_view->get_paths())
    {
        str += "\n\t<path ";
        str += "name=\"" + pth.name + "\" ";
        str += ">\n";

        for (auto &p: pth.points)
        {
            str += "\t\t<point ";
            str += "x=\"" + std::to_string(p.x) + "\" ";
            str += "y=\"" + std::to_string(p.y + p.w) + "\" ";
            str += "z=\"" + std::to_string(p.z) + "\" ";
            str += "editor_y=\"" + std::to_string(p.w) + "\" ";
            str += "/>\n";
        }

        str += "\t</path>\n";
    }

    str += "</mission>\n";

    zip_entry_open(zip, "objects.xml");
    zip_entry_write(zip, str.c_str(), str.length());
    zip_entry_close(zip);

    std::string script = to_str(m_script_edit->toPlainText());
    zip_entry_open(zip, "script.lua");
    zip_entry_write(zip, script.c_str(), script.size());
    zip_entry_close(zip);

    std::string info = "<!--Open Horizon mission info-->\n";
    info += "<info ";
    info += "name=\"" + std::string(to_str(m_mission_title->text())) + "\">\n";
    info += "\t<author name=\"" + std::string(to_str(m_mission_author->text())) + "\" ";
    info += "email=\"" + std::string(to_str(m_mission_email->text())) + "\"/>\n";
    info += "\t<description>";
    info += to_str(m_mission_description->toPlainText());
    info += "</description>\n";
    info += "</info>\n";
    zip_entry_open(zip, "info.xml");
    zip_entry_write(zip, info.c_str(), info.size());
    zip_entry_close(zip);

    zip_close(zip);
}