コード例 #1
0
bool FileContainerTemporary::save_temporary() const
{
	xmlpp::Document document;
	xmlpp::Element *root = document.create_root_node("temporary-container");
	root->add_child("container-filename")->set_child_text(container_filename_);
	xmlpp::Element *files = root->add_child("files");
	for(FileMap::const_iterator i = files_.begin(); i != files_.end(); i++)
	{
		xmlpp::Element *entry = files->add_child("entry");
		entry->add_child("name")->set_child_text(i->second.name);
		entry->add_child("tmp-basename")->set_child_text(basename(i->second.tmp_filename));
		entry->add_child("is-directory")->set_child_text(i->second.is_directory ? "true" : "false");
		entry->add_child("is-removed")->set_child_text(i->second.is_removed ? "true" : "false");
	}

	FileSystem::WriteStreamHandle stream =
		file_system_->get_write_stream(
			get_temporary_directory()
		  + get_temporary_filename_base());
	if (!stream) return false;
	stream = new ZWriteStream(stream);
	try
	{
		document.write_to_stream_formatted(*stream, "UTF-8");
	}
	catch(...)
	{
		synfig::error("FileContainerTemporary::save_temporary(): Caught unknown exception");
		return false;
	}
	stream.reset();

	return true;
}
コード例 #2
0
ファイル: savecanvas.cpp プロジェクト: ZurbaXI/synfig
bool
synfig::save_canvas(const FileSystem::Identifier &identifier, Canvas::ConstHandle canvas, bool safe)
{
    ChangeLocale change_locale(LC_NUMERIC, "C");

    synfig::String tmp_filename(safe ? identifier.filename+".TMP" : identifier.filename);

    try
    {
        assert(canvas);
        xmlpp::Document document;

        encode_canvas_toplevel(document.create_root_node("canvas"),canvas);

        FileSystem::WriteStreamHandle stream = identifier.file_system->get_write_stream(tmp_filename);
        if (!stream)
        {
            synfig::error("synfig::save_canvas(): Unable to open file for write");
            return false;
        }

        if (filename_extension(identifier.filename) == ".sifz")
            stream = FileSystem::WriteStreamHandle(new ZWriteStream(stream));

        document.write_to_stream_formatted(*stream, "UTF-8");

        // close stream
        stream.reset();

        if (safe)
        {
#ifdef _WIN32
            // On Win32 platforms, rename() has bad behavior. work around it.
            char old_file[80]="sif.XXXXXXXX";
            mktemp(old_file);
            identifier.file_system->file_rename(identifier.filename,old_file);
            if(!identifier.file_system->file_rename(tmp_filename,identifier.filename))
            {
                identifier.file_system->file_rename(old_file,tmp_filename);
                synfig::error("synfig::save_canvas(): Unable to rename file to correct filename");
                return false;
            }
            identifier.file_system->file_remove(old_file);
#else
            if(!identifier.file_system->file_rename(tmp_filename, identifier.filename))
            {
                synfig::error("synfig::save_canvas(): Unable to rename file to correct filename");
                return false;
            }
#endif
        }
    }
    catch(...) {
        synfig::error("synfig::save_canvas(): Caught unknown exception");
        return false;
    }

    return true;
}
コード例 #3
0
ファイル: savecanvas.cpp プロジェクト: BakaMANIA/synfig
bool
synfig::save_canvas(const FileSystem::Identifier &identifier, Canvas::ConstHandle canvas, bool safe)
{
    ChangeLocale change_locale(LC_NUMERIC, "C");

    synfig::String tmp_filename(safe ? identifier.filename+".TMP" : identifier.filename);

	try
	{
		assert(canvas);
		xmlpp::Document document;

		encode_canvas_toplevel(document.create_root_node("canvas"),canvas);

		FileSystem::WriteStreamHandle stream = identifier.file_system->get_write_stream(tmp_filename);
		if (!stream)
		{
			synfig::error("synfig::save_canvas(): Unable to open file for write");
			return false;
		}

		if (filename_extension(identifier.filename) == ".sifz")
			stream = FileSystem::WriteStreamHandle(new ZWriteStream(stream));

		document.write_to_stream_formatted(*stream, "UTF-8");

		// close stream
		stream.reset();

		if (safe)
		{
			if(!identifier.file_system->file_rename(tmp_filename, identifier.filename))
			{
				synfig::error("synfig::save_canvas(): Unable to rename file to correct filename");
				return false;
			}
		}
	}
	catch(...) { synfig::error("synfig::save_canvas(): Caught unknown exception"); return false; }

	return true;
}