/* Decompress infile in dest_dir. */ static void decompress_infile (GsfInfile *infile, gchar *dest_dir) { GError *err = (GError *) NULL; int j = 0; for (j = 0; j < gsf_infile_num_children (infile); j++) { GsfInput *child = gsf_infile_child_by_index (infile, j); char const* filename = gsf_input_name (child); gboolean is_dir = gsf_infile_num_children (GSF_INFILE (child)) >= 0; if (is_dir) { gchar *dir_path = g_build_filename (dest_dir, filename, (gchar *) 0); decompress_infile (GSF_INFILE (child), dir_path); g_free (dir_path); } else { gchar *file_path = g_build_filename (dest_dir, filename, (gchar *) 0); GsfOutput *output = GSF_OUTPUT (gsf_output_stdio_new (file_path, &err)); gsf_input_copy (child, output); gsf_output_close (output); g_object_unref (output); g_free (file_path); } g_object_unref (G_OBJECT (child)); } }
/* Add the filename under path to the gst_outfile. */ static void add_file_to_gst_outfile (GsfOutfile *out_file, gchar *path, const gchar *file_name) { GError *err = (GError *) NULL; gchar *file_path = g_build_filename (path, file_name, NULL); GsfInput *input = GSF_INPUT (gsf_input_stdio_new (file_path, &err)); GsfOutput *child = gsf_outfile_new_child (out_file, file_name, FALSE); gsf_input_copy (input, child); gsf_output_close (child); g_object_unref (child); g_object_unref (input); g_free (file_path); }
static int test (char *argv[]) { GsfInput *input; GsfOutput *output; GError *err = NULL; int rval = 0; input = gsf_input_stdio_new (argv[1], &err); if (input == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s\n", argv[1], err->message); g_error_free (err); return 1; } output = gsf_output_stdio_new (argv[2], &err); if (output == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s\n", argv[2], err->message); g_error_free (err); g_object_unref (G_OBJECT (input)); return 1; } if (gsf_input_copy (input, output) == FALSE) { rval = 1; err = (GError*) gsf_output_error (output); if (err != NULL) { g_warning ("'%s' error: %s\n", argv[2], err->message); } } g_object_unref (G_OBJECT (input)); gsf_output_close (output); g_object_unref (G_OBJECT (output)); return rval; }
UT_Error IE_Imp_EPUB::uncompress() { m_tmpDir = UT_go_filename_to_uri(g_get_tmp_dir()); m_tmpDir += G_DIR_SEPARATOR_S; m_tmpDir += getDoc()->getDocUUIDString(); if (!UT_go_directory_create(m_tmpDir.c_str(), 0644, NULL)) { UT_DEBUGMSG(("Can`t create temporary directory\n")); return UT_ERROR; } GsfInput *opsDirInput = gsf_infile_child_by_name(m_epub, m_opsDir.c_str()); UT_DEBUGMSG(("Child count : %d", gsf_infile_num_children(m_epub))); if (opsDirInput == NULL) { UT_DEBUGMSG(("Failed to open OPS dir\n")); return UT_ERROR; } for (std::map<std::string, std::string>::iterator i = m_manifestItems.begin(); i != m_manifestItems.end(); i++) { gchar *itemFileName = UT_go_filename_from_uri( (m_tmpDir + G_DIR_SEPARATOR_S + (*i).second).c_str()); gchar** aname = g_strsplit((*i).second.c_str(), G_DIR_SEPARATOR_S, 0); GsfInput* itemInput = gsf_infile_child_by_aname( GSF_INFILE(opsDirInput), (const char**) aname); GsfOutput* itemOutput = createFileByPath(itemFileName); gsf_input_seek(itemInput, 0, G_SEEK_SET); gsf_input_copy(itemInput, itemOutput); g_strfreev(aname); g_free(itemFileName); g_object_unref(G_OBJECT(itemInput)); gsf_output_close(itemOutput); } g_object_unref(G_OBJECT(opsDirInput)); return UT_OK; }
UT_Error IE_Exp_EPUB::compress() { GsfInfile* oebpsDir = gsf_infile_stdio_new( UT_go_filename_from_uri(m_oebpsDir.c_str()), NULL); if (oebpsDir == NULL) { UT_DEBUGMSG(("RUDYJ: Can`t open temporary OEBPS directory\n")); return UT_ERROR; } std::vector<std::string> listing = getFileList( UT_go_filename_from_uri(m_oebpsDir.c_str())); for (std::vector<std::string>::iterator i = listing.begin(); i != listing.end(); i++) { GsfOutput* item = gsf_outfile_new_child(GSF_OUTFILE(m_oebps), (*i).c_str(), FALSE); std::string fullPath = m_oebpsDir + G_DIR_SEPARATOR_S + *i; GsfInput* file = UT_go_file_open(fullPath.c_str(), NULL); if (file == NULL) { UT_DEBUGMSG(("RUDYJ: Can`t open file\n")); return UT_ERROR; } gsf_output_seek(item, 0, G_SEEK_SET); gsf_input_seek(file, 0, G_SEEK_SET); gsf_input_copy(file, item); gsf_output_close(item); // Time to delete temporary file UT_go_file_remove(fullPath.c_str(), NULL); } UT_go_file_remove((m_oebpsDir + G_DIR_SEPARATOR_S + "index.xhtml_files").c_str(), NULL); UT_go_file_remove(m_oebpsDir.c_str(), NULL); return UT_OK; }
virtual UT_Error _loadFile(GsfInput * input) { UT_Error rval = UT_ERROR; UT_String pdf_on_disk, abw_on_disk; // create temporary file names rval = temp_name (pdf_on_disk); if (rval != UT_OK) return rval; rval = temp_name (abw_on_disk); if (rval != UT_OK) return rval; GsfOutput * output = gsf_output_stdio_new (pdf_on_disk.c_str (), NULL); if (output) { // copy input to disk gboolean copy_res = gsf_input_copy (input, output); gsf_output_close (output); g_object_unref (G_OBJECT (output)); if (copy_res) { for (size_t i = 0; i < G_N_ELEMENTS(pdf_conversion_programs); i++) { if ((rval = _runConversion(pdf_on_disk, abw_on_disk, i)) == UT_OK) break; } } } // remove temporary files remove(pdf_on_disk.c_str ()); remove(abw_on_disk.c_str ()); return rval; }